:mad:
I don't know how to tackle my problem -- I 've read the through the image functions in the PHP manual but I still don't know how to do it.
I'm trying to resize an image using the GD Library, proportionally, then I want to make it a square.
For example: a 1600x1200 image, should become 400x300. That would be my "large" image. Then I want to generate thumbnails of that image that are perfect squares (100x100).
I have pasted the code that creates the large image, however, I want to know how I can make the 100x100 square -- I want it to chop from the sides equally.
Example:
400x300 resizes to 133x100 then I want to chop 133 by 16.5 from both sides (rounded of course cus it will have a bit left over).
Any ideas? The only thing I see on cropping allows u to start at an X or Y point... but that doesnt help because i also need to crop from the other side. Any clues please.
== WHAT I HAVE DONE ==
// Begin image-making function
function make_image($originalimage_path,$max_width,$max_height,$destination) {
// Get the submitted image information
$img = imagecreatefromjpeg($originalimage_path);
$originalwidth= imagesx($img);
$originalheight= imagesy($img);
// If the picture is wider than taller
if ($originalwidth > $originalheight) {
$image_w = $max_width;
$image_h = round(($originalheight * $max_width) / $originalwidth);
}
// If the picture is taller than wider
if ($originalwidth < $originalheight) {
$image_w = round(($originalwidth * $max_height) / $originalheight);
$image_h = $max_height;
}
// If the image is smaller than both maxes
if (($originalwidth < $max_width) && ($originalheight < $max_height)) {
$image_w = $originalwidth;
$image_h = $originalheight;
}
// If the original image is a square, set to max height
if ($originalwidth == $originalheight) {
$image_w = $max_height;
$image_h = $max_height;
}
$actual_image = ImageCreateTrueColor($image_w,$image_h);
ImageCopyResampled($actual_image, $img, 0,0,0,0,$image_w,$image_h,$originalwidth,$originalheight);
// Now copy the image to destiny
imagejpeg($actual_image,$destination,90);
imagedestroy($img);
// Once done, insert the filename of the image into the database
chmod($destination, 0644); //chmod the sucker
====