4

I'd like to ask whether its possible to take a bit of CSS on a page with a PHP extension, and add the PHP header to define the page as a PNG, and have a dynamic image? From what I've heard this isn't possible, but if it isn't, is there a way easier than the conventional method of creating a PHP image?

Edit* To elaborate, I want to do something like draw a bordered 200x200p box in CSS with styling and HTML, and have this HTML/CSS box on a .PHP page, and get this page to become a PNG image with the .PNG extension using the PHP header tag.

Thank You!

Karan

11
  • 1
    Your question is a bit unclear of what you want to do. You can dynamically generate CSS with PHP as well as you can dynamically serve a PNG image with PHP. Commented Dec 26, 2011 at 19:50
  • 1
    Apologies, I will elaborate :) Commented Dec 26, 2011 at 19:51
  • The most common use for dynamic PHP-created images are captchas. There are a lot of howtos and tutorials out there, just google a little bit. Commented Dec 26, 2011 at 19:55
  • 1
    You want to create a screenshot of the website? Commented Dec 26, 2011 at 19:55
  • 1
    If i understand you right, this might be helpful for you. stackoverflow.com/questions/757675/… Commented Dec 26, 2011 at 19:57

2 Answers 2

3

You can make use of wkhtmltopdf which can convert html to pdf using webkit (qtwebkit) which supports CSS properly. There even exists a PHP binding for it.

You can then convert the PDF file to a PNG (e.g. with ImageMagick) and serve it from within PHP.

Related: Website screenshots using PHP

Sign up to request clarification or add additional context in comments.

1 Comment

I'll make sure to try it out tomorrow. Cheers, hakre :)
2

If I understand your question properly, I am not sure how this would be possible using only PHP but you could use ImageMagick on server side to convert the HTML page to a png.

1 Comment

I'll take a look at Imagemagick, haven't seen it before! Thanks for your answer :) Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.