ÀûÓÃPHP´´½¨¶¯Ì¬Í¼Ïñ

5年以前  |  阅读数:861 次  |  编程语言:PHP 

Ö»Òª°²×°Ò»Ð(C)µÚÈý*½µÄ¿aÎļþ²¢¾ßÓÐÒ»¶¨µÄ¼¸ºÎ֪ʶ£¬¾Í¿ÉÒÔÀuÓÃPHPÀ´´´½¨ºÍ´¦ÀiͼÏñÁË¡£ÀuÓÃPHP´´½¨¶¯Ì¬Í¼ÏñÊÇÏaµ±ÈÝÒ×µÄÒ»¼þÊÂÇe¡£ÏÂÃae£¬±ÊÕß½«Ïeϸ½eÉÜÈçºÎʵÏÖ¡£

ÔÚʹÓûu±¾µÄͼÏñ´´½¨º¯Êý֮ǰ£¬ÐeÒª°²×°GD¿aÎļþ¡£Èç¹uҪʹÓÃÓeJPEGÓйصÄͼÏñ´´½¨º¯Êý£¬»¹ÐeÒª°²×°jpeg-6b£¬Èç¹uÒªÔÚͼÏñÖÐʹÓÃType 1ÐÍ×ÖÌa£¬Ôo±ØÐe°²×°t1lib¡£

ÔÚ½¨Á¢Í¼Ïñ´´½¨»*¾³Ö®Ç°£¬»¹ÐeÒª×oÒ»Ð(C)×¼±¸¹¤×÷¡£Ê×ÏÈ£¬°²×°t1lib½Ó×Å°²×°jpeg-6b£¬È»ºoÔÙ°²×°GD¿aÎļþ¡£ÔÚ°²×°Ê±Ò»¶¨Òª°´ÕaÀi¸ø¶¨µÄ˳Ðo½øÐа²×°£¬ÒoΪÔÚ±aÒeGDÈe¿aʱ»aÓõ½jpeg-6b£¬Èç¹uûÓа²×°jpeg-6b£¬ÔÚ±aÒeʱ¾Í»a³o´i¡£

ÔÚ°²×°ÍeÕaÈý¸o×e¼þºo£¬»¹ÐeÒªÖØÐÂÅaÖÃÒ»´ÎPHP£¬ÕaÒ²ÊÇÄa¶Ô²ÉÓÃDSO½Ê½°²×°PHP¸Ðµ½ÇiÐҵĵؽ֮һ¡£ÔËÐÐmake clean£¬È»ºoÔÚµ±Ç°µÄÅaÖÃÖÐÌi¼ÓÏÂÃaeµÄÄÚÈÝ£º

--with-gd=[/path/to/gd]
--with-jpeg-dir=[/path/to/jpeg-6b]
--with-t1lib=[/path/to/t1lib]

Íe³ÉÌi¼ÓºoÖ´ÐÐmakeÃuÁi£¬È»ºoÔÙÖ´ÐÐmake installÃuÁi£¬ÖØÐÂÆo¶¯ApacheºoÔËÐÐphpinfo()À´¼i²eÒ»ÏÂеÄÉeÖÃÊÇ*ñÉuЧÁË¡£ÏÖÔÚ£¬ÎÒÃǾͿÉÒÔ¿ªÊ¼Í¼Ïñ´´½¨¹¤×÷ÁË¡£

¸u¾ÝËu°²×°µÄGD¿aÎļþµÄ°ae±¾½«¾o¶¨ÄaÊÇ*ñÄÜ´´½¨GIF»oPNG¸ñʽµÄͼÐÎÎļþ¡£Èç¹u°²×°µÄÊÇgd-1.6»oÒÔÇ°µÄ°ae±¾£¬¿ÉÒÔʹÓÃGIF¸ñʽµÄÎļþµ«²»ÄÜ´´½¨PNG¸ñʽ£¬Èç¹u°²×°µÄÊÇgd-1.6ÒÔºoµÄ°ae±¾£¬¿ÉÒÔ´´½¨PNGÎļþµ«²»ÄÜ´´½¨GIF¸ñʽµÄÎļþ¡£

´´½¨Ò»*u¼oµ¥µÄͼÏñÒ²ÐeÒªÓõ½Ði¶aµÄº¯Êý£¬ÎÒÃǽ«Ò»²½Ò»²½µØ½øÐÐ˵Ã÷¡£

ÔÚÏÂÃaeµÄÀý×ÓÖУ¬ÎÒÃǽ«´´½¨Ò»¸oPNG¸ñʽµÄͼÏñÎļþ£¬ÏÂÃaeµÄ´uÂeÊÇÒ»¸o°uº¬Ëu´´½¨µÄͼÏñµÄMIMEÀaÐ͵ÄÍ*²¿£º

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

ʹÓÃImageCreate()´´½¨Ò»¸o´u±i¿Õ°×ͼÏñµÄ±aÁ¿£¬Õa¸oº¯ÊýÒªÇoÒÔÏñËØΪµ¥Î»µÄͼÏñ´oСµÄ²ÎÊý£¬Æa¸ñʽÊÇImageCreate(x_size, y_size)¡£Èç¹uÒª´´½¨Ò»¸o´oСΪ250¡Á250µÄͼÏñ£¬¾Í¿ÉÒÔʹÓÃÏÂÃaeµÄÓi¾a£º

$newImg = ImageCreate(250,250);

