コード例 #1
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());
 }
コード例 #2
0
 /**
  * Substitute for GD imagerotate
  *
  * @param image $imgSrc
  * @param int $angle
  * @param int $bgd_colour
  * @return image
  */
 function imagerotate($imgSrc, $angle, $bgd_colour)
 {
     // ensuring we got really RightAngle (if not we choose the closest one)
     $angle = min((int) (($angle + 45) / 90) * 90, 270);
     // no need to fight
     if ($angle == 0) {
         return $imgSrc;
     }
     // dimenstion of source image
     $srcX = imagesx($imgSrc);
     $srcY = imagesy($imgSrc);
     switch ($angle) {
         case 90:
             $imgDest = imagecreatetruecolor($srcY, $srcX);
             for ($x = 0; $x < $srcX; $x++) {
                 for ($y = 0; $y < $srcY; $y++) {
                     imagecopy($imgDest, $imgSrc, $srcY - $y - 1, $x, $x, $y, 1, 1);
                 }
             }
             break;
         case 180:
             $imgDest = imageflip($imgSrc, IMAGE_FLIP_BOTH);
             break;
         case 270:
             $imgDest = imagecreatetruecolor($srcY, $srcX);
             for ($x = 0; $x < $srcX; $x++) {
                 for ($y = 0; $y < $srcY; $y++) {
                     imagecopy($imgDest, $imgSrc, $y, $srcX - $x - 1, $x, $y, 1, 1);
                 }
             }
             break;
     }
     return $imgDest;
 }
コード例 #3
0
 public static function Mirror($image, $outtype = "png", $raw = false, $vertical = false)
 {
     if (!$raw) {
         list($size["x"], $size["y"]) = getimagesize($image);
     } else {
         list($size["x"], $size["y"]) = getimagesizefromstring($image);
     }
     $data = RandImg::loadImage($image, $raw);
     imageflip($data, $vertical ? IMG_FLIP_VERTICAL : IMG_FLIP_HORIZONTAL);
     return RandImg::makeImageString($data, $outtype);
 }
コード例 #4
0
ファイル: TileBase.php プロジェクト: ranvis/identicon
 protected function applyRotation($image, $rotation)
 {
     if ($rotation & self::PATTERN_FLIP_H) {
         imageflip($image, IMG_FLIP_HORIZONTAL);
     }
     if ($rotation & self::PATTERN_FLIP_V) {
         imageflip($image, IMG_FLIP_VERTICAL);
     }
     if ($rotation & self::PATTERN_ANGLE_MASK) {
         $image = imagerotate($image, ($rotation & self::PATTERN_ANGLE_MASK) * 90, $this->bgColorValue);
     }
     return $image;
 }
コード例 #5
0
ファイル: Render.php プロジェクト: nickdodd25/mcavatars
 public function renderBody($skin, $size, $hat = false)
 {
     $bodyWidth = (int) floor($size / 2);
     $bodyHeight = (int) floor($bodyWidth * 1.5);
     $armWidth = (int) floor($size / 4);
     $width = (int) $bodyWidth * 2;
     $height = (int) $width * 2;
     $skin = base64_decode($skin);
     $imgBody = imagecreatetruecolor($width, $height);
     $imgSkin = imagecreatefromstring($skin);
     $transparency = imagecolorat($imgSkin, 0, 0);
     $alphaRed = $transparency >> 16 & 0xff;
     $alphaGreen = $transparency >> 8 & 0xff;
     $alphaBlue = $transparency & 0xff;
     // Make body transparent
     imagesavealpha($imgBody, true);
     $transparent = imagecolorallocatealpha($imgBody, 0, 0, 0, 127);
     imagefill($imgBody, 0, 0, $transparent);
     // Head (and hat, of course)
     imagecopyresized($imgBody, $imgSkin, $armWidth, 0, 8, 8, $bodyWidth, $bodyWidth, 8, 8);
     if ($hat) {
         $imgHat = imagecreatetruecolor($bodyWidth, $bodyWidth);
         imagecolortransparent($imgHat, $transparency);
         imagecopy($imgBody, $imgHat, 0, 0, $armWidth, 0, $bodyWidth, $bodyWidth);
         imagecopyresized($imgHat, $imgSkin, $armWidth, 0, 40, 8, $bodyWidth, $bodyWidth, 8, 8);
         /*$rgb = imagecolorallocatealpha( $imgHat, 0, 0, 0, 127 );
         		imagefill( $imgHat, 0, 0, $rgb );*/
     }
     // Body
     imagecopyresized($imgBody, $imgSkin, $armWidth, $bodyWidth, 20, 20, $bodyWidth, $bodyHeight, 8, 12);
     // Arms
     imagecopyresized($imgBody, $imgSkin, $armWidth + $bodyWidth, $bodyWidth, 44, 20, $armWidth, $bodyHeight, 4, 12);
     imagecopyresized($imgBody, $imgSkin, 0, $bodyWidth, 44, 20, $armWidth, $bodyHeight, 4, 12);
     // Legs
     /**
      * X: 4
      * Y: 20
      */
     imagecopyresized($imgBody, $imgSkin, $armWidth, $bodyWidth + $bodyHeight, 4, 20, $armWidth, $bodyHeight, 4, 12);
     $imgLeftLeg = imagecreatetruecolor($armWidth, $bodyHeight);
     imagecopyresized($imgLeftLeg, $imgSkin, 0, 0, 4, 20, $armWidth, $bodyHeight, 4, 12);
     imageflip($imgLeftLeg, IMG_FLIP_HORIZONTAL);
     imagecopy($imgBody, $imgLeftLeg, $bodyWidth, $bodyWidth + $bodyHeight, 0, 0, $armWidth, $bodyHeight);
     imagedestroy($imgLeftLeg);
     header('Content-type: image/png');
     imagepng($imgBody);
     imagedestroy($imgSkin);
     imagedestroy($imgBody);
 }
コード例 #6
0
ファイル: GD.php プロジェクト: clee03/metal
 /**
  *  @inheritdoc
  */
 public function flip($flipVertical, $flipHorizontal)
 {
     if (!$flipVertical && !$flipHorizontal) {
         return $this;
     }
     if (function_exists('imageflip')) {
         if ($flipVertical && $flipHorizontal) {
             $flipMode = \IMG_FLIP_BOTH;
         } else {
             if ($flipVertical && !$flipHorizontal) {
                 $flipMode = \IMG_FLIP_VERTICAL;
             } else {
                 if (!$flipVertical && $flipHorizontal) {
                     $flipMode = \IMG_FLIP_HORIZONTAL;
                 }
             }
         }
         imageflip($this->resource, $flipMode);
     } else {
         $width = $this->width();
         $height = $this->height();
         $src_x = 0;
         $src_y = 0;
         $src_width = $width;
         $src_height = $height;
         if ($flipVertical) {
             $src_y = $height - 1;
             $src_height = -$height;
         }
         if ($flipHorizontal) {
             $src_x = $width - 1;
             $src_width = -$width;
         }
         $imgdest = imagecreatetruecolor($width, $height);
         imagealphablending($imgdest, false);
         imagesavealpha($imgdest, true);
         if (imagecopyresampled($imgdest, $this->resource, 0, 0, $src_x, $src_y, $width, $height, $src_width, $src_height)) {
             imagedestroy($this->resource);
             $this->resource = $imgdest;
         }
     }
     return $this;
 }
