예제 #1
1
 private function getImage()
 {
     $image = imagecreatefromstring(file_get_contents($this->file['tmp_name']));
     if ($this->currentExtension == 'jpg' || $this->currentExtension == 'jpeg') {
         $exif = exif_read_data($this->file['tmp_name']);
         if (!empty($exif['Orientation'])) {
             switch ($exif['Orientation']) {
                 case 8:
                     $image = imagerotate($image, 90, 0);
                     break;
                 case 3:
                     $image = imagerotate($image, 180, 0);
                     break;
                 case 6:
                     $image = imagerotate($image, -90, 0);
                     break;
             }
         }
     }
     // Get new sizes
     $width = imagesx($image);
     $height = imagesy($image);
     //list($width, $height) = getimagesize($this->file['tmp_name']);
     list($newWidth, $newHeight) = $this->getScaledDimArray($image, 800);
     // Load
     $resizeImage = imagecreatetruecolor($newWidth, $newHeight);
     // Resize
     imagecopyresized($resizeImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
     return $resizeImage;
 }
예제 #2
1
 /**
  * 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());
 }
예제 #3
1
 public function rotate($path, $degrees)
 {
     header('Content-type: image/png');
     $source = imagecreatefrompng($path);
     $rotate = imagerotate($source, $degrees, 0);
     imagepng($rotate, $path);
 }
예제 #4
1
 /**
  * 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;
 }
예제 #5
0
 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;
 }
 /**
  * (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);
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
/**
 * 修改一个图片 让其翻转指定度数
 * 
 * @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;
}
예제 #9
0
 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);
         }
     }
 }
예제 #10
0
 public function rotate($angle)
 {
     $this->_imageHandler = imagerotate($this->_imageHandler, $angle, -1);
     imagealphablending($this->_imageHandler, true);
     imagesavealpha($this->_imageHandler, true);
     $this->refreshImageDimensions();
 }
예제 #11
0
 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);
 }
예제 #12
0
파일: Captcha.php 프로젝트: rszabo/egalite
 /**
  * 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);
 }
예제 #13
0
 function imgrotate($dir, $sens)
 {
     $src = imagecreatefromjpeg($dir);
     // Rotation
     $rotate = imagerotate($src, $sens, 0);
     return imagejpeg($rotateFull, $dir, 100);
 }
예제 #14
0
 /**
  * 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));
 }
예제 #15
0
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;
}
예제 #16
0
 function fixImageOrientation($path)
 {
     $info = getimagesize($path);
     if ($info['mime'] != "image/jpeg") {
         return;
     }
     $exif = exif_read_data($path);
     if (exif_imagetype($path) != IMAGETYPE_JPEG) {
         return;
     }
     if (empty($exif['Orientation'])) {
         return;
     }
     $image = imagecreatefromjpeg($path);
     switch ($exif['Orientation']) {
         case 3:
             $image = imagerotate($image, 180, 0);
             break;
         case 6:
             $image = imagerotate($image, -90, 0);
             break;
         case 8:
             $image = imagerotate($image, 90, 0);
             break;
     }
     imagejpeg($image, $path);
 }
예제 #17
0
 private function createOrientedImage($exif)
 {
     $image = imagecreatefromstring($this->FileBin->bin);
     switch ($exif) {
         // rotate 180 degrees
         case 3:
             $image = imagerotate($image, 180, 0);
             break;
             // rotate 90 degrees
         // rotate 90 degrees
         case 6:
             $imagewidth = imagesy($image);
             $imageheight = imagesx($image);
             $image = imagerotate($image, -90, 0);
             imagecopyresampled($image, $image, 0, 0, (imagesx($image) - $imagewidth) / 2, (imagesy($image) - $imageheight) / 2, $imagewidth, $imageheight, $imagewidth, $imageheight);
             break;
             // rotate 270 degrees
         // rotate 270 degrees
         case 8:
             $imagewidth = imagesy($image);
             $imageheight = imagesx($image);
             $image = imagerotate($image, 90, 0);
             imagecopyresampled($image, $image, 0, 0, (imagesx($image) - $imagewidth) / 2, (imagesy($image) - $imageheight) / 2, $imagewidth, $imageheight, $imagewidth, $imageheight);
             break;
         default:
             break;
     }
     ob_start();
     imagejpeg($image);
     $ei = ob_get_contents();
     ob_end_clean();
     return $ei;
 }
예제 #18
0
 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);
     }
 }
예제 #19
0
 public function run($file)
 {
     $progressive = isset($this->settings['field_settings']['progressive_jpeg']) === TRUE && $this->settings['field_settings']['progressive_jpeg'] == 'yes' ? TRUE : FALSE;
     $this->size = getimagesize($file);
     $width = $this->size[0];
     $height = $this->size[1];
     if (isset($this->settings['only_if']) === TRUE) {
         // Do we need to rotate?
         if ($this->settings['only_if'] == 'width_bigger' && $width < $height) {
             return TRUE;
         } elseif ($this->settings['only_if'] == 'height_bigger' && $height < $width) {
             return TRUE;
         }
     }
     switch ($this->size[2]) {
         case 1:
             if (imagetypes() & IMG_GIF) {
                 $this->im = imagecreatefromgif($file);
             } else {
                 return 'No GIF Support!';
             }
             break;
         case 2:
             if (imagetypes() & IMG_JPG) {
                 $this->im = imagecreatefromjpeg($file);
             } else {
                 return 'No JPG Support!';
             }
             break;
         case 3:
             if (imagetypes() & IMG_PNG) {
                 $this->im = imagecreatefrompng($file);
             } else {
                 return 'No PNG Support!';
             }
             break;
         default:
             return 'File Type??';
     }
     $this->settings['background_color'];
     $this->settings['degrees'];
     $this->im = imagerotate($this->im, 360 - $this->settings['degrees'], hexdec($this->settings['background_color']));
     switch ($this->size[2]) {
         case 1:
             imagegif($this->im, $file);
             break;
         case 2:
             if ($progressive === TRUE) {
                 @imageinterlace($this->im, 1);
             }
             imagejpeg($this->im, $file, 100);
             break;
         case 3:
             imagepng($this->im, $file);
             break;
     }
     imagedestroy($this->im);
     return TRUE;
 }
예제 #20
0
파일: photo_gd.php 프로젝트: Mauru/red
 public function rotate($degrees)
 {
     if (!$this->is_valid()) {
         return FALSE;
     }
     $this->image = imagerotate($this->image, $degrees, 0);
     $this->setDimensions();
 }
예제 #21
0
/**
 * Make a thumbnail of a newly uploaded file if it is an image
 *
 * @param $src the source of the file
 * @param $dest where to save the thumbnail
 * @param $fileExt the file extension (to check if the file is an image)
 * @param $desired_width the desired width of the thumbnail, height and width are kept in ratio
 */
function make_thumb($src, $dest, $fileExt, $desired_width)
{
    $exif = exif_read_data($src, 'IFD0');
    // Read the source image
    if ($fileExt == 'gif') {
        $source_image = imagecreatefromgif($src);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        $source_image = imagecreatefromjpeg($src);
    } elseif ($fileExt == 'png') {
        $source_image = imagecreatefrompng($src);
    } elseif ($fileExt == 'wbmp') {
        $source_image = imagecreatefromwbmp($src);
    } else {
        // Return if not an image
        return;
    }
    // Fix Orientation of original image - this has to be done because of stupid apple products who can't save their
    // orientation like everybody else, ugh!
    switch ($exif['Orientation']) {
        case 3:
            $source_image = imagerotate($source_image, 180, 0);
            break;
        case 6:
            $source_image = imagerotate($source_image, -90, 0);
            break;
        case 8:
            $source_image = imagerotate($source_image, 90, 0);
            break;
    }
    // Save turned source image again (overwrites false orientation)
    if ($fileExt == 'gif') {
        imagegif($source_image, $src);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        imagejpeg($source_image, $src);
    } elseif ($fileExt == 'png') {
        imagepng($source_image, $src);
    } elseif ($fileExt == 'bmp') {
        imagewbmp($source_image, $src);
    }
    $width = imagesx($source_image);
    $height = imagesy($source_image);
    // Find the "desired height" of this thumbnail, relative to the desired width
    $desired_height = floor($height * ($desired_width / $width));
    // Create a new, "virtual" image
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);
    // Copy source image at a resized size
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
    // Create the physical thumbnail image to its destination
    if ($fileExt == 'gif') {
        imagegif($virtual_image, $dest);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        imagejpeg($virtual_image, $dest);
    } elseif ($fileExt == 'png') {
        imagepng($virtual_image, $dest);
    } elseif ($fileExt == 'bmp') {
        imagewbmp($virtual_image, $dest);
    }
}
예제 #22
0
 public function generate()
 {
     if (!function_exists('imagerotate')) {
         function imagerotate(&$srcImg, $angle, $bgcolor, $ignore_transparent = 0)
         {
             function rotateX($x, $y, $theta)
             {
                 return $x * cos($theta) - $y * sin($theta);
             }
             function rotateY($x, $y, $theta)
             {
                 return $x * sin($theta) + $y * cos($theta);
             }
             $srcw = imagesx($srcImg);
             $srch = imagesy($srcImg);
             if ($angle == 0) {
                 return $srcImg;
             }
             // Convert the angle to radians
             $theta = deg2rad($angle);
             // Calculate the width of the destination image.
             $temp = array(rotateX(0, 0, 0 - $theta), rotateX($srcw, 0, 0 - $theta), rotateX(0, $srch, 0 - $theta), rotateX($srcw, $srch, 0 - $theta));
             $minX = floor(min($temp));
             $maxX = ceil(max($temp));
             $width = $maxX - $minX;
             // Calculate the height of the destination image.
             $temp = array(rotateY(0, 0, 0 - $theta), rotateY($srcw, 0, 0 - $theta), rotateY(0, $srch, 0 - $theta), rotateY($srcw, $srch, 0 - $theta));
             $minY = floor(min($temp));
             $maxY = ceil(max($temp));
             $height = $maxY - $minY;
             $destimg = imagecreatetruecolor($width, $height);
             imagefill($destimg, 0, 0, imagecolorallocate($destimg, 0, 255, 0));
             // sets all pixels in the new image
             for ($x = $minX; $x < $maxX; $x++) {
                 for ($y = $minY; $y < $maxY; $y++) {
                     // fetch corresponding pixel from the source image
                     $srcX = round(rotateX($x, $y, $theta));
                     $srcY = round(rotateY($x, $y, $theta));
                     if ($srcX >= 0 && $srcX < $srcw && $srcY >= 0 && $srcY < $srch) {
                         $color = imagecolorat($srcImg, $srcX, $srcY);
                     } else {
                         $color = $bgcolor;
                     }
                     imagesetpixel($destimg, $x - $minX, $y - $minY, $color);
                 }
             }
             return $destimg;
         }
     }
     if ($this->_angle > 0) {
         $bg = imagecolorallocatealpha($this->_owner->image, 255, 255, 255, 127);
         $rotate = imagerotate($this->_owner->image, $this->_angle, $bg);
         imagecolortransparent($rotate, $bg);
         imagesavealpha($rotate, true);
         $this->_owner->image = $rotate;
     }
     return true;
 }
