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条)

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目