コード例 #7
0
ファイル: Vimage.php プロジェクト: rundiz/fuel-start
 /**
  * rotate image
  * @param integer|string $degree degree of rotation. (0, 90, 180, 270). for php < 5.5, you cannot use flip hor, vrt, horvrt
  * @return boolean
  */
 public function rotate($degree = '90')
 {
     // if constructor failed to load.
     if (!$this->checkConstructorLoad()) {
         return false;
     }
     // check degree
     $allowed_degree = array(0, 90, 180, 270, 'hor', 'vrt', 'horvrt');
     if (!in_array($degree, $allowed_degree)) {
         $degree = 90;
     }
     if (!is_int($degree) && $degree != 'hor' && $degree != 'vrt' && $degree != 'horvrt') {
         $degree = (int) $degree;
     }
     unset($allowed_degree);
     // if image content not set, set it up (this case just call crop without resize).
     if ($this->new_img_content == null) {
         $result = $this->setImageContent();
         if ($result === false) {
             $this->status = false;
             $this->status_msg = 'Failed to set image content.';
             return false;
         }
         $new_img_content = $this->new_img_content;
         unset($result);
     } else {
         $new_img_content = $this->new_img_object;
     }
     // rotate.
     if (is_int($degree)) {
         // rotate by degrees number
         switch ($this->original_img_ext) {
             case '1':
                 // gif
             // gif
             case '2':
                 // jpg
                 $rotate = imagerotate($new_img_content, $degree, 0);
                 break;
             case '3':
                 // png
                 $rotate = imagerotate($new_img_content, $degree, imageColorAllocateAlpha($new_img_content, 0, 0, 0, 127));
                 imagealphablending($rotate, false);
                 imagesavealpha($rotate, true);
                 break;
             default:
                 // not allowed image type.
                 $this->status = false;
                 $this->status_msg = 'Unable to rotate this type of image.';
                 return false;
                 break;
         }
         $this->new_img_object = $rotate;
         $this->new_img_height = imagesy($rotate);
         $this->new_img_width = imagesx($rotate);
         // re-set original image height & width. because image was rotate
         $this->original_img_height = $this->new_img_height;
         $this->original_img_width = $this->new_img_width;
     } else {
         // if php version lower than 5.5
         if (phpversion() < 5.5) {
             $this->status = false;
             $this->status_msg = 'Unable to flip image using PHP older than 5.5.';
             return false;
         }
         if ($degree == 'hor') {
             $mode = IMG_FLIP_HORIZONTAL;
         } elseif ($degree == 'vrt') {
             $mode = IMG_FLIP_VERTICAL;
         } else {
             $mode = IMG_FLIP_BOTH;
         }
         // flip image.
         imageflip($new_img_content, $mode);
         unset($mode);
         $this->new_img_object = $new_img_content;
         $this->new_img_height = imagesy($new_img_content);
         $this->new_img_width = imagesx($new_img_content);
         // re-set original image height & width. because image was rotate
         $this->original_img_height = $this->new_img_height;
         $this->original_img_width = $this->new_img_width;
     }
     return true;
 }
コード例 #8
0
ファイル: ResourceHelper.php プロジェクト: nodir-y/imagecraft
 /**
  * Flip the image
  * @param  resource $srcResource the image resource
  * @param  int      $mode flip mode
  * @return resource the flipped resource
  */
 public function getFlippedGdResource($srcResource, $mode)
 {
     imageflip($srcResource, $mode);
     return $srcResource;
 }