예제 #23
0
 /**
  * Convert resource $imges with rules from $info
  * 
  * @param resource $image
  * @param array $info
  * @param array $MergedImage
  * @return resource
  */
 public function transformImage($image, &$info, $MergedImage = null)
 {
     $h = imagesy($image);
     $w = imagesx($image);
     //$imageTransform = $image;
     if ($h != round($info['height']) || $w != round($info['width'])) {
         $imageTransform = imagecreatetruecolor($info['width'], $info['height']);
         imageAlphaBlending($imageTransform, false);
         imagesavealpha($imageTransform, true);
         imagecopyresampled($imageTransform, $image, 0, 0, 0, 0, round($info['width']), round($info['height']), $w, $h);
         $image = $imageTransform;
     }
     //$info['rotation'] = 90;
     if (!empty($info['rotation'])) {
         #$col = imagecolorexactalpha ($image, 57, 57, 57, 127);
         $col = imagecolorexactalpha($image, 255, 255, 255, 127);
         $imageTransform = imagerotate($image, -$info['rotation'], $col);
         $ims = imagecreatetruecolor(imagesx($imageTransform), imagesy($imageTransform));
         imagecolortransparent($ims, $col);
         imagefill($ims, 0, 0, $col);
         imagecopy($ims, $imageTransform, 0, 0, 0, 0, imagesx($imageTransform), imagesy($imageTransform));
         $info['x'] -= (imagesx($ims) - imagesx($image)) / 2;
         $info['y'] -= (imagesy($ims) - imagesy($image)) / 2;
         $image = $ims;
         //imagepng($image);die();
     }
     $info['width'] = imagesx($image);
     $info['height'] = imagesy($image);
     if (!empty($MergedImage)) {
         $new_image = array();
         if ($info['x'] > 0) {
             $info['x'] = $info['x'] + $MergedImage['areaOffsetX'];
             $info['beginX'] = 0;
         } else {
             $info['beginX'] = -$info['x'];
             $info['width'] = $info['width'] + $info['x'];
             $info['x'] = $MergedImage['areaOffsetX'];
         }
         if ($info['y'] > 0) {
             $info['y'] = $info['y'] + $MergedImage['areaOffsetY'];
             $info['beginY'] = 0;
         } else {
             $info['beginY'] = -$info['y'];
             $info['height'] = $info['height'] + $info['y'];
             $info['y'] = $MergedImage['areaOffsetY'];
         }
         if ($info['x'] + $info['width'] > $MergedImage['areaSizeX'] + $MergedImage['areaOffsetX']) {
             $info['width'] = $MergedImage['areaSizeX'] + $MergedImage['areaOffsetX'] - $info['x'];
         }
         if ($info['y'] + $info['height'] > $MergedImage['areaSizeY'] + $MergedImage['areaOffsetY']) {
             $info['height'] = $MergedImage['areaSizeY'] + $MergedImage['areaOffsetY'] - $info['y'];
         }
     }
     // die();
     //imagepng($imageTransform);die();
     return $image;
 }
