Using -path and creating multiple images

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
fRAiLtY-
Posts: 8
Joined: 2011-05-18T08:01:54-07:00
Authentication code: 8675308

Using -path and creating multiple images

Post 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.
ustas19
Posts: 4
Joined: 2011-10-17T09:37:32-07:00
Authentication code: 6789
Location: ne-bra-sko

Re: Using -path and creating multiple images

Post by ustas19 »

Add directory path to your name?

Like /path/to/my/dir/result.file.gif
Make movie online for free, easy&fast.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Using -path and creating multiple images

Post 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.
Post Reply