Draw text
It’s quite easy to do create an image containing a string
1 | $phMagick->fromString('My text'); |
You will end up with an image with the default formatting containing the text “My text” . You can apply some formatting to the text, font name, size, color, and background.
Draw using the default format
1 2 3 | $p = new phMagick(); $p->setDestination('text.png') ->fromString('phMagick - Image manipulation the easy way'); |
Using a custom format
The default format is pretty ugly, so phMagick provide us with a way to change is defaults.
1 2 3 4 5 6 7 8 9 10 11 | <?php $format = new phMagickTextObject(); $format->fontSize(28) ->font('Arial.ttf') ->color('#fff') ->background('#fd3ab5'); $p = new phMagick(); $p->setDestination('text-custom.png') ->fromString('phMagick - Image manipulation the easy way', $format); |
For those who are not developers this code can start to look scary, but is quite simple to follow
In the first block we are defining the text format to be Arial 28pt white text on pink background
On the second block of code we create an image named text-custom.png from a string with the format we defined on the first block
does phMagick provide functionality to write text on image. Do let me know if ?
@ sohil,
Not directly but you can do it with the watermark function by creating the text and then appending it to an image
http://www.francodacosta.com/blog/phmagick/examples/watermarks
Hey Sven-
I’m LOVING phMagick…it’s making all my image manipulation a breeze. Thank you!
I’m wondering, do you have an example or any suggestion when it comes to converting postscript files such as PDF or EPS to PNG with transparency? I feel like I must be missing something on the convert method. It doesn’t seem to want to maintain transparent channels.
Thanks much!
Adam
Hi Adam,
Despite what you might think, I’m far from being an expert in images
If you are converting to png you should have transparency.
ImageMagick uses ghostscript to convert the pdf to an image, if that conversion is done via a “print to file” mechanism my guess is that you end up with a white instead of transparency
I think you must mess with ghostscript directly!
I found this link with a possible solution for you
hope it helps
Hi Nuno,
This is a grate one.
I am try to create an image using fromString(),But I did n’t find this plugin in plugins folder which i have downloaded from your site can please help me on this !!
looking forward for your reply,
Thanks
Krishna .D
@Krishna
it should be on txt.php inside the plugins folder