anam-hossain / phantommagick

PhantomMagick provides a simple API to ease the process of converting HTML to PDF or images
162 stars 45 forks source link

Convert pure html code to image?? #41

Open manukieli opened 6 years ago

manukieli commented 6 years ago

Hi,

I try to convert a website to image with the URL and it work fine. But I need to convert HTML code content to image and it not work. How can I do it??

anam-hossain commented 6 years ago

@manukieli can you share your code?

manukieli commented 6 years ago

I've seen later to the documentation, for raw html data, I need an URL or local disk file. But not use directly use html code like this:
$convert->source('<h1>Title</h1><p>Hello.</p>');

anam-hossain commented 6 years ago

You can use $conv->addPage('<html><body><h1>Raw HTML</h1></body></html>');

manukieli commented 6 years ago

Ok, but I need a png image and not a PDF.

JAYMIN1991 commented 4 years ago

Hello @anam-hossain I am converting HTML with javascript which is not working. Below is example: It is generating blank image.

HTML: `

</body>
<script src="http://codeclippers.xyz/320x50/app.min.js"></script>
<script type="text/javascript">
    var availbleTitles = ["Linkedin your one stop for all", "Twitter connect people", "Facebook connect people", "Instagram ad"];
    var availbleIcons = ["https://dspbanners.s3.amazonaws.com/creatives/user_creatives_5f6dc978a20a7_1601030520.png"];
    var availbleDescription = [
        "Up to <span id='count'>0</span>% Profitability",
        "Up to <span id='count'>0</span>% Profitability",
        "this is test description without HTML",
        "one more description for test",
        "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
    ];
    var availableButtonText = ["Install", "Download", "GET", "Get Offer"];
    var selectedTitle = availbleTitles[Math.floor(Math.random() * availbleTitles.length)];
    var selectedDescription = availbleDescription[Math.floor(Math.random() * availbleDescription.length)];
    var selectedIcon = availbleIcons[Math.floor(Math.random() * availbleIcons.length)];
    var selectedButtonText = availableButtonText[Math.floor(Math.random() * availableButtonText.length)];
    cOptions.isAnimated = true;
    cOptions.animatedVariation = "counter";
    cOptions.iconURL = selectedIcon;
    cOptions.titleText = selectedTitle;
    cOptions.descrptionText = selectedDescription;
    cOptions.buttonText = selectedButtonText;
    renderCreative();
</script>`

$conv = new Converter(); $conv->addPage($html) ->toPng() ->save(storage_path(). '/documents/' . $assetName . '-' . $creativeType.'.png');

Can you help me to solve issue Thank you in advance