Imagick and Thumbnails

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
boofoohacker

Imagick and Thumbnails

Post by boofoohacker »

I'm building an advanced thumbnail generator for my website but am having some issues when try to convert the actual ImageMagick "convert" command into using the Imagick Image Library. Right now I'm using shell_exec to process the command shown below but I am looking to make it to use the library to make my code more uniform. Everything else is adapted to the library except this one command. Any help will be appreciated.

This is the command:

Code: Select all

/usr/local/bin/convert "{$filepath}" -size 1x14 xc:Black  -background Black  -append -gravity South -fill White -draw "text 0,0 '{$filereso['0']}x{$filereso['1']} - {$filesize}" "{$outputpath}";
If this is in the wrong forum please move or let me know.
boofoohacker

Re: Imagick and Thumbnails

Post by boofoohacker »

I fiquired out how to convert it and for anyone looking to make thumbnails like the one the image hosting website I'm using has here, then try using the code shown below. It will envolve a little modification to match your needs but it will work.

Code: Select all

<?php
 
$imagick = new Imagick();
$canvas = new Imagick();
$canvasdraw = new ImagickDraw();

$imagick->readImage("shin_chan.jpg");
$imagick->thumbnailImage(160, 0);
$imagick->setImageFormat("jpeg");

$canvas->newImage($imagick->getImageWidth(), ($imagick->getImageHeight() + 14), new ImagickPixel("black"));
$canvas->setImageFormat("jpeg");
$canvasdraw->setFillColor(new ImagickPixel("white"));
$canvasdraw->setFontSize(11);
$canvasdraw->setFontWeight(600);
$canvasdraw->setGravity(imagick::GRAVITY_SOUTH);
$canvas->annotateImage($canvasdraw, 0, 0, 0, "1000x1000 - 16kb");
$canvas->compositeImage($imagick, imagick::COMPOSITE_OVER, 0, 0);
$canvas->setImageCompression(9);
 
header("Content-Type: image/jpeg");
echo $canvas->getImageBlob();

?>
Post Reply