Search the Community
Showing results for tags 'gd library'.
-
Hi Larry, I have another piece of code that I just can't make work properly. I have Googled and I think that I'm using the correct code but all I get is a jpg image of the correct size and shape but it is blank. $newname is a relative URL to a large jpg image file that I know is there. I need a square thumbnail jpg image so I'm trying to crop the original image correctly to a square and also downsize it. I definitely have the GD library in my PHP. // crop and resize the image file // Get dimensions of the original image list($current_width, $current_height) = getimagesize($newname); echo "<p><font color='yellow'>Current width is $current_width, current height is $current_height.</font></p>"; // now work out the x and y coordinates on the original image where we // will begin cropping the image if ($current_width > $current_height) { // image type = "Landscape" $left = ($current_width - $current_height) / 2; $top = 0; $new_width = $current_width - (2 * $left); $new_height = $current_height; } elseif ($current_height > $current_width) { // image type = "Portrait" $top = ($current_height - $current_width) / 2; $left = 0; $new_width = $current_width; $new_height = $current_height - (2 * $top); } else { // image is square $top = 0; $left = 0; } // This will be the final size of the image (e.g. how many pixels // left and down we will be going) $crop_width = (int) $_POST['size']; $crop_height = (int) $_POST['size']; echo "<p><font color='yellow'>Parameters are left: $left, top: $top, new width: $new_width, new height: $new_height.</font></p>"; // Resample the image $canvas = imagecreatetruecolor($crop_width, $crop_height); $current_image = imagecreatefromjpeg($newname); imagecopy($canvas, $current_image, 0, 0, $left, $top, $new_width, $new_height); // imagecopy($canvas, $current_image, 0, 0, 0, 0, $current_width, $current_height); /* the imagecopy parameters are: 1) Destination image link resource 2) Source image link resource 3) x-coordinate of destination point 4) y-coordinate of destination point 5) x-coordinate of source point 6) y-coordinate of source point 7) Source width 8) Source height */ header('Content-Type: image/jpeg'); imagejpeg($canvas, $newname, 100); Any help will be appreciated. Cheers from Oz.