예제 #24
0
		public function Rotate($angle){
			//always make the uncovered color transparent
			$rgba = Color::HexToRGBA("#FFFFFF", 0);
			$color = $this->AllocateColor($rgba[0]['r'], $rgba[0]['g'], $rgba[0]['b'], $rgba[0]['alpha']);
			
			$img = new Image();
			$img->handle = imagerotate($this->handle, $angle, $color);
			return $img;
		}
 /**
  * Rotates image counter clockwise
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $angle = $this->argument(0)->type('numeric')->required()->value();
     $color = $this->argument(1)->value();
     $color = new Color($color);
     // rotate image
     $image->setCore(imagerotate($image->getCore(), $angle, $color->getInt()));
     return true;
 }
예제 #26
0
파일: GD.php 프로젝트: piratevn/cms-gio
 public function rotate($newFile, $angle)
 {
     $newFile = null == $newFile ? $this->_file : $newFile;
     $source = $this->_createSourceFile($this->_file);
     $rotate = @imagerotate($source, 360 - $angle, -1);
     $this->_createDesFile($rotate, $newFile);
     @imagedestroy($source);
     @imagedestroy($rotate);
 }
 function process_form()
 {
     $angle = required_param('angle', PARAM_INT);
     $info = lightboxgallery_image_info($this->imagepath);
     if ($im = lightboxgallery_imagecreatefromtype($info->imagesize[2], $this->imagepath)) {
         $rotated = imagerotate($im, $angle, 0);
         $this->save_image_resource($rotated, $info->imagesize[2]);
     }
 }
예제 #28
-1
파일: gd.php 프로젝트: syjzwjj/quyeba
 function output()
 {
     $arr = $this->ret;
     $bg = DATA_DIR . '/cache/vcodebg.png';
     $image = imagecreatefrompng($bg);
     list($w, $baseH) = getimagesize($bg);
     header('Content-type: image/png');
     $x = 1;
     foreach ($arr as $i => $filename) {
         list($w, $h) = getimagesize($filename);
         $source = imagecreatefrompng($filename);
         $t_id = imagecolortransparent($source);
         $rotate = imagerotate($source, rand(-20, 20), $t_id);
         $w2 = $w * $baseH / $h;
         imagecopyresized($image, $rotate, $x, 0, 0, 0, $w2, $baseH, $w, $h);
         imagedestroy($source);
         imagedestroy($rotate);
         $x += $w2;
     }
     $x += 1;
     $dst = imagecreatetruecolor($x, $baseH);
     imagecopyresampled($dst, $image, 0, 0, 0, 0, $x, $baseH, $x, $baseH);
     imagepng($dst);
     imagedestroy($image);
     imagedestroy($dst);
     exit;
 }
예제 #29
-1
/** 
 * 旋转图片
 *
 * @param $imagName string 原图地址
 * @param $degrees string 旋转角度
 * @param $aimFileName string 目标图地址(存在则新建一张目标图,否则旋转原图)
 * 
 * return bool
 */
