dougang1965 2013-02-07 13:46
浏览 86
已采纳

在左侧和右侧裁剪图像

I have an image with dimensions 1440 X 500.

I need to crop this image on the left at 200px and right at 200px. That is the new image must have dimensions of 1040 X 500.

I am trying this

$original_w = 1440;
$original_h = 500;

$new_w = 1040;
$new_h = 500;

$new_img = imagecreatetruecolor( $new_w, $new_h);
imagecopyresampled($new_img, $original_img, 200, 0, 200, 0, $new_w, $new_h, $original_w, $original_h);

I have not obtained a desirable result, please help, what I am doing wrong?

  • 写回答

2条回答 默认 最新

  • doujiao3072 2013-02-07 13:53
    关注

    Reading PHP doc, you're using imagecopyresampled wrong :

    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 
    )
    

    So :

    $original_w = 1440;
    $original_h = 500;
    
    $new_w = 1040;
    $new_h = 500;
    
    $new_img = imagecreatetruecolor( $new_w, $new_h);
    imagecopyresampled($new_img, $original_img, 0, 0, 200, 0, $new_w, $new_h, $new_w, $new_h);
    

    Copying the 1040*500 box from (200,0) coords to the new image, at (0,0) coords.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波