×ðÁú¿­Ê±¹ÙÍøµÇ¼

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¿ò¼ÜÖеÄͼƬÐýת²Ã¼ô¹¦Ð§ÔõôʵÏÖµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼  ¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ  ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý  ¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