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
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/

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.