imagecopyresampled() will take a rectangular area from $src_image with a width of $src_w and a height of $src_h at position ($src_x, $src_y) and place it in a rectangular area of $dst_image with a width of $dst_w and a height of $dst_h at position ($dst_x, $dst_y) .
If the source and target coordinates, width and height are different, the corresponding stretching or compression of the image fragment will be performed. Coordinates refer to the upper left corner.
This function can be used to copy areas within a single image. But if the areas overlap, the results will be unpredictable.
- Change -
If $src_w and $src_h less than $dst_w and $dst_h respectively, the thumb image will be enlarged. Otherwise, it will be reduced.
<?php $dst_x = 0; // X-coordinate of destination point $dst_y = 0; // Y-coordinate of destination point $src_x = 100; // Crop Start X position in original image $src_y = 100; // Crop Srart Y position in original image $dst_w = 160; // Thumb width $dst_h = 120; // Thumb height $src_w = 260; // Crop end X position in original image $src_h = 220; // Crop end Y position in original image // Creating an image with true colors having thumb dimensions (to merge with the original image) $dst_image = imagecreatetruecolor($dst_w, $dst_h); // Get original image $src_image = imagecreatefromjpeg('images/source.jpg'); // Cropping imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); // Saving imagejpeg($dst_image, 'images/crop.jpg'); ?>
Eranda Aug 13 '12 at 10:38 2012-08-13 10:38
source share