Jump to content

how to use imagecopyresampled correctly


figo2476

Recommended Posts

I have an image and I want to crop portion of the original image.

 

imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )

 

I pass the cropped image size & original image size to the function. The end result is that a smaller image with black spacing around the bottom and right side. Then the original image (it resize itself ugly) to the rest of the area.

 

But if the dst and src are in the same width and height, the end result has no problem. Any hint?

Link to comment
https://forums.phpfreaks.com/topic/99659-how-to-use-imagecopyresampled-correctly/
Share on other sites

From my understanding, src_w & src_h are the original width and height. dest_x & dest_y are the dimension I want them to be.

 

"same proportions": em.. users can clip portion from the original image. (The clip functionality I provided). So  it is not in same proportions.

 

The end result is users clip the image and it should return that part in original quality.

Hard to say without seeing your entire code, but here's what I use:

<?php

// creates a copy of a selected chunk of image.jpg

$filename= "image.jpg";
list($w, $h, $type, $attr) = getimagesize($filename);
$src_im = imagecreatefromjpeg($filename);

$src_x = '0';   // begin x
$src_y = '0';   // begin y
$src_w = '100'; // width
$src_h = '100'; // height
$dst_x = '0';   // destination x
$dst_y = '0';   // destination y

$dst_im = imagecreatetruecolor($src_w, $src_h);
$white = imagecolorallocate($dst_im, 255, 255, 255);
imagefill($dst_im, 0, 0, $white);

imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);

header("Content-type: image/png");
imagepng($dst_im);
imagedestroy($dst_im);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.