Page 1 of 3
Newbie here needs help
Posted: 2008-12-09T15:40:09-07:00
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:
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
Thanks
-Matt
Re: Newbie here needs help
Posted: 2008-12-09T16:23:43-07:00
by fmw42
Re: Newbie here needs help
Posted: 2008-12-09T17:32:54-07:00
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?
Re: Newbie here needs help
Posted: 2008-12-09T17:50:52-07:00
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?
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/
Re: Newbie here needs help
Posted: 2008-12-09T18:53:51-07:00
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?
Re: Newbie here needs help
Posted: 2008-12-09T19:23:03-07:00
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
Re: Newbie here needs help
Posted: 2008-12-09T23:56:04-07:00
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:
and how to put it in:
Code: Select all
<IMG border="0" SRC="does-resize-code-go-here?">
Thanks for helping me out, btw.
Re: Newbie here needs help
Posted: 2008-12-10T01:26:00-07:00
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">
Re: Newbie here needs help
Posted: 2008-12-10T01:43:03-07:00
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
Thank you, I have been looking for this all over the place!
Re: Newbie here needs help
Posted: 2008-12-10T01:47:25-07:00
by stingerman
Is there a way to put the resized dimensions in the image tags? -- instead of making another thumbnailx.php?
Re: Newbie here needs help
Posted: 2008-12-10T12:22:04-07:00
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">
Re: Newbie here needs help
Posted: 2008-12-10T22:16:23-07:00
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?
Re: Newbie here needs help
Posted: 2008-12-11T12:01:03-07:00
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.
Re: Newbie here needs help
Posted: 2008-12-11T13:37:38-07:00
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.
Re: Newbie here needs help
Posted: 2008-12-13T23:45:37-07:00
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