dqqyp90576 2014-02-14 10:27
浏览 16
已采纳

如何在php中动态生成的图像中添加一些源文件中的jpeg图像

Below is the code to generate an image dynamically in php. I want to add some image in this dynamically created image. I've already tried my luck with imagecopy but failed because I think it deals with the already created image to copy one onto another. So please help asap. Thanks in advance. :)

<?php

$my_img = imagecreate( 1200, 630 );

$background = imagecolorallocate( $my_img, 2,144,162 );

$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );

$text_colour1 = imagecolorallocate( $my_img, 255, 255, 255 );

$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );

$font='C:\Windows\Fonts\ARLRDBD.ttf';

imagettftext($my_img, 48, 0,  450, 100, $text_colour, $font,"Hello World");

$font1='C:\Windows\Fonts\Arial.ttf';

imagettftext($my_img, 32, 0,  650, 160, $text_colour1, $font1,Hello World" );

imagettftext($my_img, 32, 0,  500, 300, $text_colour1, $font1,"Hello World" );

imagettftext($my_img, 32, 0,  560, 440, $text_colour1, $font1,"Hello World" );

header( "Content-type: image/png" );

imagepng( $my_img );

imagepng( $my_img,'Ethers.png' );

imagecolordeallocate( $text_colour );

imagecolordeallocate( $text_colour1 );

imagecolordeallocate( $background );

imagedestroy($my_img);

header('Content-Type: image/png');

imagedestroy($my_img);

?>
  • 写回答

1条回答 默认 最新

  • drde3456 2014-02-14 10:31
    关注

    There are readymade code available for playing with image edits.

    Find the class from the following link.

    http://www.phpclasses.org/package/6323-PHP-Manipulate-GIF-JPEG-and-PNG-images.html

    This class can be used to manipulate GIF, JPEG and PNG images.

    It can load an image in GIF, JPEG and PNG formats and perform several types of operations.

    Currently it can resize the image, render a text on the image, render a watermark image and apply several types of effects like blur, edge detection, sharpen, emboss, etc..

    The resulting image can be saved to a file or displayed as the current script output also in GIF, PNG and JPEG formats.

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

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值