Upload form with IMagick

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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Upload form with IMagick

Post by Bonzo »

NOTE:- depending on your specified sizes for the original thumbnail etc. this will all need to change so everything fits. But see if you get a result from this:

Code: Select all

$new_image = $arr['img_src'];
####CROP | RESIZE THE THUMBNAIL TO 450x450 | ADD BORDER 50x50####

$save_to = $uploaddir.$thumbnail;

exec("/usr/bin/ImageMagick_6.2.6/bin/convert $new_image -crop {$height}x{$width}+$x+$y -resize 450x450  -bordercolor black -border 50x50 $save_to");

echo "<img src=\"$save_to\">";

####ADD FULLSIZED WATERMARK-IMAGE####

// The watermak to add - probably with a transparent background
$input1 = 'watermark.png';

// Resize the watermark 
exec("/usr/bin/ImageMagick_6.2.6/bin/convert $input1 -resize 450x450 temp.png");

// Not sure if you can save over the original but that can be tested later
$watermarked = $uploaddir."watermarked.jpg";

exec("/usr/bin/ImageMagick_6.2.6/bin/composite -watermark 80% -gravity center $temp $save_to $watermarked");

echo "<img src=\"$watermarked\">"; 
bruno1970
Posts: 9
Joined: 2012-10-13T17:53:46-07:00
Authentication code: 67789

Re: Upload form with IMagick

Post by bruno1970 »

I get the error message
Undefined variable: thumbnail
and i have no idea how to define $thumbnail (after hours of try&error). :?

Code: Select all

$new_image = $arr['img_src'];
####CROP | RESIZE THE THUMBNAIL TO 450x450 | ADD BORDER 50x50####

$save_to = $uploaddir.$thumbnail;
$arr['img_src'] is not only the filename. It is the the path and filename (uploads/big/44c8168a8a8cd7117f891dd.jpg). Is that the problem?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Upload form with IMagick

Post by Bonzo »

I had assumed you were creating $thumbnail somewhere in you main piece of code.

echo your variables to see what they contain.

One thing I always recomend to people is get your code working with fixed variables, everything in the same folder and then build it into a form or expand on it when it is working.
bruno1970
Posts: 9
Joined: 2012-10-13T17:53:46-07:00
Authentication code: 67789

Re: Upload form with IMagick

Post by bruno1970 »

.
Last edited by bruno1970 on 2012-10-17T17:46:09-07:00, edited 1 time in total.
bruno1970
Posts: 9
Joined: 2012-10-13T17:53:46-07:00
Authentication code: 67789

Re: Upload form with IMagick

Post by bruno1970 »

I have found the problem!

This code works:

Code: Select all

$new_image = $arr['img_src'];
####CROP | RESIZE THE THUMBNAIL TO 450x450 | ADD BORDER 50x50####
$save_to = $uploaddir.$orginal;

exec("/usr/bin/ImageMagick_6.2.6/bin/convert $new_image -crop {$height}x{$width}+$x+$y -resize 450x450  -bordercolor black -border 50x50 $save_to");

echo $save_to;
The problem is that $arr['img_src'] is the path and the filename (uploads/big/44c8168a8a8cd7117f891dd.jpg).
The thumbnails are now in the folder uploads/thumb/uploads/big/ :lol:
bruno_1970
Posts: 1
Joined: 2013-03-13T08:02:34-07:00
Authentication code: 6789

Re: Upload form with IMagick

Post by bruno_1970 »

Hello,

i have a new problem.

Code: Select all

$new_image = $ordner.$new_name;
			
		   } while(file_exists($new_image));
			if(@move_uploaded_file($myFILE['tmp_name'], $ordner.$new_name)){
			
                       $new_image2 = $new_image;

			exec("/usr/bin/ImageMagick_6.2.6/bin/convert $new_image -thumbnail 700x700 -extent 750x750 -density 300 $new_image2");
			exec("/usr/bin/ImageMagick_6.2.6/bin/mogrify $new_image2 -format jpg $new_image2");

			echo $new_image2; 	
If i upload a JPG everything works fine but if i upload a GIF or PNG "echo $new_image2" shows never the (always) wanted JPG version. How can i fix that?

P.S.
The script creates a JPG and a GIF or PNG version in the right folder.
1b041446e51713f5ddde52a88cd4fb9c.jpg
1b041446e51713f5ddde52a88cd4fb9c.gif
Post Reply