Page 1 of 1

Posted: 2006-09-23T16:01:59-07:00
by Bonzo

Code: Select all

<? 
if ( $Submit ) { 

// Display what is being posted 
echo "<br> filename = ".$filename; 
echo "<br> HTTP_POST_VARS filename = ".$HTTP_POST_VARS["filename"]; 
echo "<br> _POST filename = ".$_POST["filename"]; 

// Temporary upload image name 
$original_image = $_FILES['filename']['tmp_name']; 
// Display what original_image contains 
echo "<br> original_image = ".$original_image; 

// Get the image dimensions 
$size=GetImageSize( $original_image ); 

// Name to save the image as - in this case the same as the original 
$new_image = $_FILES['filename']['name']; 
echo "<br> new_image = ".$new_image; 

if ( $size[0] > 794 || $size[1] > 564 )
{ exec("/usr/local/bin/convert $original_image -resize 794x564 -segment 1x1 +dither -colors 2 -edge 1 -normalize -negate $new_image"); }

else
{exec("/usr/local/bin/convert $original_image -segment 1x1 +dither -colors 2 -edge 1 -normalize -negate $new_image"); }

echo "File uploaded"; 
echo "<img src=\"".$new_image."\">"; 

} 
?>
This is untested but should work ( possibly with a bit of modification ! )

Code: Select all

<? 
if ( $Submit ) { 

// Display what is being posted 
echo "<br> filename = ".$filename; 
echo "<br> HTTP_POST_VARS filename = ".$HTTP_POST_VARS["filename"]; 
echo "<br> _POST filename = ".$_POST["filename"]; 

// Temporary upload image name 
$original_image = $_FILES['filename']['tmp_name']; 
// Display what original_image contains 
echo "<br> original_image = ".$original_image; 

// Get the image dimensions 
$size=GetImageSize( $original_image ); 

// Name to save the image as - in this case the same as the original 
$new_image = $_FILES['filename']['name']; 
echo "<br> new_image = ".$new_image; 

exec("/usr/local/bin/convert $original_image -resize 794x564> -segment 1x1 +dither -colors 2 -edge 1 -normalize -negate $new_image"); 

echo "File uploaded"; 
echo "<img src=\"".$new_image."\">"; 

} 
?>
Or something like this in Imagemagick only.

Posted: 2006-09-23T18:54:00-07:00
by anthony
Pass a '>' flag as part of the size to resize. it will only resize images that are larger than the requested size.

See IM Examples, Resize for a demostration using commandline.

Posted: 2006-09-24T14:27:57-07:00
by Bonzo
Thats strange; according to the Imagemagick instructions if you use 794x564> it should only resize the image if it is larger than 794x564. I have just tried it and created an image of 0kb !

I would say use my first example where it checks the size with getimagesize and the uses the if else function.

Note: I think I may have found the problem, try changing this line :
exec("/usr/local/bin/convert $original_image -resize '794x564>' -segment 1x1 +dither -colors 2 -edge 1 -normalize -negate $new_image");

-resize 794x564> is now -resize '794x564>'

Posted: 2006-09-24T16:52:06-07:00
by anthony
Not unless you add a '!' to the resize the images aspect ration is preserved, just as you want. That is the final image will fit into the requested box, NOT fill the requested box.

See IM Examples. Resize examples.