Newbie here needs help

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
stingerman

Newbie here needs help

Post by stingerman »

Well, I am confused! LOL!

I am building a web page and I want to resize an image via imagemagick and then link that pic to the larger one (like a thumbnail).

For instance if this is the code for the regular image:

Code: Select all

<src="/images/starlin1.jpg>
What do I need to do to resize?

Do I need to make a resize php script or something and run it through that? Is there one available somewhere?

such as:

Code: Select all

<src="images/phpscriptresize/starlin1.jpg?(200)
I can't just run it through the server imagemagick path like (because this didn't work and it gave me some 24x24 pic of something missing):

Code: Select all

<img src="/usr/local/bin/convert  images/starlin1.jpg'[64x64]'    starlin1.gif">
Please help :D Thanks
-Matt
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Newbie here needs help

Post by fmw42 »

see http://www.rubblewebs.co.uk/imagemagick/ for ImageMagick using PHP
stingerman

Re: Newbie here needs help

Post by stingerman »

I still can't get it to work.

I got a gd script working but its slow. :(

IM does work in my wiki page so i gotta be doing something wrong.

Do I need a script to resize an image? and is that different than the command line? and where can I get one? :D
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Newbie here needs help

Post by fmw42 »

stingerman wrote:I still can't get it to work.

I got a gd script working but its slow. :(

IM does work in my wiki page so i gotta be doing something wrong.

Do I need a script to resize an image? and is that different than the command line? and where can I get one? :D
I don't know enough about PHP, but there is a script for resizing again at http://www.rubblewebs.co.uk/imagemagick ... filter.php

in command line you would do

convert image.jpg -resize args smallimage.jpg

where args are explained at http://www.imagemagick.org/script/comma ... php#resize

You may want to get more familiar with IM by reading:

http://www.imagemagick.org/script/comma ... ptions.php
http://www.imagemagick.org/Usage/
stingerman

Re: Newbie here needs help

Post by stingerman »

I have read all those but still can't figure it out.

Do I need a separate php file to call up imagemagick?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Newbie here needs help

Post by fmw42 »

stingerman wrote:I have read all those but still can't figure it out.

Do I need a separate php file to call up imagemagick?
You need a PHP script (don't know if you need a separate file, but often that is part of the whole script for process with IM).

See if you can access IM from PHP to find out what version you have. You need to know where IM is located. On my ISP server the following work. Try one or all of them or contact your ISP to find out where IM is located or if they even have it.

The following are each in separate files for my testing of my server, but you can process IM in one long file.

Again, I am not expert and this is as far as I got with IM and PHP:


<?php
system("/usr/local/bin/convert -version");
?>

returns:
Version: ImageMagick 6.2.7 06/08/06 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC

<?php
$IM_version=shell_exec("/usr/local/bin/convert -version");
echo $IM_version
?>

returns:
Version: ImageMagick 6.2.7 06/08/06 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC


<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

returns:
Version: ImageMagick 6.2.7 06/08/06 Q16 http://www.imagemagick.org
stingerman

Re: Newbie here needs help

Post by stingerman »

I do have it installed.

Version: ImageMagick 6.2.7 06/08/06 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC

path: /usr/local/bin/convert

For example what would I do to rezise this image to 156width/237height:

Code: Select all

"images/starlin1"
and how to put it in:

Code: Select all

<IMG border="0" SRC="does-resize-code-go-here?">
Thanks for helping me out, btw.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Newbie here needs help

Post by Bonzo »

You will need some sort of code to tell php what to do. I put mine in an upload form and resize on upload.

You can resize "on the fly" using something like:
PUT THIS ON A PAGE OF ITS OWN AND CALL thumbnail.php

Code: Select all

<?php
$photo = $_GET['p'];
$height  = '125';
$width = '200';
$cmd = "convert $photo -thumbnail {$width}x{$height} JPG:-";
header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>
Call from your page using:

Code: Select all

<img src="thumbnail.php?p=input.jpg">
stingerman

Re: Newbie here needs help

Post by stingerman »

Bonzo wrote:You will need some sort of code to tell php what to do. I put mine in an upload form and resize on upload.

You can resize "on the fly" using something like:
PUT THIS ON A PAGE OF ITS OWN AND CALL thumbnail.php

Code: Select all

<?php
$photo = $_GET['p'];
$height  = '125';
$width = '200';
$cmd = "convert $photo -thumbnail {$width}x{$height} JPG:-";
header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>
Call from your page using:

Code: Select all

<img src="thumbnail.php?p=input.jpg">
Ahhh, it worked! However, I had to put my correct path for the convert

Code: Select all

/usr/local/bin/convert
Thank you, I have been looking for this all over the place!
stingerman

Re: Newbie here needs help

Post by stingerman »

Is there a way to put the resized dimensions in the image tags? -- instead of making another thumbnailx.php?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Newbie here needs help

Post by Bonzo »

Try this:

Code: Select all

<?php
$photo = $_GET['p'];
$height  = $_GET['h'];
$width = $_GET['w'];
$cmd = "convert $photo -thumbnail {$width}x{$height} JPG:-";
header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>
<img src="thumbnail.php?p=input.jpg&w=200&h=125">
stingerman

Re: Newbie here needs help

Post by stingerman »

That's the one! Man, thanks a lot. I just started a comic book website and this is going to save me a ton of time with the previews and such!

Oh, any idea how to add on a header?

For, example:

Code: Select all

<a href="thumbnail.php?p=images/ai71.jpg">
would also contain my header.

I tried adding the header html before the php tags in the thumbnail php but got an error message:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxxx/xxxxxxxx/html/thumbnailtesta.php:9) in /home/xxxxx/xxxxxx/html/thumbnailtesta.php on line 24
Line 24 is:

Code: Select all

header("Content-type: image/jpeg");
Do I need to add something more/different?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Newbie here needs help

Post by Bonzo »

I do not think its possible using this method as you need the header to make sure the image shows as an image and not garbage and you can not put anything before the header - catch 22.

I got mixed up with my image tags and link ones; thats what comes of trying to do things in a hurry!

I am trying to think of a way to do this by passing the image name to the thumbnail.php page but at the moment I can not think of a way.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Newbie here needs help

Post by Bonzo »

At the back of my mind I knew there was a way to do this using .htaccess An example here using GD http://sneak.co.nz/2006/10/27/dynamic-image-resizing/

I searched Google for "resize image .htaccess"

I would think this was possible to mod for Imagemagick.
stingerman

Re: Newbie here needs help

Post by stingerman »

Not a big deal.

Though I think they use it here - http://comicbookresources.com/?page=pre ... disp=table (click on the enlarge button) - assuming they use imagemagick
Post Reply