is it possible to resize a gif image to several sizes and save in separate folders?
Below code doesn't work
$imagick = new Imagick($_FILES['file']['tmp_name']);
foreach ($paramVars as $var) {
$imagick = $imagick->coalesceImages();
do {
$imagick->scaleImage($var['cols'], $var['rows'], true);
} while ($imagick->nextImage());
$imagick = $imagick->deconstructImages();
$imagick->writeImages($path, true);
}
$imagick->clear();
$imagick->destroy();
Resize GIF images using imagick with php
Resize GIF images using imagick with php
Last edited by simone on 2017-11-26T00:00:26-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Resize GIF images using imagick with php
It should be possible. I presume you mean with Imagick. But please always provide your IM versions and platform and the code you tried. Is this an animated gif or a single frame gif.
Sorry, I do not know Imagick well.
I suspect if you can convert it to one size, then you can loop over it several times and resize to different sizes and then save the resulting gif. So first get your code working without variables and one resize. Then add the looping with variables. Perhaps the issue is with your variables?
Sorry, I do not know Imagick well.
I suspect if you can convert it to one size, then you can loop over it several times and resize to different sizes and then save the resulting gif. So first get your code working without variables and one resize. Then add the looping with variables. Perhaps the issue is with your variables?
Re: Resize GIF images using imagick with php
@fmw42 I've update with my code.
Re: Resize GIF images using imagick with php
A good place to start is the php imagick website. The first example on this page worked for me except it squished the image:
http://php.net/manual/en/imagick.coalesceimages.php
I added a true option to the thumbnail setting and the original image is only read in once. You could probably optimise the code a bit.
I do not use Imagick code so will not be able to answer many questions about it.
http://php.net/manual/en/imagick.coalesceimages.php
I added a true option to the thumbnail setting and the original image is only read in once. You could probably optimise the code a bit.
Code: Select all
<?php
$file_src='giphy.gif';
$file_dst='small.gif';
$file_dst_tiny='tiny.gif';
$size_w = 150;
$size_h = 150;
$image = new Imagick($file_src);
$image = $image->coalesceImages();
foreach ($image as $frame) {
$frame->thumbnailImage($size_w, $size_h, true);
}
$image = $image->deconstructImages();
$image->writeImages($file_dst, true);
$size_w = 100;
$size_h = 100;
$image = $image->coalesceImages();
foreach ($image as $frame) {
$frame->thumbnailImage($size_w, $size_h, true);
}
$image = $image->deconstructImages();
$image->writeImages($file_dst_tiny, true);
?>
<img src="giphy.gif">
<img src="small.gif">
<img src="tiny.gif">