本文整理汇总了PHP中imageRotate函数的典型用法代码示例。如果您正苦于以下问题:PHP imageRotate函数的具体用法?PHP imageRotate怎么用?PHP imageRotate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageRotate函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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':
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;
}
示例2: __rotate
/**
* Rotate the image clockwise
*
* @param Asido_TMP &$tmp
* @param float $angle
* @param Asido_Color &$color
* @return boolean
* @access protected
*/
function __rotate(&$tmp, $angle, &$color)
{
// skip full loops
//
if ($angle % 360 == 0) {
return true;
}
list($r, $g, $b) = $color->get();
$rotate_color = imageColorAllocate($tmp->target, $r, $g, $b);
if ($t = imageRotate($tmp->target, $angle * -1, $rotate_color)) {
imageDestroy($tmp->target);
$tmp->target = $t;
$tmp->image_width = imageSX($tmp->target);
$tmp->image_height = imageSY($tmp->target);
return true;
}
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) {
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;
}
示例4: 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;
}
if ($img->getNumberImages() > 1) {
$img = $img->coalesceImages();
do {
$img->rotateImage(new ImagickPixel($bgcolor), $degree);
} while ($img->nextImage());
$img = $img->optimizeImageLayers();
$result = $img->writeImages($path, true);
} else {
$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;
}
示例5: rotateImage
//.........这里部分代码省略.........
default:
$errorMsg = 'ErrorNotSupportedImage';
return false;
break;
}
if ($image1) {
// Building image for ROTATING
/* $image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
if (!$image2) {
return 'ErrorNoImageCreateTruecolor';
}*/
/* if(!function_exists("imagerotate")) {
$errorMsg = 'ErrorNoImageRotate';
return false;
}*/
switch ($type) {
case IMAGETYPE_PNG:
// imagealphablending($image1, false);
// imagesavealpha($image1, true);
if (!function_exists("imagecolorallocate")) {
$errorMsg = 'ErrorNoImageColorAllocate';
return false;
}
if (!function_exists("imagefill")) {
$errorMsg = 'ErrorNoImageFill';
return false;
}
if (!function_exists("imagecolortransparent")) {
$errorMsg = 'ErrorNoImageColorTransparent';
return false;
}
$colBlack = imagecolorallocate($image1, 0, 0, 0);
if (!function_exists("imagerotate")) {
$image2 = PhocaGalleryImageRotate::imageRotate($image1, $angle, $colBlack);
} else {
$image2 = imagerotate($image1, $angle, $colBlack);
}
imagefill($image2, 0, 0, $colBlack);
imagecolortransparent($image2, $colBlack);
break;
default:
if (!function_exists("imagerotate")) {
$image2 = PhocaGalleryImageRotate::imageRotate($image1, $angle, 0);
} else {
$image2 = imageRotate($image1, $angle, 0);
}
break;
}
// Get the image size and resize the rotated image if necessary
$rotateWidth = imagesx($image2);
// Get the size from rotated image
$rotateHeight = imagesy($image2);
// Get the size from rotated image
$parameterSize = PhocaGalleryFileThumbnail::getThumbnailResize($size);
$newWidth = $parameterSize['width'];
// Get maximum sizes, they can be displayed
$newHeight = $parameterSize['height'];
// Get maximum sizes, they can be displayed
$scale = $newWidth / $rotateWidth < $newHeight / $rotateHeight ? $newWidth / $rotateWidth : $newHeight / $rotateHeight;
// smaller rate
$src = array(0, 0, $rotateWidth, $rotateHeight);
$dst = array(0, 0, floor($rotateWidth * $scale), floor($rotateHeight * $scale));
// If original is smaller than thumbnail size, don't resize it
if ($src[2] > $dst[2] || $src[3] > $dst[3]) {
// Building image for RESIZING THE ROTATED IMAGE
$image3 = @ImageCreateTruecolor($dst[2], $dst[3]);
示例6: rotateImage
function rotateImage($thumbName, $size, $angle = 90)
{
// Try to change the size
$memory = 8;
$memoryLimitChanged = 0;
$memory = (int) ini_get('memory_limit');
if ($memory == 0) {
$memory = 8;
}
$file_in = $thumbName['abs'];
$file_out = $thumbName['abs'];
if ($file_in !== '' && file_exists($file_in)) {
//array of width, height, IMAGETYPE, "height=x width=x" (string)
list($w, $h, $type) = GetImageSize($file_in);
// we got the info from GetImageSize
if ($w > 0 && $h > 0 && $type != '') {
// Change the $w against $h because of rotating
$src = array(0, 0, $w, $h);
$dst = array(0, 0, $h, $w);
} else {
return 'ErrorWorHorType';
}
// Try to increase memory
if ($memory < 50) {
ini_set('memory_limit', '50M');
$memoryLimitChanged = 1;
}
switch ($type) {
case IMAGETYPE_JPEG:
if (!function_exists('ImageCreateFromJPEG')) {
return 'ErrorNoJPGFunction';
}
$image1 = ImageCreateFromJPEG($file_in);
break;
case IMAGETYPE_PNG:
if (!function_exists('ImageCreateFromPNG')) {
return 'ErrorNoPNGFunction';
}
$image1 = ImageCreateFromPNG($file_in);
break;
case IMAGETYPE_GIF:
if (!function_exists('ImageCreateFromGIF')) {
return 'ErrorNoGIFFunction';
}
$image1 = ImageCreateFromGIF($file_in);
break;
case IMAGETYPE_WBMP:
if (!function_exists('ImageCreateFromWBMP')) {
return 'ErrorNoWBMPFunction';
}
$image1 = ImageCreateFromWBMP($file_in);
break;
default:
return 'ErrorNotSupportedImage';
break;
}
if ($image1) {
// Building image for ROTATING
/* $image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
if (!$image2) {
return 'ErrorNoImageCreateTruecolor';
}*/
if (!function_exists("imagerotate")) {
return 'ErrorNoImageRotate';
}
switch ($type) {
case IMAGETYPE_PNG:
// imagealphablending($image1, false);
// imagesavealpha($image1, true);
if (!function_exists("imagecolorallocate")) {
return 'ErrorNoImageColorAllocate';
}
if (!function_exists("imagefill")) {
return 'ErrorNoImageFill';
}
if (!function_exists("imagecolortransparent")) {
return 'ErrorNoImageColorTransparent';
}
$colBlack = imagecolorallocate($image1, 0, 0, 0);
$image2 = imagerotate($image1, $angle, $colBlack);
imagefill($image2, 0, 0, $colBlack);
imagecolortransparent($image2, $colBlack);
break;
default:
$image2 = imageRotate($image1, $angle, 0);
break;
}
// Get the image size and resize the rotated image if necessary
$rotateWidth = imagesx($image2);
// Get the size from rotated image
$rotateHeight = imagesy($image2);
// Get the size from rotated image
$parameterSize = PhocaGalleryHelper::getFileResize($size);
$newWidth = $parameterSize['width'];
// Get maximum sizes, they can be displayed
$newHeight = $parameterSize['height'];
// Get maximum sizes, they can be displayed
$scale = $newWidth / $rotateWidth < $newHeight / $rotateHeight ? $newWidth / $rotateWidth : $newHeight / $rotateHeight;
// smaller rate
$src = array(0, 0, $rotateWidth, $rotateHeight);
//.........这里部分代码省略.........
示例7: imagecreatetruecolor
$width = $height * $ratio_orig;
} else {
$height = $width / $ratio_orig;
}
# Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($konyvtar . '/' . $fajlnev_n);
if ($degrees != "") {
// Create a square image the size of the largest side of our src image
$kulonb = ($width_orig - $height_orig) / 2;
$tmp = imageCreateTrueColor($width_orig, $width_orig);
// Exchange sides
$image_p = imageCreateTrueColor($height, $width);
// Now copy our src image to tmp where we will rotate and then copy that to $out
imageCopy($tmp, $image, 0, $kulonb, 0, 0, $width_orig, $height_orig);
$tmp2 = imageRotate($tmp, $degrees, 0);
// Now copy tmp2 to $out;
#majd kicsinyíteni a kívánt méretre
imagecopyresampled($image_p, $tmp2, 0, 0, $kulonb, 0, $width, $height + 200, $width_orig, $width_orig);
} else {
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
}
# Output
imagejpeg($image_p, $konyvtar . '/' . $fajlnev_n);
imagedestroy($image_p);
#a képek adatainak rögzítése az adatbázisba
if ($nincsfajl != 1) {
$sql2 = "INSERT INTO " . $_SESSION[adatbazis_etag] . "_galeriakepek (sorszam, fajlnev_nagy, felirat_hu, csoport, kepszam) values ('{$num_rows}', '{$fajlnev_n}', '{$_REQUEST['felirat_hu']}', '{$_REQUEST['csoport']}', '{$num_rowkeps}')";
mysql_query($sql2);
}
}
示例8: rotate
/**
* Rotates this image
* @param float $degrees Rotation angle, in degrees
* @param string $uncoveredColor
* @param boolean $handleTransparancy
* @return Image new Image instance with a rotated version of this image
*/
public function rotate($degrees, $uncoveredColor = '#000000', $handleTransparancy = false)
{
$uncoveredColor = $this->allocateColor($uncoveredColor);
$result = new self($this);
$result->resource = imageRotate($result->resource, $degrees, $uncoveredColor, $handleTransparancy);
return $result;
}
示例9: rotateToExifOrientation
protected function rotateToExifOrientation()
{
if (!$this->exif || empty($this->exif['Orientation'])) {
// No Exif Orientation; nothing to do, return original.
return;
}
$flip = false;
$rotate = 0;
switch ($this->exif['Orientation']) {
case 2:
$flip = true;
$rotate = 0;
break;
case 3:
$flip = false;
$rotate = 180;
break;
case 4:
$flip = true;
$rotate = 180;
break;
case 5:
$flip = true;
$rotate = 270;
break;
case 6:
$flip = false;
$rotate = 270;
break;
case 7:
$flip = true;
$rotate = 90;
break;
case 8:
$flip = false;
$rotate = 90;
break;
default:
break;
}
if ($rotate !== 0) {
$this->image = imageRotate($this->image, $rotate, 0);
$this->width = imageSX($this->image);
$this->height = imageSY($this->image);
$this->exifRotated = true;
}
if ($flip) {
$mirrored = imageCreateTrueColor($this->width, $this->height);
imageCopyResampled($mirrored, $this->image, 0, 0, $this->width, 0, $this->width, $this->height, $this->width, $this->height);
imageDestroy($this->image);
$this->image = $mirrored;
$this->exifRotated = true;
}
}
示例10: imagecreatefromgif
if ($extension == "gif") {
$in = imagecreatefromgif($editDirectory . basename($imageName));
}
if ($extension == "png") {
$in = imagecreatefrompng($editDirectory . basename($imageName));
}
if ($degrees == 180) {
$out = imagerotate($in, $degrees, 180);
} else {
// 90 or 270
$x = imagesx($in);
$y = imagesy($in);
$max = max($x, $y);
$square = imagecreatetruecolor($max, $max);
imagecopy($square, $in, 0, 0, 0, 0, $x, $y);
$square = imageRotate($square, $degrees, 0);
$out = imagecreatetruecolor($y, $x);
if ($degrees == 90) {
imagecopy($out, $square, 0, 0, 0, $max - $x, $y, $x);
} elseif ($degrees == 270) {
imagecopy($out, $square, 0, 0, $max - $y, 0, $y, $x);
}
imagedestroy($square);
}
if ($extension == "jpg" || $extension == "jpeg") {
imagejpeg($out, $editDirectory . basename($imageName), 100);
}
if ($extension == "gif") {
imagegif($out, $editDirectory . basename($imageName));
}
if ($extension == "png") {
示例11: imgRotate
//.........这里部分代码省略.........
$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;
}
}
if (!$jpgQuality) {
$jpgQuality = $this->options['jpgQuality'];
}
elFinder::extendTimeLimit(300);
switch ($this->imgLib) {
case 'imagick':
try {
$img = new imagick($path);
} catch (Exception $e) {
return false;
}
if ($s[2] === IMAGETYPE_GIF || $s[2] === IMAGETYPE_PNG) {
$bgcolor = 'rgba(255, 255, 255, 0.0)';
}
if ($img->getNumberImages() > 1) {
$img = $img->coalesceImages();
do {
$img->rotateImage(new ImagickPixel($bgcolor), $degree);
} while ($img->nextImage());
$img = $img->optimizeImageLayers();
$result = $img->writeImages($path, true);
} else {
$img->rotateImage(new ImagickPixel($bgcolor), $degree);
$result = $this->imagickImage($img, $path, $destformat, $jpgQuality);
}
$img->clear();
return $result ? $path : false;
break;
case 'convert':
extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
if ($s[2] === IMAGETYPE_GIF || $s[2] === IMAGETYPE_PNG) {
$bgcolor = 'rgba(255, 255, 255, 0.0)';
}
$cmd = sprintf('convert %s%s%s -background "%s" -rotate %d%s %s', $quotedPath, $coalesce, $jpgQuality, $bgcolor, $degree, $deconstruct, $quotedDstPath);
$result = false;
if ($this->procExec($cmd) === 0) {
$result = true;
}
return $result ? $path : false;
break;
case 'gd':
$img = $this->gdImageCreate($path, $s['mime']);
$degree = 360 - $degree;
$bgNum = -1;
$bgIdx = false;
if ($s[2] === IMAGETYPE_GIF) {
$bgIdx = imagecolortransparent($img);
if ($bgIdx !== -1) {
$c = imagecolorsforindex($img, $bgIdx);
$w = imagesx($img);
$h = imagesy($img);
$newImg = imagecreatetruecolor($w, $h);
imagepalettecopy($newImg, $img);
$bgNum = imagecolorallocate($newImg, $c['red'], $c['green'], $c['blue']);
imagefill($newImg, 0, 0, $bgNum);
imagecolortransparent($newImg, $bgNum);
imagecopy($newImg, $img, 0, 0, 0, 0, $w, $h);
imagedestroy($img);
$img = $newImg;
$newImg = null;
}
} else {
if ($s[2] === IMAGETYPE_PNG) {
$bgNum = imagecolorallocatealpha($img, 255, 255, 255, 127);
}
}
if ($bgNum === -1) {
list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
$bgNum = imagecolorallocate($img, $r, $g, $b);
}
$tmp = imageRotate($img, $degree, $bgNum);
if ($bgIdx !== -1) {
imagecolortransparent($tmp, $bgNum);
}
$result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
imageDestroy($img);
imageDestroy($tmp);
return $result ? $path : false;
break;
}
return false;
}
示例12: rotate
/**
* Rotate an image the given number of degrees.
*/
public function rotate($source, $destination, $degrees, $background = 0x0)
{
if (!function_exists('imageRotate')) {
return FALSE;
}
$info = $this->getInfo($source);
if (!$info) {
return FALSE;
}
$im = $this->open($source, $info['extension']);
if (!$im) {
return FALSE;
}
$res = imageRotate($im, $degrees, $background);
$result = $this->close($res, $destination, $info['extension']);
return $result;
}
示例13: rotate
function rotate($degrees = 90)
{
self::getSizes();
self::$output_type = strtolower(substr(self::getMime(), strpos(self::getMime(), '/') + 1));
$icfunc = "imagecreatefrom" . self::$output_type;
$img = @$icfunc(self::$original);
if ($degrees == 180) {
$dest = imagerotate($img, $degrees, 180);
} else {
$x = imagesx($img);
$y = imagesy($img);
$max = max($x, $y);
$square = imagecreatetruecolor($max, $max);
imagecopy($square, $img, 0, 0, 0, 0, $x, $y);
$square = imageRotate($square, $degrees, 0);
$dest = imagecreatetruecolor($y, $x);
if ($degrees == 90) {
imagecopy($dest, $square, 0, 0, 0, $max - $x, $y, $x);
} else {
if ($degrees == 270) {
imagecopy($dest, $square, 0, 0, $max - $y, 0, $y, $x);
}
}
imagedestroy($square);
}
imagejpeg($dest, self::$thumb, self::$quality);
self::destroy();
}