Jump to content

Need help writing a simple(maybe) lib that would take html and convert to GD img


emehrkay

Recommended Posts

I need a way to take html created with a wysiwyg editor and a few options (bkg image&color etc) and be able to print it as it was defined with the editor. All css stylings are lost when the user goes to print, so my solution would be to convert that html string into a GD image. I figure this shouldnt be too difficult as long as the style is inline with the html. I figured it would be useful for others so I would try to make it a generic lib. I just need some help identifying which gd functions would be needed to do what as I have never really used it before.

 

Here is the process that I've thought out so far, tell me if I am missing anything and help me out in some areas

 

[*]Define Defaults -- font, font size, font color, font bkg color, and image x y

[*]Read and parse html string

  • this step will read each html element removing the style attribute and using the applicable defintions to style the element. ie <span style="background-color: #red;">test</span> would create a red box with test as the text. If the element doesnt have one of the default settings, use the default that was defined before.
  • The result would be an array with all of the elements' types and GD rules. array(array('type'=> 'text', 'value' => 'test' 'font_color' => '#red')) etc.

[*]convert the findings on each element to the GD equivalent

  • in this step I would have to make it follow html rules as much as possible, all block level elements are treated as such etc

[*]save the image to disk (possible stream in the future) and discard the resource

 

functions/methods that id need

[*]imagettfbbox

[*]imagefilledrectangle

[*]imagecreatetruecolor

[*]imagecolorallocate

[*]gd one that loads existing images (I cannot identify this)

[*]hex to rgb and back

[*]add on...

 

Any suggestions? Does this already exist? Am I in over my head? HELP!

 

I'll make it a google code project once I get something going (well, if it proves to be of any use)

 

Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.