Page 1 of 1

Using -path and creating multiple images

Posted: 2011-05-18T08:15:30-07:00
by fRAiLtY-
Hi guys,

Currently I'm using ImageMagick to convert PDF's into jpegs with the aim of creating 2 jpegs on the fly, 1 a regular sized jpeg and 1 a thumbnail.

Here's where I am currently. This code below successfully creates jpegs of all the pages in the pdf ($targetFile) and renames them with the jpeg extension. Instead of saving those outputted files in the same directory I'd like to put them in an already created directory within the working directory called "thumbs".

Code: Select all

$image = exec("convert " . $targetFile . "  " . substr_replace($targetFile , 'jpg', strrpos($targetFile , '.') +1));
This creates one jpeg of each page in the pdf and saves it correctly beside the PDF. I want it saved in a subdirectory, I've tried using "-path" as per the manual but it has no effect in my use, and there's no example! That's the first step!

The next step is to get it to create 2 jpegs on the fly, one large one small, saving the large ones alongside the PDF and the small in "thumbs" directory.

Can anyone help please? I'm relatively familiar with PHP and I'm pretty sure this an ImageMagick "problem" more so than PHP as it's working, just not going where I want it!

Cheers.

Re: Using -path and creating multiple images

Posted: 2011-10-17T10:15:06-07:00
by ustas19
Add directory path to your name?

Like /path/to/my/dir/result.file.gif

Re: Using -path and creating multiple images

Posted: 2011-10-17T11:13:19-07:00
by Bonzo
Personaly I would change the image path/name outside the imagemagick command if nothing else it makes the code easier to read.

I have lost track of what files you wanted but this should give you some idea - not 100% sure of how it will work with a multipage pdf.

Code: Select all

$new_jpg = str_replace( 'pdf', 'jpg', $targetFile);
$new_thumb = "thumbs/$new_jpg";
$small_thumb = "th_$new_jpg";

$cmd = " $targetFile \( +clone -thumbnail x480 -write $new_jpg +delete \)".
" \( +clone -thumbnail x250 -write $new_thumb +delete \) ".
" -thumbnail 64x64! ";
exec("convert $cmd $small_thumb ");
P.S. This is not using Imagick and so I would have posted in the User section of the forum.