dqsa17330 2013-01-10 00:10
浏览 38
已采纳

PHP GD imagefill - 填充到源的左侧

I am extending an image canvas with PHP gd:

    $newimage = imagecreatetruecolor($imageWidth + 840, $imageHeight);
    $color = imagecolorallocate($newimage, 0, 0, 0);
    imagefill($newimage, 0, 0, $color);
    imagecopy($newimage, $image, 0, 0, 0, 0, $imageWidth, $imageHeight);

    //get extension of the cropped image
    $ext = end(explode('.' , $imageName));

    //timestamp it
    $timestamp = time();

    //rename the new image
    $fileName = rand() . $timestamp . '.' . $ext;

    //unlink old image
    unlink($src);

    //update the DB with new imagename
    $update = array('update' => $this->image->update($imageID, $fileName));

    //Set the path for the image
    $path = 'data/gallery/' . $galleryID . '/images/album/' . $fileName;

    //create the cropped image
    imagejpeg($newimage,$path,$jpeg_quality);

This works as expected, the canvas is extended to the right 840 pixels. What I would like to be able to do is extend the canvas to the left 840 pixels. Not sure how to make this happen.

Thanks for the help.

  • 写回答

1条回答 默认 最新

  • douzuan5365 2013-01-10 00:32
    关注

    Actually pretty simple once I deciphered all the parameters.

    imagecopy ( resource dest_image, resource source_image, int dest_x, int dest_y, int source_x, int source_y, int source_width, int source_height)
    
    • The destination image you're copying to

    • The source image you're copying from

    • The X co-ordinate you want to copy to

    • The Y co-ordinate you want to copy to

    • The X co-ordinate you want to copy from

    • The y co-ordinate you want to copy from

    • The width in pixels of the source image you want to copy

    • The height in pixels of the source image you want to copy

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题