douba9776 2012-07-18 07:10
浏览 51
已采纳

将图像合并在一起并没有真正发挥作用

I can't seem to merge 2 images for some reason and I have no clue what I'm doing wrong. This is still a bit new to me. here is the code I have:

$source = 'http://localhost:8888/develop/trunk/develop/wp-content/uploads/2012/07/card01-80x80.jpg';
$im = imagecreatetruecolor(200, 200);
$black = imagecolorallocate($im, 0, 0, 0);
// Make the background transparent
imagecolortransparent($im, $black);
$text_color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagejpeg($im, WP_UPLOADS_PATH . 'post-image-generator/1.jpg');


//merge images
$thumb = imagecreatefromjpeg($source);
$destination = imagecreatefromjpeg(WP_UPLOADS_PATH . 'post-image-generator/1.jpg');


imagecopymerge($destination, $thumb, 0, 0, 0, 0, 0, 0, 100);


imagejpeg($destination, WP_UPLOADS_PATH . 'post-image-generator/1.jpg');

echo "
    <style></style>
    <img src='" . WP_UPLOADS_URL . 'post-image-generator/1.jpg' . "' />
        ";


imagedestroy($thumb);
imagedestroy($destination);
imagedestroy($im);

It generates the following:

generated image

but should also include the following image:

missing image

Any help is appreciated

  • 写回答

1条回答 默认 最新

  • dongqin1075 2012-07-18 08:07
    关注

    As far as I can tell without actually testing it, it's this:

    imagecopymerge($destination, $thumb, 0, 0, 0, 0, 0, 0, 100);

    The area you're copying from starts at 0,0 in $thumb, and the width and height of the area to be copied is 0 and 0. Since the source picture is 80x80 and you want the whole thing to be copied to the top left corner of the first image, you'd need to change it to:

    imagecopymerge($destination, $thumb, 0, 0, 0, 0, 80, 80, 100);

    This copies the whole 80-pixel image to the top left corner of $destination.

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

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题