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 设计一个温度闭环控制系统
  • ¥100 关于加载卡的问题有能知道这个要怎么处理吗?
  • ¥100 rtmpose姿态评估
  • ¥15 java 通过反射找路径下的类,打包后就找不到
  • ¥15 通联支付网上收银统一下单接口
  • ¥15 angular有偿编写,
  • ¥15 centos7系统下abinit安装时make出错
  • ¥15 hbuildex运行微信小程序报错
  • ¥15 关于#python#的问题:我知道这个问题对你们来说肯定so easy
  • ¥15 wpf datagrid如何实现多层表头