I have a question about saving text/strings as images in PHP. Since I want to protect data on my site, I want to convert text and save it as image files in a folder on a server (before displaying it). Is there a way to do it, or maybe a better solution? Thanks in advance
If you wish to convert Text/String into image, you can try ImageMagick or GD.
Detail about ImageMagick (Imagick extension) is available at http://php.net/manual/en/book.imagick.php)
Detail about GD at http://php.net/manual/en/book.image.php
getimagettftext() function from GD can be useful, see detail at http://php.net/manual/en/function.imagettftext.php
Imagick::annotateImage() function from Imagick can be useful, see detail at http://php.net/manual/en/function.imagettftext.php
If you want to save text as an image, not overlay it on another image, then you should use label: or caption: or tango: in ImageMagick and not annotate.
See http://www.imagemagick.org/Usage/text/. Then find the equivalent command in Imagick. For example, http://us3.php.net/manual/en/imagick.labelimage.php
You can use the equivalent of -annnotate, but then you have to create an background image onto which to write the text.
The advantage of label: for example is that it creates an image automatically.
Related
I want to write text on an image using PHP by calling ImageMagick commands, like uploading an image and editing text on the image. How can I do that?
There are a lot of classes that will help you doing this, my favorite is https://github.com/claviska/SimpleImage. There is also a stackoverflow post how to convert text into an image convert text to image in php. With this combination you are able to reach what you want I think.
You'll need the function ->overlay('watermark.png', 'bottom right') of the SimpleImage class.
The effect I would like to generate is exactly like the example in
this StackOverflow thread: (Related Question)
1.Resize image
2.Keep proportion
3.Add or Fill none-image areas with white background
Here are three examples of this process below:
1. If original is square no matter 640*640 or 1024*1024, just resize it to target dimension e.g. 480*480 will work.
If the original input is vertical rectangular,the output should not be cropped
and still be centerlized as below (the red dash edge marker is just make it easier to see the background is white and the proportion is kept after image resized to 480*480 px)
if the original input is horizontal rectangular, output like below, white background, keeps proportion and image uncroped , thus without losing anything after the image processing.
So after I've clarified such a question,
I would like to know:
Is there a general name of such Custom Image Resize mentioned above?
would like to know how to achieve it using php image library Imagine?
is it doable using php-imagine, or have to switch to another library, e.g imagemagick?
P.S. If you would like to achieve the effect either in image-resizing or video resizing, you can use below FFMPEG single-line command.
(thanks to #Mulvya, yes below code applies both to videos and image formats)
[run below built-in code in ffmpeg console to achieve the mentioned resize effect]
[video resize]
ffmpeg -i "[raw video url or videofile location.mp4]" -vf "scale=iw*min(480/iw\,480/ih):ih*min(480/iw\,480/ih),pad=480:480:(480-iw)/2:(480-ih)/2:color=white" [save_path_and_filename].mp4
[image resize]
ffmpeg -i "[raw image url or imagefile location.jpg]" -vf "scale=iw*min(480/iw\,480/ih):ih*min(480/iw\,480/ih),pad=480:480:(480-iw)/2:(480-ih)/2:color=white" [save_path_and_filename].jpg
Sorry i don'T have full answer for you and it's too long for a comment, but this can be done natively using some maths and php's http://php.net/manual/en/ref.image.php
Check in the area of imagecopyresize() imageecreate() imagescale and so on. It a pretty complex lib so you will have to do some try and mistake to get where you want to go.
From experience you can:
create an empty image, imagecreatetruecolor()
change background color to white
take a scetion of an image and paste it in the new created image using imagecopyresample() imagecopyresize()
export this image ans gif, png, jpg. imagepng(), imagejpg().
add watermark
and ALOT more.
Sorry i don'T have a more complete answer but depending on your need it can take a few mitues/hours to make it perfect. have fun.
On top of it, if you know ffmpeg, you can make both work together and make awesome media outputs. Cheers to you
I have an image of NxN size and an image of MxM, with N>M. I want to place the second on top of the first, but I want to do it on a specific pixel e.g.(10,15)
I installed imagemagick and start playing with it cli (planning to try with php later), but I could not find if there is something that I could use for this purpose or if it is possible by combining some commands.
So my question(s):
Is something like this possible with imagemagick?
If yes, how could I achieve it in command line imagemagick?
If yes, how could I achieve it with imagemagick in php?
Expanding on my comment, I think php gd would be a good fit for this. PHP gd is better integrated into php and works better in my opinion. I use it for a host of things (resizing thumbnails most notably). Your question seems very similar to placing a watermark on an image, ie one image is place on top of another and it is exported as a single raster image. Here's a quick example for creating this watermark:
http://www.sitepoint.com/watermark-images-php/
This example exports it directly to the browser, but it can be easily modified to save the image locally to your file system. Enjoy!
I want to add a small functionality to my site wherein a user can upload his pic and then on selecting a specific color(basically on clicking something) a splash effect of that color gets added to that image.
The user should then get an option to save that image.
Is it possible using the php GD library? Any helpful comments are welcome.
Edit: What if i create the images for these effects? how can i overlay them on the user's pic and then offer the complete image as a download?
The simplest way to achieve this is to create the effect in another image and just use PHPs GDlib to copy that image on the image uploaded by the user and change the color.
You can use imagecopy or imagecopyresized or imagecopyresampled. Depending on the image you are using you could for example use imagecolorset to change the color of the effect.
The full list of PHPs image functions is in the PHP manual.
Use of the GD library might work here, but this is something that ImageMagick was built for. I'd look into using that, as it's almost as ubiquitous.
Just use the original image as a background image, and add on top of that a full sized fill of a colour at a reduced opacity.
http://us2.php.net/manual/en/function.imagecolorallocatealpha.php
How to include an image inside another image in PHP? I want to do it like in twitterbackgrounds.com personalized backgroud. there is one main image and we can upload four personal images after that it will show as watermark of the main image.
I never used GD by myself, but look at the example in the manual, wich is about "Using imagecopymerge() to create a translucent watermark".
Well, there are several possibilies to do that. The one that pops into my mind is to use a php page where you can upload all files needed for this. After submission you can use imagemagick to create the new image with watermarks and display it on another webpage or store it to a database.
Here is a good tutorial on how to use imagemagick to create the watermarks in another image.
you may use imagemagick as commandline command from php or use it as a server application on an own server
phpThumb has a watermark feature, if you're looking for something full-featured and ready-made..