예제 #1
0
 /**
  * 入力された画像がExifであればエラーを記録し、JFIFに変換します。
  * @param \Imagick $imagick JFIFかExif。
  */
 protected function convertExifToJFIF(\Imagick $imagick)
 {
     if ($imagick->getImageProperties('exif:*')) {
         $this->logger->error(sprintf(_('「%s」はExif形式です。'), $this->filename));
         switch ($imagick->getImageOrientation()) {
             case \Imagick::ORIENTATION_TOPRIGHT:
                 $imagick->flopImage();
                 break;
             case \Imagick::ORIENTATION_BOTTOMRIGHT:
                 $imagick->rotateImage('none', 180);
                 break;
             case \Imagick::ORIENTATION_BOTTOMLEFT:
                 $imagick->rotateImage('none', 180);
                 $imagick->flopImage();
                 break;
             case \Imagick::ORIENTATION_LEFTTOP:
                 $imagick->rotateImage('none', 90);
                 $imagick->flopImage();
                 break;
             case \Imagick::ORIENTATION_RIGHTTOP:
                 $imagick->rotateImage('none', 90);
                 break;
             case \Imagick::ORIENTATION_RIGHTBOTTOM:
                 $imagick->rotateImage('none', 270);
                 $imagick->flopImage();
                 break;
             case \Imagick::ORIENTATION_LEFTBOTTOM:
                 $imagick->rotateImage('none', 270);
                 break;
         }
         $imagick->stripImage();
     }
 }
예제 #2
0
파일: Image.php 프로젝트: nicodmf/Imagine
 /**
  * (non-PHPdoc)
  * @see Imagine\ImageInterface::flipHorizontally()
  */
 public function flipHorizontally()
 {
     try {
         $this->imagick->flopImage();
     } catch (\ImagickException $e) {
         throw new RuntimeException('Horizontal Flip operation failed', $e->getCode(), $e);
     }
     return $this;
 }
