本文整理汇总了PHP中imagick::rotateImage方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::rotateImage方法的具体用法?PHP imagick::rotateImage怎么用?PHP imagick::rotateImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagick
的用法示例。
在下文中一共展示了imagick::rotateImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: imgRotate
/**
* Rotate image
*
* @param string $path image file
* @param int $degree rotete degrees
* @param string $bgcolor square background color in #rrggbb format
* @param string $destformat image destination format
* @return string|false
* @author nao-pon
* @author Troex Nevelin
**/
protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null)
{
if (($s = @getimagesize($path)) == false) {
return false;
}
$result = false;
switch ($this->imgLib) {
case 'imagick':
try {
$img = new imagick($path);
} catch (Exception $e) {
return false;
}
$img->rotateImage(new ImagickPixel($bgcolor), $degree);
$result = $img->writeImage($path);
return $result ? $path : false;
break;
case 'gd':
$img = self::gdImageCreate($path, $s['mime']);
$degree = 360 - $degree;
list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
$bgcolor = imagecolorallocate($img, $r, $g, $b);
$tmp = imageRotate($img, $degree, (int) $bgcolor);
$result = self::gdImage($tmp, $path, $destformat, $s['mime']);
imageDestroy($img);
imageDestroy($tmp);
return $result ? $path : false;
break;
}
return false;
}
示例2: imgRotate
/**
* Rotate image
*
* @param string $path image file
* @param int $degree rotete degrees
* @param string $bgcolor square background color in #rrggbb format
* @param string $destformat image destination format
* @return string|false
* @author nao-pon
* @author Troex Nevelin
**/
protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null)
{
if (($s = @getimagesize($path)) == false) {
return false;
}
$result = false;
switch ($this->imgLib) {
case 'imagick':
try {
$img = new imagick($path);
} catch (Exception $e) {
return false;
}
$img->rotateImage(new ImagickPixel($bgcolor), $degree);
$result = $img->writeImage($path);
return $result ? $path : false;
break;
case 'gd':
if ($s['mime'] == 'image/jpeg') {
$img = imagecreatefromjpeg($path);
} elseif ($s['mime'] == 'image/png') {
$img = imagecreatefrompng($path);
} elseif ($s['mime'] == 'image/gif') {
$img = imagecreatefromgif($path);
} elseif ($s['mime'] == 'image/xbm') {
$img = imagecreatefromxbm($path);
}
$degree = 360 - $degree;
list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
$bgcolor = imagecolorallocate($img, $r, $g, $b);
$tmp = imageRotate($img, $degree, (int) $bgcolor);
if ($destformat == 'jpg' || $destformat == null && $s['mime'] == 'image/jpeg') {
$result = imagejpeg($tmp, $path, 100);
} else {
if ($destformat == 'gif' || $destformat == null && $s['mime'] == 'image/gif') {
$result = imagegif($tmp, $path, 7);
} else {
$result = imagepng($tmp, $path, 7);
}
}
imageDestroy($img);
imageDestroy($tmp);
return $result ? $path : false;
break;
}
return false;
}
示例3: imgRotate
/**
* Rotate image
*
* @param string $path image file
* @param int $degree rotete degrees
* @param string $bgcolor square background color in #rrggbb format
* @param string $destformat image destination format
* @return string|false
* @author nao-pon
* @author Troex Nevelin
**/
protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null)
{
if (($s = @getimagesize($path)) == false || $degree % 360 === 0) {
return false;
}
$result = false;
// try lossless rotate
if ($degree % 90 === 0 && in_array($s[2], array(IMAGETYPE_JPEG, IMAGETYPE_JPEG2000))) {
$count = $degree / 90 % 4;
$exiftran = array(1 => '-9', 2 => '-1', 3 => '-2');
$jpegtran = array(1 => '90', 2 => '180', 3 => '270');
$quotedPath = escapeshellarg($path);
$cmds = array('exiftran -i ' . $exiftran[$count] . ' ' . $path, 'jpegtran -rotate ' . $jpegtran[$count] . ' -copy all -outfile ' . $quotedPath . ' ' . $quotedPath);
foreach ($cmds as $cmd) {
if ($this->procExec($cmd) === 0) {
$result = true;
break;
}
}
if ($result) {
return $path;
}
}
switch ($this->imgLib) {
case 'imagick':
try {
$img = new imagick($path);
} catch (Exception $e) {
return false;
}
$img->rotateImage(new ImagickPixel($bgcolor), $degree);
$result = $img->writeImage($path);
$img->destroy();
return $result ? $path : false;
break;
case 'gd':
$img = self::gdImageCreate($path, $s['mime']);
$degree = 360 - $degree;
list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
$bgcolor = imagecolorallocate($img, $r, $g, $b);
$tmp = imageRotate($img, $degree, (int) $bgcolor);
$result = self::gdImage($tmp, $path, $destformat, $s['mime']);
imageDestroy($img);
imageDestroy($tmp);
return $result ? $path : false;
break;
}
return false;
}