melloorr Posted November 27, 2011 Share Posted November 27, 2011 Hey everyone. I have been trying to make a script that allows me to resize an image but I am having some trouble. I have got a script that takes an image and resize's it: <?php $save = $_REQUEST['SavedAs'] ; $file = $_REQUEST['ImgAdd'] ; echo "Creating file: $save"; $size = 0.45; header('Content-type: image/jpeg') ; list($width, $height) = getimagesize($file) ; $modwidth = 240; $modheight = 180; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; header ("Location: $save"); ?> But depending on the image, the aspect ratio looks wrong. Is there anyway to take an image, crop it, then resize it? Or something that makes it look decent? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/251902-image-resizing/ Share on other sites More sharing options...
Laash Posted November 27, 2011 Share Posted November 27, 2011 Hi There's an awesome way to do it: http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/ I use this script on my websites. Quote Link to comment https://forums.phpfreaks.com/topic/251902-image-resizing/#findComment-1291634 Share on other sites More sharing options...
melloorr Posted November 28, 2011 Author Share Posted November 28, 2011 Is this the only way to do it? Because I would rather crop it first then resize it, if possible. Quote Link to comment https://forums.phpfreaks.com/topic/251902-image-resizing/#findComment-1291844 Share on other sites More sharing options...
litebearer Posted November 28, 2011 Share Posted November 28, 2011 works for me ... cropping - http://www.nstoia.com/sat/crop/ resizing - http://www.nstoia.com/sat/resize/ Quote Link to comment https://forums.phpfreaks.com/topic/251902-image-resizing/#findComment-1291849 Share on other sites More sharing options...
melloorr Posted November 29, 2011 Author Share Posted November 29, 2011 Okay so I have now got code that crops it, then resizes it, but is still does not look right, is there any way to get it to start at the top of the picture, but in the middle width wise? (as it normally starts in the top left corner, then 720px out to the right) Here is my code so far: <?php $image = $_REQUEST['Img']; // the image to crop $dest_image = $_REQUEST['Saved']; // make sure the directory is writeable $img = imagecreatetruecolor('720','540'); $org_img = imagecreatefromjpeg($image); $ims = getimagesize($image); imagecopy($img,$org_img, 0, 0, 20, 20, 720, 540); imagejpeg($img,$dest_image,90); imagedestroy($img); $save = $_REQUEST['Saved'] ; $file = $dest_image ; echo "Creating file: $save"; $size = 0.3333333333333333333333333333333333333333333; header('Content-type: image/jpeg') ; list($width, $height) = getimagesize($file) ; $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; header ("Location: $save"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/251902-image-resizing/#findComment-1292277 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.