TeddyKiller Posted March 11, 2010 Author Share Posted March 11, 2010 I did an if statement. I dont need pixel sizes now. It'll automatically square the image no matter on the size in the center. I believe it's a masterpiece. It may or may not work.. I haven't tested it so far. Here's the code <?php // Original image $filename = '20070107-ces-billgates-400.jpg'; // cropped image name $filename2 = 'c_' . $filename; // Get dimensions of the original image list($current_width, $current_height) = getimagesize($filename); // This will be the final size of the image (e.g. how many pixels left and down we will be going) if($current_width > $current_height){ $crop_width = $current_height; $crop_height = $current_height; } elseif($current_height > $current_width){ $crop_width = $current_width; $crop_height = $current_width; ) // The x and y coordinates on the original image where we will begin cropping the image $sum1 = $current_width - $crop_width; $left = $sum1 / 2; $sum2 = $current_height - $height; $top = $sum2 / 2; // Resample the image $canvas = imagecreatetruecolor($crop_width, $crop_height); $current_image = imagecreatefromjpeg($filename); imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height); imagejpeg($canvas, $filename2, 100); ?> Quote Link to comment 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.