年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2077|回复: 0

PHP中使用PD库处理本地图片示例

[复制链接]
  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

    发表于 2016-1-6 15:32:51 | 显示全部楼层 |阅读模式
    下载.jpg
    [PHP] 纯文本查看 复制代码
    <?php
    	
    	
    	$file = "[email protected]";
    	// 返回数组,包含宽、高、类型
    	list($width, $height, $type) = getimagesize($file);
    	// 1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。
    	$type_array = array(1=>"gif", 2=>"jpeg", 3=>"png");
    	header("Content-type: image/{$type_array[$type]}");
    	// 通过类型拼接相应的调用函数
    	$createimage = "imagecreatefrom".$type_array[$type];
    	 
    	 // 创建图片资源
    	$image = $createimage($file);
    	// 颜色
    	$blue = imagecolorallocate($image, 0, 0, 255);
    	
    	// 在图片中间画上字符串“Hello PHP”
    	$string = "Hello PHP";
    	$w = imagefontheight(5)*strlen($string);
    	$h = imagefontheight(5);
    	$x = ($width - $w) * 0.5;
    	$y = ($height - $h) * 0.5;
    	imagestring($image, 5, $x, $y, $string, $blue);
    	
    	// 输出图片并释放资源
    	imagejpeg($image);
    	imagedestroy($image);

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-4-29 07:09 , Processed in 0.058785 second(s), 25 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表