コード例 #9
0
ファイル: PThumb.lib.php プロジェクト: rbrdevs/pydio-core
 /**
  * Prints out and cache the thumbnail. Returns verbose errors.
  * 
  * @access public
  * @param string $image The Relative Path to the image
  * @param integer $width The Width of the new thumbnail
  * @param integer $height The Height of the thumbnail
  * @param boolean $return_img Set to true to return the string instead of outputting it. Default to false
  * @param boolean $display_inline If set to true, heaers sent to browser will instruct it to display the image inline instead of asking the user to download. Defaults to true.
  * @return string
  * 
  */
 function print_thumbnail($image, $width, $height, $return_img = false, $display_inline = true, $target_file = false)
 {
     //Check parameters
     if (empty($image) || empty($width) || empty($height)) {
         return $this->set_error("Method print_thumbnail: Missing Parameters");
     }
     if (isset($this->currentRealFile) && is_file($this->currentRealFile)) {
         $image = $this->currentRealFile;
     }
     //Check whether $image is a remote address
     if ($this->is_remote($image) == 1) {
         $is_remote = true;
         //Check that file exists (Check only enabled in PHP 5 because only PHP 5 supports for checking remote files
         if (phpversion() >= 5) {
             if (!file_exists($image)) {
                 return $this->set_error("Method print_thumbnail: Error. The file '{$image}' you specified does not exists or cannot be accessed.");
             }
         }
         $image_data = $this->retrieve_remote_file($image, true, false, 1);
     } elseif ($this->is_remote($image) == 0) {
         $is_remote = false;
         if (!file_exists($image)) {
             return $this->set_error("Method print_thumbnail: Error. The file '{$image}' you specified does not exists or cannot be accessed.");
         }
         $image_data = implode("", file($image));
     }
     if (!is_string($image_data)) {
         return $this->set_error("Method print_thumbnail: Error, could not read image file '{$image}'.");
     }
     $array = $this->retrieve_image_data($image);
     if (!$array) {
         return $this->set_error("Method print_thumbnail: Unable to determine Image '{$image}' type and/or dimensions.");
     }
     list($ori_width, $ori_height, $format) = $array;
     //Check whether format is supported
     if (!array_key_exists($format, $this->file_ext)) {
         return $this->set_error("Method print_thumbnail: Image '{$image}' format is not supported.");
     }
     //Check that cache is enabled, cache DIR is writable, cache DIR exists
     if ($this->is_cacheable()) {
         //Passed eh? Generate the root dir of request file
         if ($is_remote != true) {
             $transformed = realpath($image);
             $hash = sha1_file($image);
         } else {
             $transformed = $image;
             $hash = sha1($image_data);
         }
         //Check if a version exists
         if ($this->exif_rotation) {
             $cache_file = $this->cache_dir . sha1($transformed) . "." . $width . "." . $height . ".rotated." . $hash . "." . $this->file_ext[$format];
         } else {
             $cache_file = $this->cache_dir . sha1($transformed) . "." . $width . "." . $height . "." . $hash . "." . $this->file_ext[$format];
         }
         if (file_exists($cache_file)) {
             if ($return_img == false) {
                 //AJXP_Logger::debug("Using Cache");
                 //die($cache_file);
                 header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
                 header("Cache-Control: no-store, no-cache, must-revalidate");
                 header("Pragma: no-cache");
                 header("Content-Transfer-Encoding: binary");
                 header("Content-type: " . image_type_to_mime_type($format));
                 if ($display_inline == true) {
                     header("Content-Disposition: inline; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
                 } else {
                     header("Content-Disposition: attachment; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
                 }
                 print implode("", file($cache_file));
                 die;
                 //Prepare redirectional URL
                 $redir_url = $_SERVER["HTTP_HOST"] . dirname($_SERVER["PHP_SELF"]) . "/" . $cache_file;
                 //Remove instances of double slashes "//"
                 $redir_url = str_replace("//", "/", $redir_url);
                 header("Location: http://{$redir_url}");
                 die;
             } else {
                 return implode("", file($cache_file));
             }
         } else {
             $handle = @opendir($this->cache_dir);
             if ($handle !== FALSE) {
                 while (false !== ($file = readdir($handle))) {
                     if ($this->exif_rotation) {
                         $rotated = "\\.rotated";
                     } else {
                         $rotated = "";
                     }
                     if (preg_match("/^" . preg_quote(sha1($transformed)) . "\\.[0-9]+\\.[0-9]+" . $rotated . "\\.([0-9a-z]{40})\\.(.+?)\$/i", $file, $matches)) {
                         //Hash is in [1]
                         //Check to see if the file data is the same. If it is, then don't delete it.
                         if ($matches[1] != $hash) {
                             $matched[] = $file;
                         }
                     }
                 }
                 closedir($handle);
                 if (!empty($matched)) {
                     for ($i = 0; $i <= count($matched) - 1; $i++) {
                         @unlink($this->cache_dir . $matched[$i]);
                     }
                 }
             }
         }
     }
     $gd_info = gd_info();
     //Special GIF handling
     if ($format == 1 && $gd_info["GIF Create Support"] != true) {
         //return $this -> set_error("Method print_thumbnail: Error, GIF support is unavaliable for PHP Version ".phpversion());
         //Image Outputted will be in PNG Format
         $format = 3;
     }
     $handle = @imagecreatefromstring($image_data);
     if ($handle == false) {
         return $this->set_error("Method print_thumbnail: Unsupported Image '{$image}' type");
     }
     //Exif Orientation patch
     $orientation = $this->exiforientation($image, true);
     if ($this->rotationsupported($orientation) and $orientation > 4) {
         $width2 = $width;
         $width = $height;
         $height = $width2;
     }
     //Now lets resize it
     //First lets create a new image handler which will be the thumbnailed image
     $thumbnail = imagecreatetruecolor($width, $height);
     if (!$thumbnail) {
         return $this->set_error("Method print_thumbnail: A thumbnail image '{$image}' could not be created");
     }
     /*  Image Format Special Handlinng */
     //GIF truecolour to palette - preserve transparency
     if ($format == 1) {
         imagetruecolortopalette($handle, true, 256);
     }
     //PNG Alpha Channel saving
     if ($format == 3) {
         //Set to save alpha channel info in source and destination
         imagealphablending($handle, false);
         imagesavealpha($handle, true);
         imagealphablending($thumbnail, false);
         imagesavealpha($thumbnail, true);
     }
     //Resize it
     if (!$this->fastimagecopyresampled($thumbnail, $handle, 0, 0, 0, 0, $width, $height, ImageSX($handle), ImageSY($handle), $this->thumb_quality)) {
         return $this->set_error("Method print_thumbnail: Failed resizing image '{$image}'.");
     }
     // Rotate if JPEG and Exif Information is available
     $orientation = $this->exiforientation($image, true);
     if ($this->rotationsupported($orientation)) {
         switch ($orientation) {
             case 2:
                 // mirror horizontal
                 @imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
                 break;
             case 3:
                 // rotate 180
                 $thumbnail = @imagerotate($thumbnail, 180, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
             case 4:
                 // mirror vertical
                 @imageflip($thumbnail, IMG_FLIP_VERTICAL);
                 break;
             case 5:
                 // mirror horizontal, 90 rotate left
                 @imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
                 $thumbnail = @imagerotate($thumbnail, 90, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
             case 6:
                 // 90 rotate right
                 $thumbnail = @imagerotate($thumbnail, -90, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
             case 7:
                 // mirror horizontal, 90 rotate right
                 @imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
                 $thumbnail = @imagerotate($thumbnail, -90, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
             case 8:
                 // 90 rotate left
                 $thumbnail = @imagerotate($thumbnail, 90, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
         }
     }
     //Cache it
     if ($this->is_cacheable()) {
         switch ($format) {
             case 1:
                 $cached = @imagegif($thumbnail, $cache_file);
                 break;
             case 2:
                 $cached = @imageJPEG($thumbnail, $cache_file, 100);
                 break;
             case 3:
                 $cached = @imagepng($thumbnail, $cache_file);
                 break;
             case 15:
                 $cached = @imagewbmp($thumbnail, $cache_file);
                 break;
             case 16:
                 $cached = @imagexbm($thumbnail, $cache_file);
                 break;
             default:
                 $cached = false;
         }
         if (!$cached) {
             return $this->set_error("Method print_thumbnail 1: Error in cache generation of image '{$image}'.");
         }
     }
     if ($target_file != false) {
         $wrappers = stream_get_wrappers();
         $wrappers_re = '(' . implode('|', $wrappers) . ')';
         $isStream = preg_match("!^{$wrappers_re}://!", $target_file) === 1;
         if ($isStream) {
             $backToStreamTarget = $target_file;
             $target_file = tempnam(AJXP_Utils::getAjxpTmpDir(), "pthumb_");
         }
         switch ($format) {
             case 1:
                 $cached = @imagegif($thumbnail, $target_file);
                 break;
             case 2:
                 $cached = @imageJPEG($thumbnail, $target_file, 100);
                 break;
             case 3:
                 $cached = @imagepng($thumbnail, $target_file);
                 break;
             case 15:
                 $cached = @imagewbmp($thumbnail, $target_file);
                 break;
             case 16:
                 $cached = @imagexbm($thumbnail, $target_file);
                 break;
             default:
                 $cached = false;
         }
         if ($cached && $isStream) {
             $cached = @copy($target_file, $backToStreamTarget);
             @unlink($target_file);
         }
         if (!$cached) {
             return $this->set_error("Method print_thumbnail: Error in cache generation of image '{$image}'.");
         }
         return true;
     }
     if ($return_img == false) {
         header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
         header("Cache-Control: no-store, no-cache, must-revalidate");
         header("Pragma: no-cache");
         header("Content-Transfer-Encoding: binary");
         header("Content-type: " . image_type_to_mime_type($format));
         if ($display_inline == true) {
             header("Content-Disposition: inline; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
         } else {
             header("Content-Disposition: attachment; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
         }
         if ($this->is_cacheable()) {
             echo implode("", file($cache_file));
         } else {
             switch ($format) {
                 case 1:
                     $outputed = @imagegif($thumbnail);
                     break;
                 case 2:
                     $outputed = @imageJPEG($thumbnail, null, 100);
                     break;
                 case 3:
                     $outputed = @imagepng($thumbnail);
                     break;
                 case 15:
                     $outpupted = @imagewbmp($thumbnail);
                     break;
                 case 16:
                     $outputed = @imagexbm($thumbnail, NULL);
                     break;
                 default:
                     $outputed = false;
             }
             if (!$outputed) {
                 return $this->set_error("Method print_thumbnail: Error outputting Image '{$image}'");
             }
         }
     } else {
         if ($this->is_cacheable()) {
             return implode("", file($cache_file));
         } else {
             return $this->set_error("Method print_thumbnail: Cannot return image '{$image}'! Cache must be enabled!");
         }
     }
     //Destroy the image
     imagedestroy($handle);
     imagedestroy($thumbnail);
     //Clear any cache; if needed
     $this->clear_cache();
 }
コード例 #10
0
 public function imageCreateJpegfromExif($filename)
 {
     $img = imagecreatefromjpeg($filename);
     $exif = exif_read_data($filename);
     if (!$exif || !isset($exif['Orientation'])) {
         return $img;
     }
     $orientation = $exif['Orientation'];
     if ($orientation === 6 || $orientation === 5) {
         $img = imagerotate($img, 270, null);
     } else {
         if ($orientation === 3 || $orientation === 4) {
             $img = imagerotate($img, 180, null);
         } else {
             if ($orientation === 8 || $orientation === 7) {
                 $img = imagerotate($img, 90, null);
             }
         }
     }
     if ($orientation === 5 || $orientation === 4 || $orientation === 7) {
         imageflip($img, IMG_FLIP_HORIZONTAL);
     }
     return $img;
 }
コード例 #11
0
ファイル: Parse_lib.php プロジェクト: skybee/france
 function flipImg($imgPathName)
 {
     $filename = $imgPathName;
     #$this->CI->dir_lib->getImgRdir().$this->lastLoadImgName;
     preg_match("#\\.([a-z]{3,4})\$#", $filename, $arr);
     if (isset($arr[1]) && !empty($arr[1])) {
         switch ($arr[1]) {
             case 'png':
                 $header = 'image/png';
                 $createImgFunc = '$im = imagecreatefrompng($filename);';
                 $outputImgFunc = 'imagepng($im,$filename);';
                 break;
             case 'jpg':
                 $header = 'image/jpeg';
                 $createImgFunc = '$im = imagecreatefromjpeg($filename);';
                 $outputImgFunc = 'imagejpeg($im,$filename,100);';
                 break;
             case 'jpeg':
                 $header = 'image/jpeg';
                 $createImgFunc = '$im = imagecreatefromjpeg($filename);';
                 $outputImgFunc = 'imagejpeg($im,$filename,100);';
                 break;
             default:
                 $header = false;
         }
     }
     if (!$header) {
         return false;
     }
     // Load
     eval($createImgFunc);
     // Flip it horizontally
     imageflip($im, IMG_FLIP_HORIZONTAL);
     // Output
     eval($outputImgFunc);
     imagedestroy($im);
 }
コード例 #12
0
ファイル: Gd.php プロジェクト: rundiz/image
 /**
  * {@inheritDoc}
  */
 public function rotate($degree = 90)
 {
     if (false === $this->isClassSetup()) {
         return false;
     }
     // check degree
     $allowed_flip = array('hor', 'vrt', 'horvrt');
     if (is_numeric($degree)) {
         $degree = intval($degree);
     } elseif (!is_numeric($degree) && !in_array($degree, $allowed_flip)) {
         $degree = 90;
     }
     unset($allowed_flip);
     // setup source image object
     if (false === $this->setupSourceImageObject()) {
         return false;
     }
     // check previous step contain errors?
     if ($this->isPreviousError() === true) {
         return false;
     }
     // begins rotate.
     if (is_int($degree)) {
         // rotate by degree
         switch ($this->source_image_type) {
             case '1':
                 // gif
                 // set source image width and height
                 $source_image_width = imagesx($this->source_image_object);
                 $source_image_height = imagesy($this->source_image_object);
                 $this->destination_image_object = imagecreatetruecolor($source_image_width, $source_image_height);
                 $transwhite = imagecolorallocatealpha($this->destination_image_object, 255, 255, 255, 127);
                 imagefill($this->destination_image_object, 0, 0, $transwhite);
                 imagecolortransparent($this->destination_image_object, $transwhite);
                 imagecopy($this->destination_image_object, $this->source_image_object, 0, 0, 0, 0, $source_image_width, $source_image_height);
                 $this->destination_image_object = imagerotate($this->destination_image_object, $degree, $transwhite);
                 unset($source_image_height, $source_image_width, $transwhite);
                 break;
             case '2':
                 // jpg
                 $white = imagecolorallocate($this->source_image_object, 255, 255, 255);
                 $this->destination_image_object = imagerotate($this->source_image_object, $degree, $white);
                 unset($white);
                 break;
             case '3':
                 // png
                 $transwhite = imageColorAllocateAlpha($this->source_image_object, 0, 0, 0, 127);
                 $this->destination_image_object = imagerotate($this->source_image_object, $degree, $transwhite);
                 imagealphablending($this->destination_image_object, false);
                 imagesavealpha($this->destination_image_object, true);
                 unset($transwhite);
                 break;
             default:
                 $this->status = false;
                 $this->status_msg = 'Unable to rotate this kind of image.';
                 return false;
         }
         $this->destination_image_height = imagesy($this->destination_image_object);
         $this->destination_image_width = imagesx($this->destination_image_object);
         $this->source_image_height = $this->destination_image_height;
         $this->source_image_width = $this->destination_image_width;
     } else {
         // flip image
         if (version_compare(phpversion(), '5.5', '<')) {
             $this->status = false;
             $this->status_msg = 'Unable to flip image using PHP older than 5.5.';
             return false;
         }
         if ($degree == 'hor') {
             $mode = IMG_FLIP_HORIZONTAL;
         } elseif ($degree == 'vrt') {
             $mode = IMG_FLIP_VERTICAL;
         } else {
             $mode = IMG_FLIP_BOTH;
         }
         // flip image.
         imageflip($this->source_image_object, $mode);
         unset($mode);
         $this->destination_image_object = $this->source_image_object;
         $this->destination_image_height = imagesy($this->source_image_object);
         $this->destination_image_width = imagesx($this->source_image_object);
         $this->source_image_height = $this->destination_image_height;
         $this->source_image_width = $this->destination_image_width;
     }
     // clear
     if (get_resource_type($this->source_image_object) === 'gd') {
         if ($this->source_image_object != $this->destination_image_object) {
             imagedestroy($this->source_image_object);
         }
         $this->source_image_object = null;
     }
     if (!$this->isPreviousError()) {
         $this->status = true;
         $this->status_msg = null;
     }
     return true;
 }
コード例 #13
0
ファイル: imager.php プロジェクト: Kunnapat/chowtime
function __image_flip($img, $mode)
{
    if (function_exists("imageflip")) {
        return imageflip($img, $mode);
    }
    $width = imagesx($img);
    $height = imagesy($img);
    $src_x = 0;
    $src_y = 0;
    $src_width = $width;
    $src_height = $height;
    switch ($mode) {
        case FLIP_HORIZONTAL:
            $src_x = $width - 1;
            $src_width = -$width;
            break;
        case FLIP_VERTICAL:
            $src_y = $height - 1;
            $src_height = -$height;
            break;
        case FLIP_BOTH:
            $src_x = $width - 1;
            $src_y = $height - 1;
            $src_width = -$width;
            $src_height = -$height;
            break;
        default:
            return $img;
    }
    $img_new = imagecreatetruecolor($width, $height);
    return imagecopyresampled($img_new, $img, 0, 0, $src_x, $src_y, $width, $height, $src_width, $src_height) ? $img_new : $img;
}
コード例 #14
0
ファイル: Identicon.php プロジェクト: ranvis/identicon
 /**
  * draw icon to internal buffer
  * @param string $hash
  * @return $this
  */
 public function draw($hash)
 {
     $index = 0;
     $tiles = $this->tiles;
     $tileSize = $this->tileSize;
     $tile = $this->tile;
     $tile->allocate($tileSize);
     $br = $tileSize * ($tiles - 1);
     $offsets = array(array(0, 0, 0, 1, 1, 0), array($br, 0, -1, 0, 0, 1), array($br, $br, 0, -1, -1, 0), array(0, $br, 1, 0, 0, -1), array($br, 0, 0, 1, -1, 0), array($br, $br, -1, 0, 0, -1), array(0, $br, 0, -1, 1, 0), array(0, 0, 1, 0, 0, 1));
     if (!$this->image) {
         $this->image = $image = imagecreatetruecolor($tileSize * $tiles, $tileSize * $tiles);
         $this->white = imagecolorallocate($image, 255, 255, 255);
     }
     $image = $this->image;
     $white = $this->white;
     $xEnd = $tiles + 1 >> 1;
     $xMid = $xEnd + 1 >> 1;
     $center = $tiles & 1 ? $tiles >> 1 : -1;
     $numColors = $this->colors;
     assert('$this->getMinimumHashLength() <= strlen($hash)');
     $colors = array();
     for ($i = 0; $i < $numColors; $i++) {
         $r = hexdec(substr($hash, $index, 2));
         $index += 2;
         $g = hexdec(substr($hash, $index, 2));
         $index += 2;
         $b = hexdec(substr($hash, $index, 2));
         $index += 2;
         $colors[] = $tile->getColor($r, $g, $b);
     }
     $baseColor = hexdec($hash[$index++]);
     $colorPattern = hexdec($hash[$index++]);
     $type = hexdec($hash[$index++]);
     for ($x = 0; $x < $xEnd; $x++) {
         $xOffsets = $offsets;
         for ($y = 0; $y <= $x; $y++) {
             $color = $baseColor;
             if ($colorPattern & 1) {
                 $color++;
             }
             if ($colorPattern & 2) {
                 $color += $x;
             }
             if ($colorPattern & 4) {
                 $color += $y;
             }
             if ($colorPattern & 8) {
                 $color += $x <= $xMid;
             }
             $type += hexdec($hash[$index++]);
             $tileImage = $tile->draw($type, $colors[$color % $numColors]);
             for ($i = 0; $i < 8; $i++) {
                 if ($i == 4 && ($y == $x || $x == 0)) {
                     break;
                 }
                 $offset = $xOffsets[$i];
                 if ($i < 4 || $x != $center) {
                     if ($i == 4) {
                         imageflip($tileImage, IMG_FLIP_HORIZONTAL);
                     }
                     imagecopy($image, $tileImage, $offset[0], $offset[1], 0, 0, $tileSize, $tileSize);
                     if ($x == $center && $y == $center) {
                         break;
                     }
                     if ($i != 7) {
                         $tileImage = imagerotate($tileImage, 270, $white);
                     }
                 }
                 $xOffsets[$i][0] += $offset[2] * $tileSize;
                 $xOffsets[$i][1] += $offset[3] * $tileSize;
             }
         }
         for ($i = 0; $i < 8; $i++) {
             $offsets[$i][0] += $offsets[$i][4] * $tileSize;
             $offsets[$i][1] += $offsets[$i][5] * $tileSize;
         }
     }
     return $this;
 }
コード例 #15
0
function wppa_orientate_image_file($file, $ori)
{
    // Validate args
    if (!is_file($file)) {
        wppa_log('Err', 'File not found (wppa_orientate_image_file())');
        return false;
    }
    if (!wppa_is_int($ori) || $ori < '2' || $ori > '8') {
        wppa_log('Err', 'Bad arg $ori:' . $ori . ' (wppa_orientate_image_file())');
        return false;
    }
    // Load image
    $source = wppa_imagecreatefromjpeg($file);
    if (!$source) {
        wppa_log('Err', 'Could not create memoryimage from jpg file ' . $file);
        return false;
    }
    // Perform operation
    switch ($ori) {
        case '2':
            $orientate = $source;
            imageflip($orientate, IMG_FLIP_HORIZONTAL);
            break;
        case '3':
            $orientate = imagerotate($source, 180, 0);
            break;
        case '4':
            $orientate = $source;
            imageflip($orientate, IMG_FLIP_VERTICAL);
            break;
        case '5':
            $orientate = imagerotate($source, 270, 0);
            imageflip($orientate, IMG_FLIP_HORIZONTAL);
            break;
        case '6':
            $orientate = imagerotate($source, 270, 0);
            break;
        case '7':
            $orientate = imagerotate($source, 90, 0);
            imageflip($orientate, IMG_FLIP_HORIZONTAL);
            break;
        case '8':
            $orientate = imagerotate($source, 90, 0);
            break;
    }
    // Output
    imagejpeg($orientate, $file, wppa_opt('jpeg_quality'));
    // Accessable
    wppa_chmod($file);
    // Optimized
    wppa_optimize_image_file($file);
    // Free the memory
    imagedestroy($source);
    @imagedestroy($orientate);
    // Done
    return true;
}
コード例 #16
0
ファイル: Image.php プロジェクト: radekdostal/utils
 /**
  * Resizes image.
  * @param  mixed  width in pixels or percent
  * @param  mixed  height in pixels or percent
  * @param  int    flags
  * @return self
  */
 public function resize($width, $height, $flags = self::FIT)
 {
     if ($flags & self::EXACT) {
         return $this->resize($width, $height, self::FILL)->crop('50%', '50%', $width, $height);
     }
     list($newWidth, $newHeight) = static::calculateSize($this->getWidth(), $this->getHeight(), $width, $height, $flags);
     if ($newWidth !== $this->getWidth() || $newHeight !== $this->getHeight()) {
         // resize
         $newImage = static::fromBlank($newWidth, $newHeight, self::RGB(0, 0, 0, 127))->getImageResource();
         imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $this->getWidth(), $this->getHeight());
         $this->image = $newImage;
     }
     if ($width < 0 || $height < 0) {
         imageflip($this->image, $width < 0 ? $height < 0 ? IMG_FLIP_BOTH : IMG_FLIP_HORIZONTAL : IMG_FLIP_VERTICAL);
     }
     return $this;
 }
コード例 #17
0
ファイル: Character.php プロジェクト: puring0815/OpenKore
 /**
  * Imprime um frame da animação do personagem
  * @param $action_index animação desejada
  * @param $frame_index frame da animação
  */
 public function output($action_index, $frame_index, $filename = "")
 {
     $center_x = $this->width / 2;
     $center_y = $this->height / 4 * 3;
     $img = imagecreatetruecolor($this->width, $this->height);
     // Cor que vai ser usada para a transparencia
     $pink = imagecolorallocate($img, 255, 255, 255);
     // Deixa toda a imagem transparente
     imagefill($img, 0, 0, $pink);
     imagecolortransparent($img, $pink);
     //Pega o frame do corpo
     $body = $this->body->getActionList()->getAction($action_index)->getFrame($frame_index);
     //e os sprites que compõem ele
     $sprites = $body->getSprites();
     // desenha o corpo
     foreach ($sprites as $s) {
         // caso o sprite seja invalido pula ele
         if ($s->getIndex() < 0) {
             continue;
         }
         //cria a imagem
         $tmp_img = $this->body->getSpriteList()->getSprite($s->getIndex())->createImage();
         //espelha a imagem se necessario
         if ($s->getMirror()) {
             imageflip($tmp_img, IMAGE_FLIP_HORIZONTAL);
         }
         imagerotate($tmp_img, $s->getRotation(), $pink);
         // calcula a largura e altura
         $width = $s->getWidth() ? $s->getWidth() : imagesx($tmp_img);
         $height = $s->getHeight() ? $s->getHeight() : imagesy($tmp_img);
         $width *= $s->getScaleX();
         $height *= $s->getScaleY();
         //desenha o sprite
         imagecopyresized($img, $tmp_img, $center_x - $width / 2 + $s->getX(), $center_y - $height / 2 + $s->getY(), 0, 0, $width, $height, imagesx($tmp_img), imagesy($tmp_img));
         imagedestroy($tmp_img);
     }
     //desenha todas as outras partes que compõem o personagem
     foreach ($this->parts as $part) {
         $frame = $part->getActionList()->getAction($action_index)->getFrame($frame_index);
         $sprites = $frame->getSprites();
         foreach ($sprites as $s) {
             if ($s->getIndex() < 0) {
                 continue;
             }
             $tmp_img = $part->getSpriteList()->getSprite($s->getIndex())->createImage();
             if ($s->getMirror()) {
                 imageflip($tmp_img, IMAGE_FLIP_HORIZONTAL);
             }
             imagerotate($tmp_img, $s->getRotation(), $pink);
             //imagefilter($tmp_img, IMG_FILTER_COLORIZE, 255, 0, 0, 255);
             $width = $s->getWidth() ? $s->getWidth() : imagesx($tmp_img);
             $height = $s->getHeight() ? $s->getHeight() : imagesy($tmp_img);
             $width *= $s->getScaleX();
             $height *= $s->getScaleY();
             imagecopyresized($img, $tmp_img, $center_x + ($body->getAttachPoint(0)->getX() - $frame->getAttachPoint(0)->getX() + $s->getX()) - $width / 2, $center_y + ($body->getAttachPoint(0)->getY() - $frame->getAttachPoint(0)->getY() + $s->getY()) - $height / 2, 0, 0, $width, $height, imagesx($tmp_img), imagesy($tmp_img));
             imagedestroy($tmp_img);
         }
     }
     header("Content-Type: image/gif");
     imagegif($img);
     imagedestroy($img);
 }
コード例 #18
0
ファイル: imageflip.php プロジェクト: badlamer/hhvm
<?php

$im = imagecreatetruecolor(99, 99);
imagesetpixel($im, 0, 0, 0xff);
imagesetpixel($im, 0, 98, 0xff00);
imagesetpixel($im, 98, 0, 0xff0000);
imagesetpixel($im, 98, 98, 0xff);
imageflip($im, IMG_FLIP_HORIZONTAL);
imageflip($im, IMG_FLIP_VERTICAL);
imageflip($im, IMG_FLIP_BOTH);
var_dump(dechex(imagecolorat($im, 0, 0)));
var_dump(dechex(imagecolorat($im, 0, 98)));
var_dump(dechex(imagecolorat($im, 98, 0)));
var_dump(dechex(imagecolorat($im, 98, 98)));
?>
 
コード例 #19
0
ファイル: Trim.php プロジェクト: sus-happy/Fegg_Tool_Trim
function flip_horizontal(&$imgsrc)
{
    // PHP5.5以上であればimageflipがあるので使う
    if (function_exists('imageflip')) {
        imageflip($imgsrc, IMG_FLIP_HORIZONTAL);
        return;
    }
    $x = imagesx($imgsrc);
    $y = imagesy($imgsrc);
    $flip = imagecreatetruecolor($x, $y);
    if (imagecopyresampled($flip, $imgsrc, 0, 0, $x - 1, 0, $x, $y, 0 - $x, $y)) {
        $imgsrc = $flip;
    }
}
コード例 #20
0
 protected function gd_imageflip($image, $mode)
 {
     if (function_exists('imageflip')) {
         return imageflip($image, $mode);
     }
     $new_width = $src_width = imagesx($image);
     $new_height = $src_height = imagesy($image);
     $new_img = imagecreatetruecolor($new_width, $new_height);
     $src_x = 0;
     $src_y = 0;
     switch ($mode) {
         case '1':
             // flip on the horizontal axis
             $src_y = $new_height - 1;
             $src_height = -$new_height;
             break;
         case '2':
             // flip on the vertical axis
             $src_x = $new_width - 1;
             $src_width = -$new_width;
             break;
         case '3':
             // flip on both axes
             $src_y = $new_height - 1;
             $src_height = -$new_height;
             $src_x = $new_width - 1;
             $src_width = -$new_width;
             break;
         default:
             return $image;
     }
     imagecopyresampled($new_img, $image, 0, 0, $src_x, $src_y, $new_width, $new_height, $src_width, $src_height);
     return $new_img;
 }
コード例 #21
0
ファイル: image.php プロジェクト: kebenxiaoming/owncloudRedis
 /**
  * (I'm open for suggestions on better method name ;)
  * Fixes orientation based on EXIF data.
  *
  * @return bool.
  */
 public function fixOrientation()
 {
     $o = $this->getOrientation();
     $this->logger->debug('OC_Image->fixOrientation() Orientation: ' . $o, array('app' => 'core'));
     $rotate = 0;
     $flip = false;
     switch ($o) {
         case -1:
             return false;
             //Nothing to fix
         //Nothing to fix
         case 1:
             $rotate = 0;
             break;
         case 2:
             $rotate = 0;
             $flip = true;
             break;
         case 3:
             $rotate = 180;
             break;
         case 4:
             $rotate = 180;
             $flip = true;
             break;
         case 5:
             $rotate = 90;
             $flip = true;
             break;
         case 6:
             $rotate = 270;
             break;
         case 7:
             $rotate = 270;
             $flip = true;
             break;
         case 8:
             $rotate = 90;
             break;
     }
     if ($flip && function_exists('imageflip')) {
         imageflip($this->resource, IMG_FLIP_HORIZONTAL);
     }
     if ($rotate) {
         $res = imagerotate($this->resource, $rotate, 0);
         if ($res) {
             if (imagealphablending($res, true)) {
                 if (imagesavealpha($res, true)) {
                     imagedestroy($this->resource);
                     $this->resource = $res;
                     return true;
                 } else {
                     $this->logger->debug('OC_Image->fixOrientation() Error during alpha-saving', array('app' => 'core'));
                     return false;
                 }
             } else {
                 $this->logger->debug('OC_Image->fixOrientation() Error during alpha-blending', array('app' => 'core'));
                 return false;
             }
         } else {
             $this->logger->debug('OC_Image->fixOrientation() Error during orientation fixing', array('app' => 'core'));
             return false;
         }
     }
     return false;
 }
コード例 #22
0
ファイル: ImageResizer.php プロジェクト: adrienrn/Osclass
 public function autoRotate()
 {
     if (osc_use_imagick()) {
         switch ($this->im->getImageOrientation()) {
             case imagick::ORIENTATION_TOPRIGHT:
                 $this->im->flopImage();
                 break;
             case imagick::ORIENTATION_BOTTOMRIGHT:
                 $this->im->rotateimage(new ImagickPixel('none'), 180);
                 // rotate 180 degrees
                 break;
             case imagick::ORIENTATION_BOTTOMLEFT:
                 $this->im->flopImage();
                 $this->im->rotateImage(new ImagickPixel('none'), 180);
                 break;
             case imagick::ORIENTATION_LEFTTOP:
                 $this->im->flopImage();
                 $this->im->rotateImage(new ImagickPixel('none'), -90);
                 break;
             case imagick::ORIENTATION_RIGHTTOP:
                 $this->im->rotateimage(new ImagickPixel('none'), 90);
                 // rotate 90 degrees CW
                 break;
             case imagick::ORIENTATION_RIGHTBOTTOM:
                 $this->im->flopImage();
                 $this->im->rotateImage(new ImagickPixel('none'), 90);
                 break;
             case imagick::ORIENTATION_LEFTBOTTOM:
                 $this->im->rotateimage(new ImagickPixel('none'), -90);
                 // rotate 90 degrees CCW
                 break;
             default:
                 // DO NOTHING, THE IMAGE IS OK OR WE DON'T KNOW IF IT'S ROTATED
                 break;
         }
     } else {
         if (isset($this->_exif['Orientation'])) {
             switch ($this->_exif['Orientation']) {
                 case 1:
                 default:
                     // DO NOTHING, THE IMAGE IS OK OR WE DON'T KNOW IF IT'S ROTATED
                     break;
                 case 2:
                     imageflip($this->im, IMG_FLIP_HORIZONTAL);
                     break;
                 case 3:
                     $this->im = imagerotate($this->im, 180, 0);
                     break;
                 case 4:
                     $this->im = imagerotate($this->im, 180, 0);
                     imageflip($this->im, IMG_FLIP_HORIZONTAL);
                     break;
                 case 5:
                     $this->im = imagerotate($this->im, 270, 0);
                     imageflip($this->im, IMG_FLIP_HORIZONTAL);
                     $aux = $this->_height;
                     $this->_height = $this->_width;
                     $this->_width = $aux;
                     break;
                 case 6:
                     $this->im = imagerotate($this->im, -90, 0);
                     $aux = $this->_height;
                     $this->_height = $this->_width;
                     $this->_width = $aux;
                     break;
                 case 7:
                     $this->im = imagerotate($this->im, 90, 0);
                     imageflip($this->im, IMG_FLIP_HORIZONTAL);
                     $aux = $this->_height;
                     $this->_height = $this->_width;
                     $this->_width = $aux;
                     break;
                 case 8:
                     $this->im = imagerotate($this->im, 90, 0);
                     $aux = $this->_height;
                     $this->_height = $this->_width;
                     $this->_width = $aux;
                     break;
             }
             $this->_exif['Orientation'] = 1;
         }
     }
     return $this;
 }
コード例 #23
0
ファイル: phppi.php プロジェクト: joszz/phppi
 function initialize()
 {
     //Debug Mode
     if ($this->settings['debug_mode'] == true) {
         error_reporting(E_ALL);
         ini_set('display_errors', '1');
     }
     ini_set('memory_limit', $this->settings['php_memory'] . 'M');
     //Set Thumb Size if changed
     if (isset($_POST['thumb_size'])) {
         if ($_POST['thumb_size'] == 0) {
             $this->setThumbSize('small');
         } else {
             if ($_POST['thumb_size'] == 1) {
                 $this->setThumbSize('medium');
             } else {
                 if ($_POST['thumb_size'] == 2) {
                     $this->setThumbSize('large');
                 }
             }
         }
     } else {
         $this->setThumbSize(NULL);
     }
     //GZIP Compression
     ini_set('zlib.output_compression', $this->settings['use_gzip_compression']);
     ini_set('zlib.output_compression_level', $this->settings['gzip_compression_level']);
     //Theme Mode
     $this->setThemeMode();
     if ($this->settings['allow_mobile_theme'] == true) {
         if (!is_file('phppi/themes/gallery/' . $this->settings['theme'] . '/' . $this->vars['theme_mode'] . '/template.php')) {
             $this->vars['theme_mode'] = 'standard';
         }
     } else {
         $this->vars['theme_mode'] = 'standard';
     }
     //Load Variables
     $this->loadVars();
     //Load Blacklists/Whitelists
     $this->loadLists();
     //Display Content
     if (isset($_GET['thumb'])) {
         //Show thumbnail only
         $this->genThumbnail($_GET['thumb']);
         exit;
     } else {
         if (isset($_GET['image'])) {
             //Show image
             if ($this->checkExploit('/' . $_GET['image']) == true) {
                 $filename = $this->vars['dir']['gallery'] . '/' . $_GET['image'];
                 $file_ext = strtolower($this->pathInfo($filename, 'file_ext'));
                 if ($file_ext == 'jpg' or $file_ext == 'jpeg') {
                     $image = imagecreatefromjpeg($filename);
                     $format = 'pjpeg';
                 } else {
                     if ($file_ext == 'png') {
                         $image = imagecreatefrompng($filename);
                         $format = 'png';
                     } else {
                         if ($file_ext == 'gif') {
                             $image = imagecreatefromgif($filename);
                             $format = 'gif';
                         }
                     }
                 }
                 $exif = @exif_read_data($filename);
                 if (isset($exif['Orientation'])) {
                     $ort = $exif['Orientation'];
                     if ($ort == 6 || $ort == 5) {
                         $image = imagerotate($image, 270, null);
                     }
                     if ($ort == 3 || $ort == 4) {
                         $image = imagerotate($image, 180, null);
                     }
                     if ($ort == 8 || $ort == 7) {
                         $image = imagerotate($image, 90, null);
                     }
                     if ($ort == 5 || $ort == 4 || $ort == 7) {
                         imageflip($image, IMG_FLIP_HORIZONTAL);
                     }
                 }
                 header("Content-Disposition: filename=" . basename($_GET['image']));
                 header("Content-Type: image/" . $format);
                 imagejpeg($image, null, 40);
                 imagedestroy($image);
             } else {
                 echo "File doesn't exist.";
             }
             exit;
         } else {
             if (isset($_GET['view'])) {
                 //Show full image view
                 $req_path = $this->pathInfo($_GET['view'], 'dir_path');
                 if ($req_path !== "") {
                     $req_path = "/" . $req_path;
                 }
                 if ($this->checkExploit($req_path) == true) {
                     if (!$this->getDir($req_path . '/')) {
                         $this->vars['error'] = 'Folder doesn\'t exist';
                         $this->vars['page_title'] = 'Error';
                         $this->vars['page_requested'] = 'error';
                         $this->logs("access", "add", "Folder not found (/" . $_GET['view'] . ")");
                     } else {
                         if (!is_file($this->vars['dir']['gallery'] . '/' . $_GET['view'])) {
                             $this->vars['error'] = 'File doesn\'t exist';
                             $this->vars['page_title'] = 'Error';
                             $this->vars['page_requested'] = 'error';
                             $this->logs("access", "add", "File not found (/" . $_GET['view'] . ")");
                         } else {
                             for ($i = 0; $i < count($this->vars['file_list']); $i++) {
                                 if ($this->vars['file_list'][$i]['file'] == $this->pathInfo($_GET['view'], 'full_file_name')) {
                                     $this->vars['current_image_id'] = $i;
                                     $this->vars['previous_image_id'] = NULL;
                                     $this->vars['next_image_id'] = NULL;
                                     if ($i > 0) {
                                         $this->vars['previous_image_id'] = $i - 1;
                                     }
                                     if ($i < count($this->vars['file_list']) - 1) {
                                         $this->vars['next_image_id'] = $i + 1;
                                     }
                                     break;
                                 }
                             }
                             if ($this->settings['page_title_show_full_path'] == true) {
                                 $this->vars['page_title'] = $this->settings['site_name'] . " - " . str_replace("/", " \\ ", $_GET['view']);
                             } else {
                                 $this->vars['page_title'] = $this->settings['site_name'] . " - " . $this->pathInfo($_GET['view'], 'full_file_name');
                             }
                             $this->vars['page_requested'] = 'image';
                             $this->logs("access", "add", "Viewed image (/" . $_GET['view'] . ")");
                         }
                     }
                 } else {
                     $this->vars['error'] = 'File doesn\'t exist';
                     $this->vars['page_title'] = 'Error';
                     $this->vars['page_requested'] = 'error';
                     $this->logs("access", "add", "Possible exploit attempt, blocked access (/" . $_GET['view'] . ")");
                 }
                 require 'phppi/themes/gallery/' . $this->settings['theme'] . '/' . $this->vars['theme_mode'] . '/template.php';
                 if ($this->settings['debug_show_vars'] == true) {
                     $this->outputVarsArray();
                 }
                 if ($this->settings['debug_show_settings'] == true) {
                     $this->outputSettingsArray();
                 }
             } else {
                 //Show folder view
                 if ($this->vars['dir']['req']['full'] == '') {
                     $dir_req = "";
                 } else {
                     $dir_req = $this->vars['dir']['req']['full'] . '/';
                 }
                 if ($this->vars['dir']['req']['full'] == '' || $this->checkExploit('/' . $this->vars['dir']['req']['full']) == true) {
                     if (!$this->getDir($dir_req)) {
                         $this->vars['error'] = 'Folder doesn\'t exist';
                         $this->vars['page_title'] = 'Error';
                         $this->vars['page_requested'] = 'error';
                         $this->logs("access", "add", "Folder not found (/" . $dir_req . ")");
                     } else {
                         if ($this->settings['page_title_show_full_path'] == true) {
                             if ($this->vars['dir']['req']['full'] == "") {
                                 $sep = "";
                             } else {
                                 $sep = " - ";
                             }
                             $this->vars['page_title'] = $this->settings['site_name'] . $sep . str_replace("/", " \\ ", $this->vars['dir']['req']['full']);
                         } else {
                             if ($this->vars['dir']['req']['full'] == "") {
                                 $sep = "";
                             } else {
                                 $sep = " - ";
                             }
                             $this->vars['page_title'] = $this->settings['site_name'] . $sep . $this->vars['dir']['req']['curr'];
                         }
                         $this->vars['page_requested'] = 'folder';
                         $this->logs("access", "add", "Viewed folder (/" . $dir_req . ")");
                     }
                 } else {
                     $this->vars['error'] = 'Folder doesn\'t exist';
                     $this->vars['page_title'] = 'Error';
                     $this->vars['page_requested'] = 'error';
                     $this->logs("access", "add", "Folder not found or exploit attempt, blocked access (/" . $dir_req . ")");
                 }
                 require 'phppi/themes/gallery/' . $this->settings['theme'] . '/' . $this->vars['theme_mode'] . '/template.php';
                 if ($this->settings['debug_show_vars'] == true) {
                     $this->outputVarsArray();
                 }
                 if ($this->settings['debug_show_settings'] == true) {
                     $this->outputSettingsArray();
                 }
             }
         }
     }
 }
コード例 #24
0
ファイル: Image.php プロジェクト: elboletaire/watimage
 /**
  * Flips an image. If PHP version is 5.5.0 or greater will use
  * proper php gd imageflip method. Otherwise will fallback to
  * convenienceflip.
  *
  * @param  string $type Type of flip, can be any of: horizontal, vertical, both
  * @return Image
  */
 public function flip($type = 'horizontal')
 {
     if (version_compare(PHP_VERSION, '5.5.0', '<')) {
         return $this->convenienceFlip($type);
     }
     imageflip($this->image, Normalize::flip($type));
     return $this;
 }
コード例 #25
0
ファイル: imageGen.php プロジェクト: TridentSoftware/signin
function printFromOptions($id)
{
    global $db, $infoText, $_POST;
    if (!isset($db)) {
        $db = new SQLite3('local_db.sql');
    }
    $id = $db->escapeString($id);
    $q = @$db->query('SELECT * FROM `users` WHERE `id`=' . $id);
    $user = $q->fetchArray();
    $visit = @$db->query('SELECT * FROM `visits` WHERE `uid`=' . $id . ' ORDER BY `time` DESC LIMIT 1;');
    if (($lastVisit = $visit->fetchArray()) === false) {
        if (isset($_POST['event'])) {
            header('Location: options.php?id=' . $id . "&event=" . htmlspecialchars($_POST['event']));
        } else {
            header('Location: options.php?id=' . $id);
        }
        return;
    } else {
        $infoText = $lastVisit['info'];
    }
    include 'phpqrcode/phpqrcode.php';
    unlink('resources/qr.png');
    unlink('temp.png');
    QRcode::png($id, 'resources/qr.png');
    $qrImage = imagecreatefrompng('resources/qr.png');
    if (isset($_POST['event'])) {
        echo $_POST['event'];
        $printText = $_POST['event'] . "\n" . $infoText;
    } else {
        $printText = $infoText;
    }
    $font = 'resources/Verdana.ttf';
    $logo = imagecreatefrompng('resources/logo.png');
    $width = 280 * 2;
    $height = 180 * 2;
    $im = @imagecreatetruecolor($width, $height) or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 255, 255, 255);
    $text_color = imagecolorallocate($im, 0, 0, 0);
    $text_color2 = imagecolorallocate($im, 100, 100, 100);
    //imageantialias($im, true);
    imagefill($im, 0, 0, $background_color);
    $tb = imagettfbbox(20, 0, $font, 'TechSpring');
    //solution found on PHP forums for centering text
    $x = ceil(($width - $tb[2]) / 2);
    imagettftext($im, 25, 0, $x, 50, $text_color2, $font, "TechSpring");
    //imagesavealpha($im, true);
    //imagealphablending($im, false);
    imagecopyresized($im, $logo, $x - 60, -5, 0, 0, 75, 75, 393, 413);
    imagecopyresized($im, $qrImage, 0, 0, 0, 0, 70, 70, 87, 87);
    imagettftext($im, 40, 0, 35, 110, $text_color, $font, $user['first_name'] . " " . $user['last_name']);
    imagettftext($im, 25, 0, 35, 170, $text_color2, $font, $printText);
    imageflip($im, IMG_FLIP_BOTH);
    imagesavealpha($im, false);
    imagepng($im, 'temp.png');
    imagedestroy($im);
    imagedestroy($logo);
}
コード例 #26
0
 /**
  * 转换可打印格式
  *
  * @param string $content
  * @return string
  */
 public function imageToBmp($content)
 {
     $imagine = new Imagine();
     $image = $imagine->load($content);
     // 宽 > 384
     if ($image->getSize()->getHeight() > self::CONTENT_MAX_WIDTH) {
         $image->resize($image->getSize()->widen(self::CONTENT_MAX_WIDTH));
     }
     // 转180度
     $image->rotate(180);
     $image->effects()->grayscale();
     /**
      * @var resource $im
      */
     $im = $image->getGdResource();
     // 水平反转
     imageflip($im, IMG_FLIP_HORIZONTAL);
     // 仿生处理
     $converter = new GDIndexedColorConverter();
     $palette = array(array(0, 0, 0), array(255, 255, 255));
     /**
      * @var resource $im
      */
     $im = $converter->convertToIndexedColor($im, $palette, 0.8);
     // 转为单色 bmp
     $dWord = function ($n) {
         return pack("V", $n);
     };
     $word = function ($n) {
         return pack("v", $n);
     };
     $width = imagesx($im);
     $height = imagesy($im);
     $widthPad = str_pad('', (4 - ceil($width / 8) % 4) % 4, "");
     $size = 62 + (ceil($width / 8) + strlen($widthPad)) * $height;
     $header['identifier'] = 'BM';
     $header['file_size'] = $dWord($size);
     $header['reserved'] = $dWord(0);
     $header['bitmap_data'] = $dWord(62);
     $header['header_size'] = $dWord(40);
     $header['width'] = $dWord($width);
     $header['height'] = $dWord($height);
     $header['planes'] = $word(1);
     $header['bits_per_pixel'] = $word(1);
     $header['compression'] = $dWord(0);
     $header['data_size'] = $dWord(0);
     $header['h_resolution'] = $dWord(0);
     $header['v_resolution'] = $dWord(0);
     $header['colors'] = $dWord(0);
     $header['important_colors'] = $dWord(0);
     $header['white'] = chr(255) . chr(255) . chr(255) . chr(0);
     $header['black'] = chr(0) . chr(0) . chr(0) . chr(0);
     $bmp = '';
     foreach ($header as $h) {
         $bmp .= $h;
     }
     $str = '';
     for ($y = $height - 1; $y >= 0; $y--) {
         for ($x = 0; $x < $width; $x++) {
             $rgb = imagecolorat($im, $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
             if ($gs > 150) {
                 $color = 0;
             } else {
                 $color = 1;
             }
             $str = $str . $color;
             if ($x == $width - 1) {
                 $str = str_pad($str, 8, "0");
             }
             if (strlen($str) == 8) {
                 $bmp .= chr((int) bindec($str));
                 $str = "";
             }
         }
         $bmp .= $widthPad;
     }
     imagedestroy($im);
     return $bmp;
 }
コード例 #27
0
ファイル: image.php プロジェクト: nuQuery/v1m0-api-image
 function flip($flip)
 {
     switch ($flip) {
         case 'h':
         case 'horizontal':
             imageflip($this->image, IMG_FLIP_HORIZONTAL);
             break;
         case 'v':
         case 'vertical':
             imageflip($this->image, IMG_FLIP_VERTICAL);
             break;
         case 'b':
         case 'hv':
         case 'vh':
         case 'both':
             imageflip($this->image, IMG_FLIP_BOTH);
             break;
     }
 }
コード例 #28
0
 function fix($path)
 {
     $image = imagecreatefromjpeg($path);
     $exif = exif_read_data($path);
     if (!empty($exif['Orientation'])) {
         switch ($exif['Orientation']) {
             case 1:
                 break;
             case 2:
                 imageflip($image, IMG_FLIP_HORIZONTAL);
                 break;
             case 3:
                 $image = imagerotate($image, 180, 0);
                 break;
             case 4:
                 imageflip($image, IMG_FLIP_VERTICAL);
                 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, $path);
     }
 }
コード例 #29
0
ファイル: do.php プロジェクト: skybee/cctv-pro
            $header = 'image/png';
            $createImgFunc = '$im = imagecreatefrompng($filename);';
            $outputImgFunc = 'imagepng($im);';
            break;
        case 'jpg':
            $header = 'image/jpeg';
            $createImgFunc = '$im = imagecreatefromjpeg($filename);';
            $outputImgFunc = 'imagejpeg($im);';
            break;
        case 'jpeg':
            $header = 'image/jpeg';
            $createImgFunc = '$im = imagecreatefromjpeg($filename);';
            $outputImgFunc = 'imagejpeg($im);';
            break;
        default:
            $header = false;
    }
}
if (!$header) {
    echo file_get_contents($filename);
    exit;
}
// Content type
header('Content-type: ' . $header);
// Load
eval($createImgFunc);
// Flip it horizontally
imageflip($im, IMG_FLIP_HORIZONTAL);
// Output
eval($outputImgFunc);
imagedestroy($im);
コード例 #30
0
ファイル: EmblemInfo.php プロジェクト: TorbenKoehn/gw2-php
 public function getImage(array $backgroundColor = null)
 {
     list($bgR, $bgG, $bgB, $bgA) = $backgroundColor ? array_pad($backgroundColor, 4, 0) : [0, 0, 0, 127];
     $img = imagecreatetruecolor(128, 128);
     imagesavealpha($img, true);
     imagealphablending($img, true);
     imagefill($img, 0, 0, imagecolorallocatealpha($img, $bgR, $bgG, $bgB, $bgA));
     if ($this->_backgroundId) {
         $background = $this->getBackground();
         $bgImage = $background->getImage($this->_backgroundColorId ? [$this->getBackgroundColor()->getLeatherRgbValue()->getArray()] : null);
         if (in_array('FlipBackgroundHorizontal', $this->_flags)) {
             imageflip($bgImage, \IMG_FLIP_HORIZONTAL);
         }
         if (in_array('FlipBackgroundVertical', $this->_flags)) {
             imageflip($bgImage, \IMG_FLIP_VERTICAL);
         }
         imagecopy($img, $bgImage, 0, 0, 0, 0, 128, 128);
         imagedestroy($bgImage);
     }
     if ($this->_foregroundId) {
         $foreground = $this->getForeground();
         $fgImage = $foreground->getImage([[0, 0, 0], $this->_foregroundPrimaryColorId ? $this->getForegroundPrimaryColor()->getLeatherRgbValue()->getArray() : [255, 0, 0], $this->_foregroundSecondaryColorId ? $this->getForegroundSecondaryColor()->getLeatherRgbValue()->getArray() : [0, 0, 255], [0, 0, 0]]);
         if (in_array('FlipForegroundHorizontal', $this->_flags)) {
             imageflip($fgImage, \IMG_FLIP_HORIZONTAL);
         }
         if (in_array('FlipForegroundVertical', $this->_flags)) {
             imageflip($fgImage, \IMG_FLIP_VERTICAL);
         }
         imagecopy($img, $fgImage, 0, 0, 0, 0, 128, 128);
         imagedestroy($fgImage);
     }
     return $img;
 }