Is there any way to check if an image URL returns an animated or not GIF?
I need to save image URLs and then show the images on my site, so I would like to allow GIF extension, but I need to avoid animated GIFs. Is it possible to detect that on the fly with out downloading the image?
Check out this comment to the documentation for function imagecreatefromgif (on php.net). You still need to first download the image file even if you are just going to link to it later.
I think, ImageMagick really will be your best chance:
identify -format %n posible_animation.gif
Please check the forum post How to identify animated image format for more information.
Related
I need to manipulate images on the server-side via PHP. I use ImageMagick for that purpose, and there are a lot of great functions, but no documentation...
The issue is the next:
I have two images a png with a transparent background, and a jpg one;
I need to change the JPG image that has the same shape as the visible part of the PNG.
I don't want to crop the image, but to adjust to the PNG's visible part. Is that possible to do?
Example:
I have a picture uploading PHP script, which handles png, jpg and jpeg images well. The problem is, that since I am using the combo of imagealphablending, imagesavealpha, imagecreatetruecolor and imagecopyresampled to resize the picture, the gif animation is lost. I am using imagecreatefromgif to load the gif into memory.
I know one can use ImageMagick to achieve the desired result, but I wonder whether there is a solution with a combo of standard php functions to resize the gif without losing the animation. I there such a solution, or should I start to use a library?
It is possible to resize an animated GIF using GD (what you call "standard PHP").
You need to split the image into individual frames, resize them and then put everything back together.
You can see a more detailed explanation here.
However, I would really suggest you to use imagick, since it's easy to install and much easier to use for advanced tasks like this.
EDIT This is the relevant part from the answer I linked above:
If you don't have ImageMagick access, you should be able to use a
combination of the following steps to resize an animated gif (assuming
you have GD access):
Detect if the image is an animated gif: https://stackoverflow.com/questions/280658/can-i-detect-animated-gifs-using-php-and-gd
(top answer)
Split the animated gif into individual frames: [http://www.phpclasses.org/package/3234-PHP-Split-GIF-animations-into-multiple-images.html][2]
Resize the individual frames: [http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/][3]
Recomposite the frames into an animated gif again: [http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html][4]
Is there any code out there that will allow me to rotate an animated gif 180 degrees while still maintaining the animation?
I tried using the standard imagerotate function (changing the appropriate things from jpeg to gif), but it still only outputs the first frame.
I also found https://stackoverflow.com/a/9356895/462158, but I would like to find something other than ImageMagick if at all possible.
Thanks!
You can either use ImageMagick rotateImage, as suggested in the comments
OR
Extract frames from the gif
Process individual frames the way you like (imagerotate in your case..)
Reconstruct animation
To extract frames from gif image (and reconstruct the animation), you can use gifsicle for example.
The first way is simpler, so first try that, but in case it does not fit the need somehow, processing manually is always an option
So far, I've been uploading one image by hand (FTP to the server when live, locally moving a file), and then resizing them on the fly using the img tag's width and height properties to resize them. Well, the images don't look good, because I need a square, cropped 100px version as a thumbnail, and then a 800px wide version for the view image page, and then finally the full-size original image for HD viewing, but I also need to apply a watermark, but only to the full res version. And I need help with an image upload script. Any sort of file upload, really. I've looked at tutorials, and they don't seem to make too much sense. Furthermore, I need to drop all three versions into a database row (which I think I can figure out). I know that I need to use something like $_FILE to do it, but I'm just really confused to the actual usage and the cropping/resizing/watermarking part really has me stumped. Solutions, anyone?
File uploading
Upload using a simple HTML form and use PHP to manipulate the image. Example
Read all the images stored in a directory and convert them in a batch. Example
Image re-sizing
Use ImageMagick or GD library to resize images. Example
Use any of the same libraries to watermark the images. Example
In all, you need to combine all these in order to upload, resize and watermark all in one go.
For the resizing, watermark etc, you should look at ImageMagic
I don't know how to do this and I was wondering if someone smart could give me an example :)
I want someone to be able to post a png,jpg, or bmp image url and then id use PHP GD to duplicate the image including width and height.
Could someone give me an example of this? Also id like it to support only png, jpeg, and bmp.
I would, in the script, download the URL first (check out PHP cURL), and then attempt to read in the file using GD.
http://php.net/manual/en/book.curl.php
http://php.net/manual/en/book.image.php
You can do a simple regex (something like /^.*\.(jpg|jpeg|png|gif)$/i) on the URL, but URLs don't always represent the type of file you get. Depending on what you need, it might be better to download first and ask questions later.