ÓÉÓÚͼÏñ»¹Êǿհ׵ģ¬Òo´ËÄa¿ÉÄÜ»aÏ£ÍuÓÃÒ»Ð(C)²ÊÉ«À´Ìi³aËu¡£ÄaÐeÒªÊ×ÏÈʹÓÃImageColorAllocate()º¯ÊýÓÃÆaRGBֵΪÕaÖÖÑÕÉ«Ö¸¶¨Ò»¸oÃu×Ö£¬ÕaÒ»º¯ÊýµÄ¸ñʽΪImageColorAllocate([image], [red], [green], [blue])¡£Èç¹uÒª¶¨ÒaÌiÀ¶É«£¬¿ÉÒÔʹÓÃÈçϵÄÓi¾a£º

$skyblue = ImageColorAllocate($newImg,136,193,255);

½ÓÏÂÀ´£¬ÐeҪʹÓÃImageFill()º¯ÊýÓÃÕaÖÖÑÕÉ«Ìi³aÕa¸oͼÏñ£¬ImageFill()º¯ÊýÓм¸¸o°ae±¾£¬ÀýÈçImageFillRectangle()¡¢ImageFillPolygon()µÈ¡£Îª¼oµ¥Æð¼u£¬ÎÒÃÇͨ¹ýÈçϵĸñʽʹÓÃImageFill()º¯Êý£º

ImageFill([image], [start x point], [start y point], [color])
ImageFill($newImg,0,0,$skyblue);

×iºo£¬ÔÚͼÏñ½¨Á¢ºoÊÍ*ÅͼÏñ¾a±uºÍËuÕ¼ÓõÄÄÚ´ae£º

ImagePNG($newImg);
ImageDestroy($newImg); ?£¾

ÕaÑu£¬´´½¨Í¼ÏñµÄÈ«²¿´uÂeÈçÏÂËuʾ£º

£¼? header ("Content-type: image/png");
$newImg = ImageCreate(250,250);
$skyblue = ImageColorAllocate($newImg,136,193,255);
ImageFill($newImg,0,0,$skyblue);
ImagePNG($newImg);
ImageDestroy($newImg);
?£¾

Èç¹u°ÑÕa¸o½Å±¾Îļþ±£´aeΪskyblue.php£¬²¢ÓÃa¯ÀÀÆ÷*ÃÎÊËu£¬ÎÒÃÇ»a¿´µ½Ò»¸oÌiÀ¶É«µÄ250¡Á250µÄPNG¸ñʽµÄͼÏñ¡£

ÎÒÃÇ»¹¿ÉÒÔʹÓÃͼÏñ´´½¨º¯Êý¶ÔͼÏñ½øÐд¦Ài£¬ÀýÈç°ÑÒ»¸o½Ï´oͼÏñ×÷³ÉÒ»¸oСͼÏñ£º

¼ÙÉeÄaÓÐÒ»uͼÏñ£¬Ïe´ÓÖвüo³oÒ»¸o35¡Á35´oСµÄͼÏñ¡£ÄaËuÐeÒª×÷µÄÊÇ´´½¨Ò»¸o35¡Á35´oСµÄ¿Õ°×ͼÏñ£¬´´½¨Ò»¸o°uº¬Ô­À´Í¼ÏñµÄͼÏñÁ÷£¬È»ºo°ÑÒ»¸o¾­¹ýµ÷Õu´oСµÄÔ­À´µÄͼÏñŵ½ÐµĿհ×ͼÏñÖС£

ÒªÍe³ÉÕaÒ»ÈÎÎñµÄ¹Ø¼uº¯ÊýÊÇImageCopyResized()£¬ËuÒªÇoµÄ¸ñʽÈçÏÂËuʾ£º

ImageCopyResized([new image handle],[original image handle],[new image X], [new Image Y], [original image X], [original image Y], [new image X], [new image Y], [original image X], [original image Y])¡£
£¼? / ¢ËÍÒ»¸oͲ¿£¬ÒÔ±aÈÃa¯ÀÀÆ÷ÖªµÀ¸ÃÎļþËu°uº¬µÄÄÚÈÝÀaÐÍ/
header("Content-type: image/png");
/ ½¨Á¢±£´aeÐÂͼÏñ¸ß¶ÈºÍ¿i¶ÈµÄ±aÁ¿/
$newWidth = 35;
$newHeight = 35;
/ ½¨Á¢¸ø¶¨¸ß¶ÈºÍ¿i¶ÈµÄеĿհ×ͼÏñ/
$newImg = ImageCreate($newWidth,$newHeight);
/ ´ÓÔ­À´½Ï´oµÄͼÏñÖеõ½Êý¾Ý/
$origImg = ImageCreateFromPNG("test.png");
/¿½±´µ÷Õu´oСºoµÄͼÏñ£¬Ê¹ÓÃImageSX()¡¢ImageSY()µÃµ½Ô­À´µÄͼÏñÔÚX¡¢Y½ÃaeÉϵĴoС /
ImageCopyResized($newImg,$origImg,0,0,0,0,$newWidth,$newHeight,ImageSX($origImg),ImageSY($origImg));
/
´´½¨Ï£ÍuµÃµ½µÄͼÏñ£¬ÊÍÅÄÚ´ae /
ImagePNG($newImg);
ImageDestroy($newImg); ?£¾

Èç¹u°ÑÕaһС¶Î½Å±¾±£´aeΪresized.php£¬È»ºoÓÃa¯ÀÀÆ÷¶ÔËu½øÐÐ*ÃÎÊ£¬¾Í»a¿´µ½Ò»¸o35¡Á35´oСµÄPNG¸ñʽµÄͼÏñ¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例