JamesHeinrich / phpThumb

phpThumb() - The PHP thumbnail generator
Other
315 stars 141 forks source link

Why doesn't the library work with Imagick? How to fix it? #217

Closed ulin-evgeny closed 12 months ago

ulin-evgeny commented 12 months ago

I have such code:

require_once 'vendor/autoload.php';
$imagePath = __DIR__ . '/photo.jpg';
$thumb = new phpThumb();
$thumb->setSourceFilename($imagePath);
$thumb->setParameter('w', 100);
$thumb->setParameter('h', 100);
if ($thumb->GenerateThumbnail()) {
    $thumb->OutputThumbnail();
}

As a result of his work, I get a white picture with black letters "no GD": image

I don't really have GD, but I do have Imagick. The README says that the library also works with Imagick:

phpThumb() uses the GD library and/or ImageMagick to create thumbnails from images

I decided to check if Imagick works. I wrote this code:

$sourceImagePath = __DIR__ . '/photo.jpg';
$image = new Imagick($sourceImagePath);
$newWidth = 100;
$newHeight = 100;
$image->resizeImage($newWidth, $newHeight, Imagick::FILTER_LANCZOS, 1);
$destinationImagePath =  __DIR__ . '/photoRes.jpg';
$image->writeImage($destinationImagePath);
$image->clear();
$image->destroy();
echo 'Success!';

I got "Success" and a processed file called photoRes.jpg appeared in the folder. That is, Imagick works. Why is phpThumb not working then? How to fix it?

JamesHeinrich commented 12 months ago

phpThumb was written before PHP had native support for ImageMagick. It depends on passing commands to the external binary as configured: https://github.com/JamesHeinrich/phpThumb/blob/master/phpThumb.config.php.default#L116-L126