예제 #3
0
 /**
  * Mirror the current image.
  */
 public function mirror()
 {
     try {
         $this->_imagick->flopImage();
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
 }
 /**
  * Horizontal mirroring
  *
  * @return bool|PEAR_Error TRUE or a PEAR_Error object on error
  * @access public
  */
 function mirror()
 {
     try {
         $this->imagick->flopImage();
     } catch (ImagickException $e) {
         return $this->raiseError('Could not mirror the image.', IMAGE_TRANSFORM_ERROR_FAILED);
     }
     return true;
 }
예제 #5
0
파일: Resource.php 프로젝트: phpixie/image
 public function flip($flipX = false, $flipY = false)
 {
     if ($flipX) {
         $this->image->flopImage();
     }
     if ($flipY) {
         $this->image->flipImage();
     }
     return $this;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function flip($direction = Image::FLIP_HORIZONTAL)
 {
     if ($direction === Image::FLIP_VERTICAL) {
         // Flips the image in the vertical direction
         $this->image->flipImage();
     } else {
         // Flips the image in the horizontal direction
         $this->image->flopImage();
     }
 }
 /**
  * @ref http://www.b-prep.com/blog/?p=1764
  *
  * @param \Imagick $image
  * @return \Imagick
  */
 private function fixImageOrientation($image)
 {
     $orientation = $image->getImageOrientation();
     switch ($orientation) {
         case \Imagick::ORIENTATION_UNDEFINED:
             break;
         case \Imagick::ORIENTATION_TOPLEFT:
             break;
         case \Imagick::ORIENTATION_TOPRIGHT:
             $image->flopImage();
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_BOTTOMRIGHT:
             $image->rotateImage(new \ImagickPixel(), 180);
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_BOTTOMLEFT:
             $image->rotateImage(new \ImagickPixel(), 180);
             $image->flopImage();
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_LEFTTOP:
             $image->rotateImage(new \ImagickPixel(), 90);
             $image->flopImage();
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_RIGHTTOP:
             $image->rotateImage(new \ImagickPixel(), 90);
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_RIGHTBOTTOM:
             $image->rotateImage(new \ImagickPixel(), 270);
             $image->flopImage();
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
         case \Imagick::ORIENTATION_LEFTBOTTOM:
             $image->rotateImage(new \ImagickPixel(), 270);
             $image->setimageorientation(\Imagick::ORIENTATION_TOPLEFT);
             break;
     }
     return $image;
 }
예제 #8
0
 /**
  * @param $mode
  * @return $this|Adapter
  */
 public function mirror($mode)
 {
     $this->preModify();
     if ($mode == "vertical") {
         $this->resource->flipImage();
     } elseif ($mode == "horizontal") {
         $this->resource->flopImage();
     }
     $this->postModify();
     return $this;
 }
예제 #9
0
 public function process(\Imagick $image)
 {
     $info = getimagesize($this->_file);
     if ($info['mime'] != 'image/jpeg') {
         return $image;
     }
     if (!($exif_data = exif_read_data($this->_file))) {
         return $image;
     }
     if (isset($exif_data['Orientation'])) {
         $ort = $exif_data['Orientation'];
         if ($ort > 1) {
             switch ($ort) {
                 case 2:
                     $image->flopImage();
                     break;
                 case 3:
                     $image->rotateImage(new \ImagickPixel(), 180);
                     break;
                 case 4:
                     $image->flipImage();
                     break;
                 case 5:
                     $image->flopImage();
                     $image->rotateImage(new \ImagickPixel(), 270);
                     break;
                 case 6:
                     $image->rotateImage(new \ImagickPixel(), 90);
                     break;
                 case 7:
                     $image->flopImage();
                     $image->rotateImage(new \ImagickPixel(), 90);
                     break;
                 case 8:
                     $image->rotateImage(new \ImagickPixel(), 270);
                     break;
             }
         }
     }
     return $image;
 }
	/**
	 * Flips current image.
	 *
	 * @since 3.5.0
	 * @access public
	 *
	 * @param boolean $horz Flip along Horizontal Axis
	 * @param boolean $vert Flip along Vertical Axis
	 * @returns true|WP_Error
	 */
	public function flip( $horz, $vert ) {
		try {
			if ( $horz )
				$this->image->flipImage();

			if ( $vert )
				$this->image->flopImage();
		}
		catch ( Exception $e ) {
			return new WP_Error( 'image_flip_error', $e->getMessage() );
		}
		return true;
	}
예제 #11
0
 public function flip($horizontal = true)
 {
     // Flip
     try {
         if ($horizontal) {
             $return = $this->_resource->flopImage();
         } else {
             $return = $this->_resource->flipImage();
         }
     } catch (ImagickException $e) {
         throw new Engine_Image_Adapter_Exception(sprintf('Unable to flip image: %s', $e->getMessage()), $e->getCode());
     }
     return $this;
 }
예제 #12
0
 public function flip($newFile, $mode)
 {
     $imagick = new Imagick();
     $imagick->readImage($this->_file);
     switch ($mode) {
         case Tomato_Image_Abstract::FLIP_VERTICAL:
             $imagick->flipImage();
             break;
         case Tomato_Image_Abstract::FLIP_HORIZONTAL:
             $imagick->flopImage();
             break;
     }
     $imagick->writeImage($newFile);
     $imagick->clear();
     $imagick->destroy();
 }
예제 #13
0
파일: Imagick.php 프로젝트: anp135/altocms
 public function flip($flip_x = false, $flip_y = false)
 {
     if ($flip_x) {
         if ($this->multiframe()) {
             foreach ($this->image as $frame) {
                 $frame->flopImage();
             }
         } else {
             $this->image->flopImage();
         }
     }
     if ($flip_y) {
         if ($this->multiframe()) {
             foreach ($this->image as $frame) {
                 $frame->flipImage();
             }
         } else {
             $this->image->flipImage();
         }
     }
     return $this;
 }
예제 #14
0
 protected function imagick_orient_image(\Imagick $image)
 {
     $orientation = $image->getImageOrientation();
     $background = new \ImagickPixel('none');
     switch ($orientation) {
         case \imagick::ORIENTATION_TOPRIGHT:
             // 2
             $image->flopImage();
             // horizontal flop around y-axis
             break;
         case \imagick::ORIENTATION_BOTTOMRIGHT:
             // 3
             $image->rotateImage($background, 180);
             break;
         case \imagick::ORIENTATION_BOTTOMLEFT:
             // 4
             $image->flipImage();
             // vertical flip around x-axis
             break;
         case \imagick::ORIENTATION_LEFTTOP:
             // 5
             $image->flopImage();
             // horizontal flop around y-axis
             $image->rotateImage($background, 270);
             break;
         case \imagick::ORIENTATION_RIGHTTOP:
             // 6
             $image->rotateImage($background, 90);
             break;
         case \imagick::ORIENTATION_RIGHTBOTTOM:
             // 7
             $image->flipImage();
             // vertical flip around x-axis
             $image->rotateImage($background, 270);
             break;
         case \imagick::ORIENTATION_LEFTBOTTOM:
             // 8
             $image->rotateImage($background, 270);
             break;
         default:
             return false;
     }
     $image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT);
     // 1
     return true;
 }
예제 #15
0
파일: media.php 프로젝트: kimblemj/server
 public function createMediaFromJSON($glob)
 {
     $path = $glob->path;
     $filename = $glob->filename;
     $data = $glob->data;
     $resizeTo = isset($glob->resizeTo) ? $glob->resizeTo : null;
     $gameMediaDirectory = Media::getMediaDirectory($path)->data;
     $md5 = md5((string) microtime() . $filename);
     $ext = strtolower(substr($filename, -3));
     $newMediaFileName = 'aris' . $md5 . '.' . $ext;
     $resizedMediaFileName = 'aris' . $md5 . '_128.' . $ext;
     if ($ext != "jpg" && $ext != "png" && $ext != "gif" && $ext != "mp4" && $ext != "mov" && $ext != "m4v" && $ext != "3gp" && $ext != "caf" && $ext != "mp3" && $ext != "aac" && $ext != "m4a" && $ext != "zip") {
         return new returnData(1, NULL, "Invalid filetype:{$ext}");
     }
     $fullFilePath = $gameMediaDirectory . "/" . $newMediaFileName;
     if (isset($resizeTo) && ($ext == "jpg" || $ext == "png" || $ext == "gif")) {
         $bigFilePath = $gameMediaDirectory . "/big_" . $newMediaFileName;
         $fp = fopen($bigFilePath, 'w');
         if (!$fp) {
             return new returnData(1, NULL, "Couldn't open file:{$bigFilePath}");
         }
         fwrite($fp, base64_decode($data));
         fclose($fp);
         $image = new Imagick($bigFilePath);
         // Reorient based on EXIF tag
         switch ($image->getImageOrientation()) {
             case Imagick::ORIENTATION_UNDEFINED:
                 // We assume normal orientation
                 break;
             case Imagick::ORIENTATION_TOPLEFT:
                 // All good
                 break;
             case Imagick::ORIENTATION_TOPRIGHT:
                 $image->flopImage();
                 break;
             case Imagick::ORIENTATION_BOTTOMRIGHT:
                 $image->rotateImage('#000', 180);
                 break;
             case Imagick::ORIENTATION_BOTTOMLEFT:
                 $image->rotateImage('#000', 180);
                 $image->flopImage();
                 break;
             case Imagick::ORIENTATION_LEFTTOP:
                 $image->rotateImage('#000', 90);
                 $image->flopImage();
                 break;
             case Imagick::ORIENTATION_RIGHTTOP:
                 $image->rotateImage('#000', 90);
                 break;
             case Imagick::ORIENTATION_RIGHTBOTTOM:
                 $image->rotateImage('#000', -90);
                 $image->flopImage();
                 break;
             case Imagick::ORIENTATION_LEFTBOTTOM:
                 $image->rotateImage('#000', -90);
                 break;
         }
         $image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
         // Resize image proportionally so min(width, height) == $resizeTo
         if ($image->getImageWidth() < $image->getImageHeight()) {
             $image->resizeImage($resizeTo, 0, Imagick::FILTER_LANCZOS, 1);
         } else {
             $image->resizeImage(0, $resizeTo, Imagick::FILTER_LANCZOS, 1);
         }
         $image->setImageCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(40);
         $image->writeImage($fullFilePath);
         unlink($bigFilePath);
     } else {
         $fp = fopen($fullFilePath, 'w');
         if (!$fp) {
             return new returnData(1, NULL, "Couldn't open file:{$fullFilePath}");
         }
         fwrite($fp, base64_decode($data));
         fclose($fp);
     }
     if ($ext == "jpg" || $ext == "png" || $ext == "gif") {
         $img = WideImage::load($fullFilePath);
         $img = $img->resize(128, 128, 'outside');
         $img = $img->crop('center', 'center', 128, 128);
         $img->saveToFile($gameMediaDirectory . "/" . $resizedMediaFileName);
     } else {
         if ($ext == "mp4") {
             /*
               $ffmpeg = '../../libraries/ffmpeg';
               $videoFilePath      = $gameMediaDirectory."/".$newMediaFileName; 
               $tempImageFilePath  = $gameMediaDirectory."/temp_".$resizedMediaFileName; 
               $imageFilePath      = $gameMediaDirectory."/".$resizedMediaFileName; 
               $cmd = "$ffmpeg -i $videoFilePath 2>&1"; 
               $thumbTime = 1;
               if(preg_match('/Duration: ((\d+):(\d+):(\d+))/s', shell_exec($cmd), $videoLength))
               $thumbTime = (($videoLength[2] * 3600) + ($videoLength[3] * 60) + $videoLength[4])/2; 
               $cmd = "$ffmpeg -i $videoFilePath -deinterlace -an -ss $thumbTime -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $tempImageFilePath 2>&1"; 
               shell_exec($cmd);
             
               $img = WideImage::load($tempImageFilePath);
               $img = $img->resize(128, 128, 'outside');
               $img = $img->crop('center','center',128,128);
               $img->saveToFile($imageFilePath);
             */
         }
     }
     $m = Media::createMedia($path, "UploadedMedia", $newMediaFileName, 0);
     return new returnData(0, $m->data);
 }
예제 #16
0
 protected static function autoRotateImage($image_file, Imagick $imagick)
 {
     $orientation = exec(sprintf('exiftool -Orientation -n -S -t %s', escapeshellarg($image_file)));
     if (!ctype_digit($orientation)) {
         return;
     } else {
         $orientation = intval($orientation);
     }
     $rotated = true;
     switch ($orientation) {
         case Imagick::ORIENTATION_TOPRIGHT:
             // Mirror horizontal
             $imagick->flopImage();
             break;
         case Imagick::ORIENTATION_BOTTOMRIGHT:
             // Rotate 180
             $imagick->rotateImage(new ImagickPixel(), 180);
             break;
         case Imagick::ORIENTATION_BOTTOMLEFT:
             // Mirror vertical
             $imagick->flipImage();
             break;
         case Imagick::ORIENTATION_LEFTTOP:
             // Mirror horizontal and rotate 270 CW
             $imagick->transverseImage();
             break;
         case Imagick::ORIENTATION_RIGHTTOP:
             // Rotate 90 CW
             $imagick->rotateImage(new ImagickPixel(), 90);
             break;
         case Imagick::ORIENTATION_RIGHTBOTTOM:
             // Mirror horizontal and rotate 90 CW
             $imagick->transposeImage();
             break;
         case Imagick::ORIENTATION_LEFTBOTTOM:
             // Rotate 270 CW
             $imagick->rotateImage(new ImagickPixel(), 270);
             break;
         default:
             $rotated = false;
     }
     return $rotated;
 }
 /**
  * rotate image depending on exif info
  *
  * @param Imagick $image image handler
  * @return void
  */
 protected function _autorotate(\Imagick $image)
 {
     switch ($image->getImageOrientation()) {
         case \Imagick::ORIENTATION_TOPRIGHT:
             $image->flopImage();
             break;
         case \Imagick::ORIENTATION_BOTTOMRIGHT:
             $image->rotateImage('#000', 180);
             break;
         case \Imagick::ORIENTATION_BOTTOMLEFT:
             $image->flopImage();
             $image->rotateImage('#000', 180);
             break;
         case \Imagick::ORIENTATION_LEFTTOP:
             $image->flopImage();
             $image->rotateImage('#000', -90);
             break;
         case \Imagick::ORIENTATION_RIGHTTOP:
             $image->rotateImage('#000', 90);
             break;
         case \Imagick::ORIENTATION_RIGHTBOTTOM:
             $image->flopImage();
             $image->rotateImage('#000', 90);
             break;
         case \Imagick::ORIENTATION_LEFTBOTTOM:
             $image->rotateImage('#000', -90);
             break;
     }
     $image->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
 }
예제 #18
0
파일: Image.php 프로젝트: Cryde/sydney-core
 /**
  * Flip
  * @param string $val
  * @return bool
  */
 public function flip($val = 'h')
 {
     $source = $this->_getTempEditorFullPath();
     $picture = new Imagick($source[0]);
     if ($val == 'h') {
         $picture->flipImage();
     }
     if ($val == 'v') {
         $picture->flopImage();
     }
     $picture->writeImage($source[1]);
     $this->getRawEditorCache();
     return true;
 }
예제 #19
0
파일: media.php 프로젝트: kimblemj/server
 public static function createMedia($pack)
 {
     $pack->auth->permission = "read_write";
     if (!users::authenticateUser($pack->auth)) {
         return new return_package(6, NULL, "Failed Authentication");
     }
     $filenameext = strtolower(substr($pack->file_name, strrpos($pack->file_name, '.') + 1));
     if ($filenameext == "jpeg") {
         $filenameext = "jpg";
     }
     //sanity
     $filename = md5((string) microtime() . $pack->file_name);
     $newfilename = 'aris' . $filename . '.' . $filenameext;
     $resizedfilename = 'aris' . $filename . '_resized.' . $filenameext;
     $newthumbfilename = 'aris' . $filename . '_128.' . $filenameext;
     // Make sure playerUploaded requirements keep in sync with this list
     if ($filenameext != "jpg" && $filenameext != "png" && $filenameext != "gif" && $filenameext != "mp4" && $filenameext != "mov" && $filenameext != "m4v" && $filenameext != "3gp" && $filenameext != "caf" && $filenameext != "mp3" && $filenameext != "aac" && $filenameext != "m4a") {
         return new return_package(1, NULL, "Invalid filetype: '{$filenameext}'");
     }
     $filefolder = "";
     if ($pack->game_id) {
         $filefolder = $pack->game_id;
     } else {
         $filefolder = "players";
     }
     $fspath = Config::v2_gamedata_folder . "/" . $filefolder . "/" . $newfilename;
     $resizedpath = Config::v2_gamedata_folder . "/" . $filefolder . "/" . $resizedfilename;
     $fsthumbpath = Config::v2_gamedata_folder . "/" . $filefolder . "/" . $newthumbfilename;
     $fp = fopen($fspath, 'w');
     if (!$fp) {
         return new return_package(1, NULL, "Couldn't open file:{$fspath}");
     }
     fwrite($fp, base64_decode($pack->data));
     fclose($fp);
     $did_resize = false;
     if ($filenameext == "jpg" || $filenameext == "png" || $filenameext == "gif") {
         if (isset($pack->resize)) {
             $image = new Imagick($fspath);
             // Reorient based on EXIF tag
             switch ($image->getImageOrientation()) {
                 case Imagick::ORIENTATION_UNDEFINED:
                     // We assume normal orientation
                     break;
                 case Imagick::ORIENTATION_TOPLEFT:
                     // All good
                     break;
                 case Imagick::ORIENTATION_TOPRIGHT:
                     $image->flopImage();
                     break;
                 case Imagick::ORIENTATION_BOTTOMRIGHT:
                     $image->rotateImage('#000', 180);
                     break;
                 case Imagick::ORIENTATION_BOTTOMLEFT:
                     $image->rotateImage('#000', 180);
                     $image->flopImage();
                     break;
                 case Imagick::ORIENTATION_LEFTTOP:
                     $image->rotateImage('#000', 90);
                     $image->flopImage();
                     break;
                 case Imagick::ORIENTATION_RIGHTTOP:
                     $image->rotateImage('#000', 90);
                     break;
                 case Imagick::ORIENTATION_RIGHTBOTTOM:
                     $image->rotateImage('#000', -90);
                     $image->flopImage();
                     break;
                 case Imagick::ORIENTATION_LEFTBOTTOM:
                     $image->rotateImage('#000', -90);
                     break;
             }
             $image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
             // Resize image proportionally so min(width, height) == $pack->resize
             $w = $image->getImageWidth();
             $h = $image->getImageHeight();
             if ($w < $h) {
                 $image->resizeImage($pack->resize, $pack->resize / $w * $h, Imagick::FILTER_LANCZOS, 1);
             } else {
                 $image->resizeImage($pack->resize / $h * $w, $pack->resize, Imagick::FILTER_LANCZOS, 1);
             }
             $image->setImageCompression(Imagick::COMPRESSION_JPEG);
             $image->setImageCompressionQuality(40);
             $image->writeImage($resizedpath);
             $did_resize = true;
         }
         $image = new Imagick(isset($pack->resize) ? $resizedpath : $fspath);
         //aspect fill to 128x128
         $w = $image->getImageWidth();
         $h = $image->getImageHeight();
         if ($w < $h) {
             $image->thumbnailImage(128, 128 / $w * $h, 1, 1);
         } else {
             $image->thumbnailImage(128 / $h * $w, 128, 1, 1);
         }
         //crop around center
         $w = $image->getImageWidth();
         $h = $image->getImageHeight();
         $image->cropImage(128, 128, ($w - 128) / 2, ($h - 128) / 2);
         $image->writeImage($fsthumbpath);
     }
     if ($did_resize) {
         unlink($fspath);
     }
     // after making the 128 thumbnail
     $pack->media_id = dbconnection::queryInsert("INSERT INTO media (" . "file_folder," . "file_name," . (isset($pack->game_id) ? "game_id," : "") . (isset($pack->auth->user_id) ? "user_id," : "") . (isset($pack->name) ? "name," : "") . "created" . ") VALUES (" . "'" . $filefolder . "'," . "'" . ($did_resize ? $resizedfilename : $newfilename) . "'," . (isset($pack->game_id) ? "'" . addslashes($pack->game_id) . "'," : "") . (isset($pack->auth->user_id) ? "'" . addslashes($pack->auth->user_id) . "'," : "") . (isset($pack->name) ? "'" . addslashes($pack->name) . "'," : "") . "CURRENT_TIMESTAMP" . ")");
     games::bumpGameVersion($pack);
     return media::getMedia($pack);
 }
예제 #20
0
 /**
  * Auto-correction of image orientation based on exif data
  *
  * @param array $data
  */
 protected function OrientationCorrection($data)
 {
     // catch for those who don't have exif module loaded
     if (!is_callable('exif_read_data')) {
         return;
     }
     $exif = exif_read_data($data['tmp_name']);
     $orientation = isset($exif['Orientation']) ? $exif['Orientation'] : 0;
     if ($orientation != 0 || $orientation != 1) {
         $imageLib = elgg_get_plugin_setting('image_lib', 'tidypics');
         if ($imageLib == 'ImageMagick') {
             // ImageMagick command line
             $im_path = elgg_get_plugin_setting('im_path', 'tidypics');
             if (!$im_path) {
                 $im_path = "/usr/bin/";
             }
             if (substr($im_path, strlen($im_path) - 1, 1) != "/") {
                 $im_path .= "/";
             }
             $filename = $data['tmp_name'];
             $command = $im_path . "mogrify -auto-orient {$filename}";
             $output = array();
             $ret = 0;
             exec($command, $output, $ret);
         } else {
             if ($imageLib == 'ImageMagickPHP') {
                 // imagick php extension
                 $rotate = false;
                 $flop = false;
                 $angle = 0;
                 switch ($orientation) {
                     case 2:
                         $rotate = false;
                         $flop = true;
                         break;
                     case 3:
                         $rotate = true;
                         $flop = false;
                         $angle = 180;
                         break;
                     case 4:
                         $rotate = true;
                         $flop = true;
                         $angle = 180;
                         break;
                     case 5:
                         $rotate = true;
                         $flop = true;
                         $angle = 90;
                         break;
                     case 6:
                         $rotate = true;
                         $flop = false;
                         $angle = 90;
                         break;
                     case 7:
                         $rotate = true;
                         $flop = true;
                         $angle = -90;
                         break;
                     case 8:
                         $rotate = true;
                         $flop = false;
                         $angle = -90;
                         break;
                     default:
                         $rotate = false;
                         $flop = false;
                         break;
                 }
                 $imagick = new Imagick();
                 $imagick->readImage($data['tmp_name']);
                 if ($rotate) {
                     $imagick->rotateImage('#000000', $angle);
                 }
                 if ($flop) {
                     $imagick->flopImage();
                 }
                 $imagick->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
                 $imagick->writeImage($data['tmp_name']);
                 $imagick->clear();
                 $imagick->destroy();
             } else {
                 // make sure the in memory image size does not exceed memory available
                 $imginfo = getimagesize($data['tmp_name']);
                 $requiredMemory1 = ceil($imginfo[0] * $imginfo[1] * 5.35);
                 $requiredMemory2 = ceil($imginfo[0] * $imginfo[1] * ($imginfo['bits'] / 8) * $imginfo['channels'] * 2.5);
                 $requiredMemory = (int) max($requiredMemory1, $requiredMemory2);
                 $mem_avail = elgg_get_ini_setting_in_bytes('memory_limit');
                 $mem_used = memory_get_usage();
                 $mem_avail = $mem_avail - $mem_used - 2097152;
                 // 2 MB buffer
                 if ($requiredMemory < $mem_avail) {
                     $image = imagecreatefromstring(file_get_contents($data['tmp_name']));
                     $rotate = false;
                     $flip = false;
                     $angle = 0;
                     switch ($orientation) {
                         case 2:
                             $rotate = false;
                             $flip = true;
                             break;
                         case 3:
                             $rotate = true;
                             $flip = false;
                             $angle = 180;
                             break;
                         case 4:
                             $rotate = true;
                             $flip = true;
                             $angle = 180;
                             break;
                         case 5:
                             $rotate = true;
                             $flip = true;
                             $angle = -90;
                             break;
                         case 6:
                             $rotate = true;
                             $flip = false;
                             $angle = -90;
                             break;
                         case 7:
                             $rotate = true;
                             $flip = true;
                             $angle = 90;
                             break;
                         case 8:
                             $rotate = true;
                             $flip = false;
                             $angle = 90;
                             break;
                         default:
                             $rotate = false;
                             $flip = false;
                             break;
                     }
                     if ($rotate) {
                         $image = imagerotate($image, $angle, 0);
                         imagejpeg($image, $data['tmp_name']);
                     }
                     if ($flip) {
                         $mem_avail = elgg_get_ini_setting_in_bytes('memory_limit');
                         $mem_used = memory_get_usage();
                         $mem_avail = $mem_avail - $mem_used - 2097152;
                         // 2 MB buffer
                         if ($requiredMemory < $mem_avail) {
                             $width = imagesx($image);
                             $height = imagesy($image);
                             $src_x = 0;
                             $src_y = 0;
                             $src_width = $width;
                             $src_height = $height;
                             $src_x = $width - 1;
                             $src_width = -$width;
                             $imgdest = imagecreatetruecolor($width, $height);
                             imagecopyresampled($imgdest, $image, 0, 0, $src_x, $src_y, $width, $height, $src_width, $src_height);
                             imagejpeg($imgdest, $data['tmp_name']);
                             imagedestroy($imgdest);
                         }
                     }
                     imagedestroy($image);
                 }
             }
         }
     }
 }
예제 #21
0
파일: Imagick.php 프로젝트: OuHaixiong/img
 /**
  * 水平翻转(左右翻转)或垂直翻转(上下翻转)
  * @param Imagick $im
  * @param string $hv
  * @return boolean
  */
 private function _rotate(&$im, $hv)
 {
     if (self::ROTATE_H == $hv) {
         // 水平翻转
         $boolean = $im->flopImage();
     } elseif (self::ROTATE_V == $hv) {
         // 垂直翻转
         $boolean = $im->flipImage();
     } else {
         $this->_error = '参数错误';
         $this->_im = null;
         return false;
     }
     if ($boolean) {
         return true;
     } else {
         $this->_error = '翻转失败';
         $this->_im = null;
         return false;
     }
 }
예제 #22
0
 /**
  * 水平翻转
  *
  * @return bool
  * @author Sauwe
  */
 public function flipH()
 {
     if ($this->notValid()) {
         return false;
     }
     try {
         $im = new Imagick();
         $im->readImageBlob($this->_img_data);
         if ($im->flopImage()) {
             $this->_img_data = $im->getImageBlob();
             return true;
         }
         return false;
     } catch (Exception $e) {
         $this->_errno = SAE_ErrUnknown;
         $this->_errmsg = $e->getMessage();
         return false;
     }
 }
예제 #23
0
 /**
  * Applies a horizontal mirror on the image
  *
  * @return Imagick
  */
 public function flop()
 {
     $this->image->flopImage();
     $this->operations[] = 'flip';
     return $this;
 }
예제 #24
0
파일: image.php 프로젝트: rmd6502/PicClient
if (array_key_exists("img", $_REQUEST)) {
    $image = $_REQUEST['img'];
    try {
        $img = new Imagick($image);
        if ($img->valid()) {
            if ($img->getImageWidth() > $img->getImageHeight()) {
                $img->rotateImage(new ImagickPixel('none'), 90);
            }
            $img->thumbnailImage(0, 160);
            if ($img->getImageWidth() > 128) {
                $img->thumbnailImage(128, 0);
            }
            $img->setImageFormat('bmp');
            $img->setCompression(imagick::COMPRESSION_NO);
            $img->setImageDepth(24);
            $img->setImageMatte(false);
            $img->flopImage();
            //$img->setImageAlphaChannel(imagick::ALPHACHANNEL_DEACTIVATE);
            $imgData = (string) $img;
            header("Content-Type: image/bmp");
            header("Content-Length: " . strlen($imgData));
            echo $img;
        } else {
            throw new Exception("image not valid");
        }
    } catch (Exception $e) {
        //http_response_code(403);
        echo $e;
    }
}