Shaun
Shaun

Reputation: 2311

Image Magick create thumbnail

Hi i am creating a thumbnail using imagemagick by following command

 convert -define jpeg:size=".$this->info[0]."x".$this->info[1]."  testi/".$this->filename."  -auto-orient  -thumbnail 200x200   -unsharp 0x.5 testi/".$this->filename

but this command only runs for jpack input file.

Can anyone tell me the command for any file type? like if gif then output shuld gif ?

Upvotes: 0

Views: 3356

Answers (2)

Bonzo
Bonzo

Reputation: 5299

What is a jpack file?

The -define will only work for jpg files but I thought if the output file was not a jpg it would be ignored; try removing that.

The output file should be the same name as the input file.

Try writing your code like this so you can see what the command actualy is; you can comment the echo out when its working.

$cmd = "-define jpeg:size={$this->info[0]}x{$this->info[1]}  testi/{$this->filename}  -auto-orient -thumbnail 200x200 -unsharp 0x.5 testi/{$this->filename}"; 
echo $cmd;
exec("convert $cmd");

I got a bit lost with the "$this->" business and so the code may not work as written. I try and keep things simple in my commands and would have put the filenames etc. into a variable outside the Imagemagick command.

Upvotes: 2

Preet Sandhu
Preet Sandhu

Reputation: 435

Here is code:

<?php 
// read page 1 
$im = new imagick( 'test.pdf' );

// convert to jpg 
$im->setImageColorspace(255); 
$im->setCompression(Imagick::COMPRESSION_JPEG); 
$im->setCompressionQuality(60); 
$im->setImageFormat('jpeg'); 

//resize 
$im->resizeImage(290, 375, imagick::FILTER_LANCZOS, 1);  

//write image on server 
$im->writeImage('thumb1.jpg'); 
$im->clear(); 
$im->destroy(); 
?>

Upvotes: 3

Related Questions