本文整理汇总了PHP中imagerotate函数的典型用法代码示例。如果您正苦于以下问题:PHP imagerotate函数的具体用法?PHP imagerotate怎么用?PHP imagerotate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagerotate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: orientate
/**
* Orientate the image.
*
* @param UploadedFile $file
* @param $orientation
* @return UploadedFile
*/
protected function orientate(UploadedFile $file, $orientation)
{
$image = imagecreatefromjpeg($file->getRealPath());
switch ($orientation) {
case 2:
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 3:
$image = imagerotate($image, 180, 0);
break;
case 4:
$image = imagerotate($image, 180, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 5:
$image = imagerotate($image, -90, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 6:
$image = imagerotate($image, -90, 0);
break;
case 7:
$image = imagerotate($image, 90, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 8:
$image = imagerotate($image, 90, 0);
break;
}
imagejpeg($image, $file->getRealPath(), 90);
return new UploadedFile($file->getRealPath(), $file->getClientOriginalName(), $file->getMimeType(), $file->getSize());
}
示例2: rotate
/**
* rotate image
*/
public static function rotate($filename)
{
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
switch ($extension) {
case 'gif':
$img_r = imagecreatefromgif($filename);
$dst_r = imagerotate($img_r, -90, 0);
imagegif($dst_r, $filename);
break;
case 'jpg':
case 'jpeg':
$img_r = imagecreatefromjpeg($filename);
$dst_r = imagerotate($img_r, -90, 0);
imagejpeg($dst_r, $filename, 75);
break;
case 'png':
$img_r = imagecreatefrompng($filename);
$dst_r = imagerotate($img_r, -90, 0);
imagealphablending($dst_r, false);
imagesavealpha($dst_r, true);
imagepng($dst_r, $filename, 9);
break;
default:
return false;
}
return true;
}
示例3: rotate
public function rotate($path, $degrees)
{
header('Content-type: image/png');
$source = imagecreatefrompng($path);
$rotate = imagerotate($source, $degrees, 0);
imagepng($rotate, $path);
}
示例4: applyFilter
/**
* (non-PHPdoc)
* @see \imagemanipulation\filter\IImageFilter::applyFilter()
*/
public function applyFilter(ImageResource $resource)
{
if ($this->radius === 0) {
return;
}
$source_image = $resource->getResource();
$source_width = $resource->getX();
$source_height = $resource->getY();
$corner_image = imagecreatetruecolor($this->radius, $this->radius);
$clear_colour = imagecolorallocate($corner_image, 0, 0, 0);
imagecolortransparent($corner_image, $clear_colour);
$solid_colour = imagecolorallocate($corner_image, $this->color->getRed(), $this->color->getGreen(), $this->color->getBlue());
imagefill($corner_image, 0, 0, $solid_colour);
imagefilledellipse($corner_image, $this->radius, $this->radius, $this->radius * 2, $this->radius * 2, $clear_colour);
/*
* render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask
*/
imagecopymerge($source_image, $corner_image, 0, 0, 0, 0, $this->radius, $this->radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($source_image, $corner_image, 0, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($source_image, $corner_image, $source_width - $this->radius, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($source_image, $corner_image, $source_width - $this->radius, 0, 0, 0, $this->radius, $this->radius, 100);
}
示例5: setImageFile
/**
* Set image resource from file
*
* @param string $file Path to image file
* @return ImageManipulator for a fluent interface
* @throws InvalidArgumentException
*/
public function setImageFile($file, $ios)
{
if (!(is_readable($file) && is_file($file))) {
throw new InvalidArgumentException("Image file {$file} is not readable");
}
if (is_resource($this->image)) {
imagedestroy($this->image);
}
list($this->width, $this->height, $type) = getimagesize($file);
switch ($type) {
case IMAGETYPE_GIF:
$tmp = imagecreatefromgif($file);
break;
case IMAGETYPE_JPEG:
$tmp = imagecreatefromjpeg($file);
break;
case IMAGETYPE_PNG:
$tmp = imagecreatefrompng($file);
break;
default:
throw new InvalidArgumentException("Image type {$type} not supported");
}
if ($ios) {
$this->image = imagerotate($tmp, 270, 0);
imagedestroy($tmp);
} else {
$this->image = $tmp;
}
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
return $this;
}
示例6: flip
/**
* 修改一个图片 让其翻转指定度数
*
* @param string $filename 文件名(包括文件路径)
* @param string $src 输出文件名(包括文件路径)
* @param float $degrees 旋转度数 -90顺时针 90逆时针
*/
function flip($filename, $src, $degrees = 90)
{
//读取图片
$data = @getimagesize($filename);
if ($data == false) {
return false;
}
//读取旧图片
switch ($data[2]) {
case 1:
$src_f = imagecreatefromgif($filename);
break;
case 2:
$src_f = imagecreatefromjpeg($filename);
break;
case 3:
$src_f = imagecreatefrompng($filename);
break;
}
if ($src_f == "") {
return false;
}
$rotate = @imagerotate($src_f, $degrees, 0);
if (!imagejpeg($rotate, $src, 100)) {
return false;
}
@imagedestroy($rotate);
return true;
}
示例7: fixOrientation
public function fixOrientation()
{
if (exif_imagetype($this->image) == 2) {
$exif = exif_read_data($this->image);
if (array_key_exists('Orientation', $exif)) {
$orientation = $exif['Orientation'];
$images_orig = ImageCreateFromJPEG($this->image);
$rotate = "";
switch ($orientation) {
case 3:
$rotate = imagerotate($images_orig, 180, 0);
break;
case 6:
$rotate = imagerotate($images_orig, -90, 0);
break;
case 8:
$rotate = imagerotate($images_orig, 90, 0);
break;
}
if ($rotate != "") {
ImageJPEG($rotate, $this->image);
ImageDestroy($rotate);
}
ImageDestroy($images_orig);
}
}
}
示例8: rotate
public function rotate($angle)
{
$this->_imageHandler = imagerotate($this->_imageHandler, $angle, -1);
imagealphablending($this->_imageHandler, true);
imagesavealpha($this->_imageHandler, true);
$this->refreshImageDimensions();
}
示例9: _rotate
protected function _rotate($degrees)
{
extract(parent::_rotate($degrees));
$degrees = 360 - $degrees;
$color = $this->create_color($this->image_data, $this->config['bgcolor'], 1000);
$this->image_data = imagerotate($this->image_data, $degrees, $color, false);
}
示例10: __construct
/**
* Create a new captcha.
*
* @param integer $characters The amount of characters to show.
* @param integer $width
* @param integer $height
*
* @return image resource
*/
public function __construct($characters = 10, $width = 145, $height = 65)
{
$this->captcha = new Captcha_Text($characters, $width - 2, $height / 2.8);
$im = imagecreatetruecolor($width, $height);
$noise_color = imagecolorallocate($im, 131, 131, 131);
$background_color = imagecolorallocate($im, 244, 0, 0);
imagefill($im, 0, 0, $background_color);
// Fetch captcha text
$cpt = $this->captcha->getImage();
$w = imagesx($cpt);
$h = imagesy($cpt);
// Rotate captcha text
$cpt2 = imagerotate($cpt, rand(1, 20), rand(1, 9));
imagecopy($im, $cpt2, rand(1, 5), rand(1, 6), rand(1, 5), rand(1, 6), $width, $height);
// Make some noise.
for ($i = 0; $i < $width * $height / 6; $i++) {
imagefilledellipse($im, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
}
//$im = imagerotate($im, rand(0, 30), rand(0, 5));
// Assign captcha
$this->render = $im;
// Clean used images
imagedestroy($cpt);
imagedestroy($cpt2);
}
示例11: render_text_on_gd_image
function render_text_on_gd_image($target, $imgSize, $text, $font, $size, $color, $opacity, $rotation)
{
$im = imagecreatetruecolor($imgSize[0], $imgSize[1]);
//$black = imagecolorallocate($im, 0, 0, 0);
//imagecolortransparent($im, $black);
imagealphablending($im, false);
imagesavealpha($im, true);
$transparent = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefill($im, 0, 0, $transparent);
//imagecolortransparent($im, $transparent);
$source_width = $imgSize[0];
$source_height = $imgSize[1];
$bb = $this->imagettfbbox_fixed($size, 0, $font, $text);
$x = $bb[0] + $imgSize[0] / 2 - $bb[4] / 2 - 5;
$y = $bb[1] + $imgSize[1] / 2 - $bb[5] / 2 - 5;
$alpha_color = imagecolorallocatealpha($im, $color[0], $color[1], $color[2], 127 * (100 - $opacity) / 100);
imagettftext($im, $size, 0, $x, $y, $alpha_color, $font, $text);
if ($rotation != 0) {
$new = imagerotate($im, $rotation, $transparent);
imagealphablending($new, false);
imagesavealpha($new, true);
imagedestroy($im);
$im = $new;
}
/*$newWidth = imagesx($tmpImage);
$newHt = imagesy($tmpImage);
imagecopymerge($image, $tmpImage, $x - $newWidth + $dropdown, $y - $newHt, 0, 0, $newWidth, $newHt, 100);*/
imagepng($im, $target);
imagedestroy($im);
return TRUE;
}
示例12: imgrotate
function imgrotate($dir, $sens)
{
$src = imagecreatefromjpeg($dir);
// Rotation
$rotate = imagerotate($src, $sens, 0);
return imagejpeg($rotateFull, $dir, 100);
}
示例13: execute
/**
* Returns rotated image
*
* @param WideImage_Image $image
* @param numeric $angle
* @param int $bgColor
* @param bool $ignoreTransparent
* @return WideImage_Image
*/
function execute($image, $angle, $bgColor, $ignoreTransparent)
{
$angle = -floatval($angle);
if ($angle < 0) {
$angle = 360 + $angle;
}
$angle = $angle % 360;
if ($angle == 0) {
return $image->copy();
}
if ($bgColor === null) {
if ($image->isTransparent()) {
$bgColor = $image->getTransparentColor();
} else {
$tc = array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127);
if ($image->isTrueColor()) {
$bgColor = $image->getExactColorAlpha($tc);
if ($bgColor == -1) {
$bgColor = $image->allocateColorAlpha($tc);
}
} else {
$bgColor = $image->getExactColor($tc);
if ($bgColor == -1) {
$bgColor = $image->allocateColor($tc);
}
}
}
}
return new WideImage_TrueColorImage(imagerotate($image->getHandle(), $angle, $bgColor, $ignoreTransparent));
}
示例14: save
function save($filename, $image_type = 2, $compression = 80, $permissions = null)
{
if ($image_type == 2) {
//jpg
$exif = exif_read_data($filename);
$ort = 1;
if (isset($exif['Orientation'])) {
$ort = $exif['Orientation'];
}
if ($ort == 3) {
$this->image = imagerotate($this->image, 180, -1);
} else {
if ($ort == 5 || $ort == 6 || $ort == 7) {
$this->image = imagerotate($this->image, -90, -1);
} else {
if ($ort == 8) {
$this->image = imagerotate($this->image, 90, -1);
}
}
}
imagejpeg($this->image, $filename);
//imagejpeg($this->image,$filename,$compression);
} elseif ($image_type == 1) {
//gif
imagegif($this->image, $filename);
} elseif ($image_type == 3) {
//png
imagepng($this->image, $filename);
}
if ($permissions != null) {
chmod($filename, $permissions);
}
}
示例15: generateImage
function generateImage($certiImage, $posXString, $posYString, $posX2String, $posY2String, $valueString)
{
$certiPath = dirname(__FILE__);
$certiImage = imagecreatefromjpeg($certiPath . '/certi_images/' . $certiImage);
$color = imagecolorallocate($certiImage, 0, 0, 0);
//black
// $whiteBackground = imagecolorallocate($background, 255, 255, 255);
// $imagefill($certiImage,0,0,$whiteBackground);
$rotatedImage = imagerotate($certiImage, 90, $color);
//rotate certificate
$font = $certiPath . '/fonts/odstemplik.otf';
$posXArray = explode("::", $posXString);
$posYArray = explode("::", $posYString);
$posX2Array = explode("::", $posX2String);
$posY2Array = explode("::", $posY2String);
$valuesArray = explode("::", $valueString);
// error_log(print_r($valuesArray));
for ($i = 0; $i < sizeof($valuesArray); $i++) {
$lineWidth = $posYArray[$i] - $posY2Array[$i];
$font_size = 90;
do {
$p = imagettfbbox($font_size, 0, $font, $valuesArray[$i]);
$textWidth = $p[2] - $p[0];
$font_size--;
// error_log($textWidth);
} while ($textWidth >= $lineWidth);
$y = ($lineWidth - $textWidth) / 2;
imagettftext($rotatedImage, $font_size, 90, $posXArray[$i], $posYArray[$i] - $y, $color, $font, $valuesArray[$i]);
}
ob_start();
imagejpeg($rotatedImage);
$actual_image = base64_encode(ob_get_contents());
ob_end_clean();
return "data:image/png;base64," . $actual_image;
}