Page 2 of 3
Re: Newbie here needs help
Posted: 2008-12-14T16:56:07-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">
Is there a way to incorporate the drop shadow command into this?
Re: Newbie here needs help
Posted: 2008-12-15T15:19:30-07:00
by Bonzo
Code: Select all
<?php
$photo = 'original.jpg';
$height = '125';
$width = '200';
$cmd = "convert $photo -matte -thumbnail {$width}x{$height} ( +clone -background black -shadow 90x3+15+15 ) +swap -gravity northwest -geometry -3-3 -composite -background white -flatten +repage PNG:-";
header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>
This would need the output to be a png; you may be able to modify it so the background is the same colour as your page. Not very speedy though and depends on you IM version.
You may need to use \( \) rather than ( )
Re: Newbie here needs help
Posted: 2008-12-15T18:42:19-07:00
by stingerman
Is there some reason the pics are not thumbnailed to the exact size? I notice some pics are off a few pixels here or there.
Does it depend on the original size pic or something in the command?
For example setting the width and height to 180x270 of a pic 900x1316 -
Imagemagick thumnails it to: 180x263
Re: Newbie here needs help
Posted: 2008-12-15T18:53:18-07:00
by anthony
IM tries to preserve the aspect ratio of images, so that circles remain circles!
If that is not wanted add a '!' flag to the resize/thumbnail option.
Otherwise you can pad out the image using techniques given in
Im Examples, Thumbnails, Padding
Re: Newbie here needs help
Posted: 2008-12-15T20:10:34-07:00
by stingerman
anthony wrote:IM tries to preserve the aspect ratio of images, so that circles remain circles!
If that is not wanted add a '!' flag to the resize/thumbnail option.
Otherwise you can pad out the image using techniques given in
Im Examples, Thumbnails, Padding
Well, I just added the image attributes in the image tags and it resizes automatically. Guess, its a good idea to do that.
Re: Newbie here needs help
Posted: 2009-01-07T01:35:42-07:00
by stingerman
Another question
In the above php code, 'thumbnail' is used.
Does that give less quality compared to 'resize'?
Which is better and how would I use resize in that code?
Thanks!
Re: Newbie here needs help
Posted: 2009-01-07T03:34:07-07:00
by Bonzo
I think the quality of thumbnail and resize is the same. Thumbnail strips out all the EXIF data automaticaly where as with resize you need to use -strip.
To use resize just swap the words.
To speed up jpg resizing try changing:
Code: Select all
$cmd = "convert $photo -matte -thumbnail {$width}x{$height}
To
Code: Select all
$cmd = "convert -size {$width}x{$height} $photo -matte -thumbnail {$width}x{$height}
Re: Newbie here needs help
Posted: 2009-01-15T21:03:48-07:00
by stingerman
Awesome Thanks!
Re: Newbie here needs help
Posted: 2009-01-15T21:26:05-07:00
by stingerman
Is there a way to incorporate two commands into one php?
For instance use the above to resize but then add a shadow and convert to png?
I found this drop shadow code but not sure what to do with it, lol.
Basically I want to resize an image down to 80x120, add a drop shadow with an offset of 8 (for both x and y), blur radius 15 and opacity 80. This makes the image 110x150. Would save me some time instead of using The Gimp.
Code: Select all
convert -page +4+4 thumbnail.gif -matte \
\( +clone -background navy -shadow 60x4+4+4 \) +swap \
-background none -mosaic shadow_soft.png
Re: Newbie here needs help
Posted: 2009-01-16T17:52:26-07:00
by stingerman
You know what I am having a hard time figuring out (surprise!) is the quality command.
I cant seem to get it to be equivalent to of say 85 (of a photo program like the gimp).
Re: Newbie here needs help
Posted: 2009-01-16T18:54:06-07:00
by fmw42
IM quality factors may not be truly linear percents.
Re: Newbie here needs help
Posted: 2009-01-16T19:09:41-07:00
by stingerman
I kinda figured something out, I just exported (from a pdf) the original image at smaller scale. So that worked.
Speaking of that is there a way to use imagemagick to export pdf to jpg?
Re: Newbie here needs help
Posted: 2009-01-17T04:13:26-07:00
by Bonzo
Try this code - its one I used for a website just change the values to what you want:
Code: Select all
exec("convert $value -matte -resize 560x450 \( +clone -background black -shadow 90x3+15+15 \) +swap -gravity northwest -geometry -3-3 -composite -background white -flatten +repage $photo");
To convert a pdf you use the same code as normal but you need ghostscript installed:
Code: Select all
exec("convert input.pdf output.jpg");
To control the quality a bit more add a density:
Code: Select all
exec("convert -density 300 input.pdf output.jpg");
To just convert the second page ( note the first page is 0 I think not 1 ):
Code: Select all
exec("convert input.pdf[1] output.jpg");
Re: Newbie here needs help
Posted: 2009-01-17T22:46:27-07:00
by stingerman
Bonzo wrote:Try this code - its one I used for a website just change the values to what you want:
Code: Select all
exec("convert $value -matte -resize 560x450 \( +clone -background black -shadow 90x3+15+15 \) +swap -gravity northwest -geometry -3-3 -composite -background white -flatten +repage $photo");
Ok, I messed something up:
Here is my php:
Code: Select all
<?php
$photo = $_GET['p'];
$height = $_GET['h'];
$width = $_GET['w'];
$cmd = "/usr/local/bin/convert exec("convert $value -matte -resize 960x1457 \( +clone -background black -shadow 90x3+15+15 \) +swap -gravity northwest
-geometry -3-3 -composite -background white -flatten +repage $photo");
passthru($cmd, $retval);
?>
and the href:
Code: Select all
SRC="resizepic.php?p=images/xxxx.jpg&w=960&h=1457"
Image not showing up. Thanks, again.
Re: Newbie here needs help
Posted: 2009-01-18T02:19:58-07:00
by Bonzo
My code was to save an image to do what you want try this:
Code: Select all
<?php
$photo = $_GET['p'];
$height = $_GET['h'];
$width = $_GET['w'];
$cmd = "/usr/local/bin/convert $photo -matte -resize {$width}x{$height} \( +clone -background black -shadow 90x3+15+15 \) +swap -gravity northwest
-geometry -3-3 -composite -background white -flatten +repage ";
passthru($cmd, $retval);
?>