thinkphp¿ò¼ÜÖеÄͼƬÐýת²Ã¼ô¹¦Ð§ÔõôʵÏÖ
µÚÒ»²½£º×°ÖÃthinkphp¿ò¼Ü
ÏëÒªÔÚ×Ô¼ºµÄ¿ª·¢ÖÐʹÓÃthinkphp¿ò¼Ü×ÔÈ»ÐèÒª½«Ëü×°Öýø×Ô¼ºµÄÏîÄ¿ÖС£thinkphpµÄ×°ÖúÜÊǼòÆÓ£¬Ö»ÐèÒª½«½âѹºóµÄѹËõ°üÖ±½ÓÒÆÈëÏîÄ¿¸ùĿ¼Ï¼´¿É¡£Òƶ¯Ö®ºóÖ»ÐèÒªÐÞ¸ÄÒ»ÏÂÏîÄ¿ÖеÄÈë¿ÚÎļþindex.php¼´¿É×îÏÈʹÓÃthinkphp¡£
µÚ¶þ²½£ºÒýÈëthinkphpÖеÄͼƬ´¦ÀíÀà
ÒýÈëthinkphp¿ò¼ÜÖеÄͼƬ´¦ÀíÀàÓÃÓÚ²Ù×÷ͼƬ£¬Ö÷ÒªÓÐËõ·Å¡¢²Ã¼ô¡¢ÐýתµÈ»ù´¡´¦ÀíÒªÁì¡£ÆäÖÐÐýת²Ã¼ôÊDZ¾ÎÄÐèÒªÏÈÈݵÄÖص㡣
ÔÚ¿ØÖÆÆ÷ÖÐÌí¼ÓÈçÏ´úÂëÒýÈëͼƬ´¦ÀíÀࣺ
use think\Image;
µÇ¼ºó¸´ÖÆ
µÚÈý²½£ºÍ¼Æ¬Ðýת²Ã¼ôµÄʵÏÖ
Ðýת²Ã¼ôÊǶÔͼƬ¾ÙÐÐÐýתºÍ²Ã¼ôµÄ×éºÏ²Ù×÷£¬ÊµÏÖÆðÀ´Ò²ºÜÊǼòÆÓ¡£ÏÂÃæÊDZ¾ÎĵÄÖØÄѵ㲿·Ö¡ª¡ªrotateCropº¯ÊýµÄ´úÂëʵÏÖ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
/** * Ðýת²¢²Ã¼ôͼƬ²Ù×÷ * @param string $image ±»²Ù×÷ͼƬ·¾¶ * @param int $width ²Ã¼ô¿í¶È * @param int $height ²Ã¼ô¸ß¶È * @param int $degree Ðýת½Ç¶È * @return bool|string ´¦ÀíºóÉúÑĵÄÎļþ·¾¶»òÕßfalse **/ public function rotateCrop($image, $width, $height, $degree) { $image = Image::open($image); $image->rotate($degree)->crop($width, $height)->save($image); return $image->save() ? $image->getPathName() : false; }
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öº¯ÊýÖУ¬ÎÒÃÇÐèҪת´ï4¸ö²ÎÊý£ºÍ¼Æ¬Â·¾¶¡¢²Ã¼ô¿í¶È¡¢²Ã¼ô¸ß¶ÈºÍÐýת½Ç¶È£¬ÆäÖÐͼƬ·¾¶ÊDZش«²ÎÊý£¬ÆäËû3¸ö²ÎÊýÊÇ¿ÉÑ¡²ÎÊý£¬¿í¶ÈºÍ¸ß¶ÈĬÒÔΪÁ㣬¼´²»×ö²Ã¼ô´¦Àí¡£Ðýת½Ç¶ÈÒ²ÊÇĬÈÏֵΪ0£¬¼´²»×öÐýת´¦Àí¡£
ÆäÖÐ×îÖ÷ÒªµÄ¾ÍÊÇÐýתºÍ²Ã¼ôµÄ²Ù×÷£¬Image::open($image)º¯ÊýÊÇ¿ªÆôÒ»¸öͼƬ¹¤¾ß£¬ÔÚ¹¤¾ßÖÐŲÓÃrotate()ºÍcrop()ÒªÁì¾ÙÐÐÐýתºÍ²Ã¼ô²Ù×÷£¬×îºósave()ÒªÁìÉúÑIJ¢Êä³öͼƬ¼´¿É¡£
µÚËIJ½£º²âÊÔЧ¹û
×îºóÎÒÃÇÀ´²âÊÔÒ»ÏÂÎÒÃǵĴúÂë¡£ÔÚÎÒÃǵĿØÖÆÆ÷ÖÐÌí¼ÓÈçÏ´úÂ룺
$image = 'image/test.jpg'; $width = 200; $height = 300; $degree = 90; $test = $this->rotateCrop($image, $width, $height, $degree); echo '@@##@@';
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬$imageΪĿµÄͼƬ·¾¶£¬$width¡¢$heightΪ²âÊԲüô²ÎÊý£¬$degreeΪ²âÊÔÐýת²ÎÊý£¬ÔÚÖ´ÐÐÍêÎÒÃǵÄrotateCrop()º¯ÊýÖ®ºó£¬·µ»ØÒ»¸öÉúÑĵÄͼƬ·¾¶£¬×îºó½«ËüÏÔʾÔÚÒ³ÃæÉÏ¡£µ±È·ÈÏÒ»ÇÐ׼ȷÎÞÎóºó£¬ÖØмÓÔØÒ³Ã棬¼´¿Éä¯ÀÀÎÒÃÇ´¦ÀíºóµÄͼƬ
ÒÔÉϾÍÊÇthinkphp¿ò¼ÜÖеÄͼƬÐýת²Ã¼ô¹¦Ð§ÔõôʵÏÖµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