function rotateImage($imagName, $degrees = 90, $aimFileName = '')
{
    // 图片信息
    list($imagName_w, $imagName_h, $imagName_type) = getimagesize($imagName);
    //创建图像资源
    switch ($imagName_type) {
        case 1:
            $source = imagecreatefromgif($imagName);
            break;
        case 2:
            $source = imagecreatefromjpeg($imagName);
            break;
        case 3:
            $source = imagecreatefrompng($imagName);
            break;
        default:
            return array('status' => '-1', 'msg' => '图片格式不符合!');
            break;
    }
    //使用imagerotate()函数按指定的角度旋转
    $rotate = imagerotate($source, $degrees, 0);
    //旋转后的图片保存
    $aimFileName = $aimFileName ? $aimFileName : $imagName;
    // 保存
    if ($imagName_type == 1) {
        $result = imagegif($rotate, $aimFileName);
    } elseif ($imagName_type == 2) {
        $result = imagejpeg($rotate, $aimFileName);
    } elseif ($imagName_type == 3) {
        $result = imagepng($rotate, $aimFileName);
    }
    //释放资源
    imagedestroy($source);
    return array('status' => $result, 'msg' => $aimFileName);
}
예제 #30
-2
 function load($filename, $orientation = 0)
 {
     $image_info = getimagesize($filename);
     $this->image_type = $image_info[2];
     if ($this->image_type == IMAGETYPE_JPEG) {
         $this->image = imagecreatefromjpeg($filename);
     } elseif ($this->image_type == IMAGETYPE_GIF) {
         $this->image = imagecreatefromgif($filename);
     } elseif ($this->image_type == IMAGETYPE_PNG) {
         $this->image = imagecreatefrompng($filename);
     }
     if ($orientation != 0) {
         switch ($orientation) {
             case 8:
                 $this->image = imagerotate($this->image, 90, 0);
                 break;
             case 3:
                 $this->image = imagerotate($this->image, 180, 0);
                 break;
             case 6:
                 //echo "hiii"; die;
                 $this->image = imagerotate($this->image, -90, 0);
                 break;
         }
     }
 }