Resizing animated GIF with GIFDecoder.class.php will cause transparency problems - php

I need to resize animated GIF in PHP without ImageMagick. I am using the latest GIFDecoder and GIFEncoder classes from PHPclasses. When I extract each frame from the GIF, I get blotches of transparent areas on all the frames but the first one, even though the GIF is not transparent at all. Even putting them back together does not work. I have tried other files but still have the same problem.
The original
How it turned out
Individual frames
If there are other solutions to resizing animated GIF please tell me, too. Thanks!

I would recomment using ImageMagick. It's way faster and more powerfull than any custom coded PHP class.
Please take a look at this thread. The top answer even offers an alternative solution, if you have no access to ImageMagick on your server.

Related

How to resize gif with standard php functions without losing the animation

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]

How do I rotate an animated gif using PHP?

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

Resize images vs thumbnails

I've read many articles and discussions in forums and I still cann't figure out the difference between resizing a large image with php(not with html) and creating thumbnails. Except for the fact that the most people suggest phpthumb and imageMagick for thumbnails I don't understand why I should or not prefer to use these and not php functions like imagecreatefromgif(png,jpeg) and imagecopyresampled which can do this job(according to what I read.). What I'm trying to do is to create many galleries, so I want the images the user uploads to be resized in a smaller size if they are too large. Moreover, I need these images to be resized in smaller pictures that will be shown to gallery and when the user clicks on them they get their real size. So far, the user can upload an image that will be saved in a folder. I resize my images for galleries with html(which I know it's wrong) and I use fancybox for clicking and enlarging part with which I am satisfied. Please help understand the difference and give me the your advice what is the best thing to do. Thanks
Take this scenario.
I'm a highly equiped professional photographer and your photo application will store every image I take. I shoot in RAW so my images are massive. I also want to upload the original hi res JPEGs.
Now if you do not resize these images to thumbnails (by whatever mechanism you choose), if I try and view a particular album, I might have to load a 10x 20Mb images, only to have them resized down to 80x60pixels (and become totally crackling/noisy and extremely pixelated).
So what can you do?
Resize the images on your server, using something like ImageMagick as you suggest to generate multiple versions of this image.
This way you can deliver optimzed qualities for every occassion.
You should always intend to display an image in it's native resolution/dimension to avoid rastering or resizing noise.
And also, you want to save the different versions of the images.
imagecreatefromgif() will use the GD library by default.
Some reasons why one might prefer ImageMagick are detailed here and here.
That said, if you're happy with what you've got already and if there's no realistic chance of running into any GD dealbreakers later on, you certainly may reasonably decide to stay with what you have.

PHP GD library losing quality. Other ideas?

So I'm in the middle of working on a website that deals with photographs. A user uploads their original photograph and GD library creates a smaller sized image of the same photo. However, when comparing a manually sized down image with the GD one, the GD image seems to lose quite a bit of color quality like it had been slightly desaturated. Any alternate suggestions or ways to improve this?
Thanks!
I'd advice using imagemagick for handling anything serious about photos.
besides quality, you'll find using imagick functions like more convenient
Imagick::cropThumbnailImage()
Imagick::thumbnailImage()
Use imagecopyresampled instead of imagecopyresized. It gives much better quality. Also, try NOT to use GIF images as output.
Wow, the answer is imagemagick. Easier to use and maintains the full photograph quality!

Merging (watermark) a jpg with png while resizing the png in PHP GD

I am sure I could somehow figure this out but it's just taking me way too long since I am not a PHP guy. Hopefully someone can set up the script for me in minutes...
So here's what I need to do:
I transmit 2 pictures from a smartphone to a webserver. These 2 images need to be merged (watermarked). They differ a little:
picture is a 2 megapixel jpg (holding a photo)
picture will be a png of 480x800 pixels with a transparent background (holding a simple finger painting)
Now I need to merge these images. The 2nd one (png) needs to be scaled to the 1st one's (jpeg) resolution.
Please note 2 things:
I can only use the GD library that is installed on the server. Imagick or alike is not available
I am well aware of the fact that the 2nd image's quality won't be brilliant. That's okay.
So could anyone help me out on this? Like I said, I've been messing around with a couple of GD functions but progress is far too slow. I guess I found the required functions with imagecopy and watermark. But I don't find the right way to put 'em together.
Thanks in advance,
steff
Thanks a million
A few months ago i posted a function that does that, since the code is quite big i will just link my post, check it out here. Make sure you don't do this onfly, it will overload your server, save the watermarked images or at least cache them.
If you also need to resize the original or watermark, i also posted a function to do this here.

Categories