how to use imagecopyresampled correctly

Discussion in 'PHP' started by figo2476, Apr 4, 2008.

  1. #1
    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?
     
    figo2476, Apr 4, 2008 IP
  2. blognol

    blognol Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    Have you create "imagecreatetruecolor" before "imagecopyresampled". For example see the below code
    $src_image = @imagecreatefromgif($imagepath);
    $dest_image = @imagecreatetruecolor ($output_width, $output_height);
    imagecopyresampled($dest_image, $src_image, 0, 0, 0, 0, $output_width, $output_height, $imgwidth, $imgheight);
    imagegif($dest_image, $imagepath, 100);
     
    blognol, Apr 5, 2008 IP