petenaylor Posted October 3, 2011 Share Posted October 3, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248365-imagemagick-changes-image-shape/ Share on other sites More sharing options...
Deoctor Posted October 4, 2011 Share Posted October 4, 2011 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/ Quote Link to comment https://forums.phpfreaks.com/topic/248365-imagemagick-changes-image-shape/#findComment-1275489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.