dtj4307 2011-07-20 06:19
浏览 20
已采纳

如何在PHP中绘制png图像?

$image = imagecreatetruecolor(538,616);

$black = imagecolorallocate($image,0,0,0);

imagefill($image,0,0,$black);

I have already draw a black image i want draw a file suppose 3.png on it .. How to do that ?

  • 写回答

3条回答 默认 最新

  • dpd3447 2011-07-20 06:43
    关注

    You have to load an image you want to draw and then use imagecopy() to draw it:

    // the part you already have; creates 538x616 px black image
    $image = imagecreatetruecolor(538,616);
    $black = imagecolorallocate($image,0,0,0);
    imagefill($image,0,0,$black);
    
    // load image from file and draw it onto black image;
    // for loading PNG, use imagecreatefrompng()
    $overlayImage = imagecreatefromjpeg('macro_photo_1.jpg');
    imagecopy($image, $overlayImage, 10, 10, 0, 0, imagesx($overlayImage), imagesy($overlayImage));
    
    // send image to the browser    
    header("Content-Type: image/png");
    imagepng($image);
    exit;
    

    I would also advise to go through the list of GD and Image functions to see what (and how) can be done with images in PHP.

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

报告相同问题?

悬赏问题

  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信
  • ¥30 Python调用dll文件输出Nan重置dll状态
  • ¥15 浮动div的高度控制问题。
  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题
  • ¥15 pic16F877a单片机的外部触发中断程序仿真失效
  • ¥15 Matlab插值拟合差分微分规划图论