dongxiaoyan4388 2014-02-13 06:24
浏览 98
已采纳

如何在PHP中使用背景图像而不是颜色imagecolorallocate()

I want to create a custom captcha. so i need to convert text and background image as single image;
Now i can use only background color in imagecolorallocate()
here is my code

<?php
$text = rand (1000, 9999);
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img,255, 255, 255);
$text_colour = imagecolorallocate( $my_img, 0, 0, 255 );
$line_colour = imagecolorallocate( $my_img, 255, 255, 255 );
imagestring( $my_img, 4, 30, 25, $text, $text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>

  • 写回答

3条回答 默认 最新

  • douguanci9158 2014-02-13 06:28
    关注

    You can use the imagecreatefromjpg PHP function, or any of its associated functions based on the image type, like imagecreatefrompng.

    This will create an image element in PHP from the selected file that you can use as a background file.

    From the PHP manual.

    Your next option is to use imagecopymerge() that will use an existing image element and merge it with another image. Info from the PHP manual

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

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!