Jump to content

Imagemagick changes image shape


petenaylor

Recommended Posts

Hi all

 

I have created the below script to resize my images and it works fine for landscape images but if you select a portrait image it saves it as a landscape image. How do I modify the script so it keeps the same aspect ratio?

 

copy($_FILES['image1']['tmp_name'], WEB_UPLOAD."images/adverts/test/".$_FILES['image1']['name']) or die("Error uploading image.");
$ext = strtolower(substr($_FILES['image1']['name'], strrpos($_FILES['image1']['name'], ".")));
$rand = rand(1, 100000000000000); 
$name = $rand . $ext;
$image_small = $rand . $ext;		
rename(WEB_UPLOAD."images/adverts/test/".$_FILES['image1']['name'], WEB_UPLOAD."images/adverts/test/".$name) or die("Error renaming image.");;				
$go = WEB_UPLOAD.'images/adverts/test/'.$name;
$stop = WEB_UPLOAD.'images/adverts/test/'.$image_small;		
exec ("/usr/bin/convert $go -resize 10%\> -quality 100 $stop");			
unset($scale, $go, $stop);	

 

Many thanks for your help.

 

Pete

Link to comment
https://forums.phpfreaks.com/topic/248365-imagemagick-changes-image-shape/
Share on other sites

here you are resizing the image to 10% of the actual image you better try to use the following methodology rather than using the above.

-resize $conv_widthx$conv_height

consider your image is of 100dpi and you want this to be converted to the 72dpi then you should do something like this

 

 

$conv_width = $width* 72/100

the same follows for the height.

If you need further help regarding image magick refer to the manual at http://www.imagemagick.org/Usage/files/

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.