Jump to content

Image Resizing


melloorr

Recommended Posts

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

Link to comment
Share on other sites

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");

?>

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.