/**
  * Rotate image
  *
  * @param  string   $path               image file
  * @param  int      $degree             rotete degrees
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author nao-pon
  * @author Troex Nevelin
  **/
 protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img->rotateImage(new ImagickPixel($bgcolor), $degree);
             $result = $img->writeImage($path);
             return $result ? $path : false;
             break;
         case 'gd':
             if ($s['mime'] == 'image/jpeg') {
                 $img = imagecreatefromjpeg($path);
             } elseif ($s['mime'] == 'image/png') {
                 $img = imagecreatefrompng($path);
             } elseif ($s['mime'] == 'image/gif') {
                 $img = imagecreatefromgif($path);
             } elseif ($s['mime'] == 'image/xbm') {
                 $img = imagecreatefromxbm($path);
             }
             $degree = 360 - $degree;
             list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
             $bgcolor = imagecolorallocate($img, $r, $g, $b);
             $tmp = imageRotate($img, $degree, (int) $bgcolor);
             if ($destformat == 'jpg' || $destformat == null && $s['mime'] == 'image/jpeg') {
                 $result = imagejpeg($tmp, $path, 100);
             } else {
                 if ($destformat == 'gif' || $destformat == null && $s['mime'] == 'image/gif') {
                     $result = imagegif($tmp, $path, 7);
                 } else {
                     $result = imagepng($tmp, $path, 7);
                 }
             }
             imageDestroy($img);
             imageDestroy($tmp);
             return $result ? $path : false;
             break;
     }
     return false;
 }
Example #2
0
 /**
  * Rotate the image clockwise
  *
  * @param Asido_TMP &$tmp
  * @param float $angle
  * @param Asido_Color &$color
  * @return boolean
  * @access protected
  */
 function __rotate(&$tmp, $angle, &$color)
 {
     // skip full loops
     //
     if ($angle % 360 == 0) {
         return true;
     }
     list($r, $g, $b) = $color->get();
     $rotate_color = imageColorAllocate($tmp->target, $r, $g, $b);
     if ($t = imageRotate($tmp->target, $angle * -1, $rotate_color)) {
         imageDestroy($tmp->target);
         $tmp->target = $t;
         $tmp->image_width = imageSX($tmp->target);
         $tmp->image_height = imageSY($tmp->target);
         return true;
     }
     return false;
 }
 /**
  * Rotate image
  *
  * @param  string   $path               image file
  * @param  int      $degree             rotete degrees
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author nao-pon
  * @author Troex Nevelin
  **/
 protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img->rotateImage(new ImagickPixel($bgcolor), $degree);
             $result = $img->writeImage($path);
             return $result ? $path : false;
             break;
         case 'gd':
             $img = self::gdImageCreate($path, $s['mime']);
             $degree = 360 - $degree;
             list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
             $bgcolor = imagecolorallocate($img, $r, $g, $b);
             $tmp = imageRotate($img, $degree, (int) $bgcolor);
             $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
             imageDestroy($img);
             imageDestroy($tmp);
             return $result ? $path : false;
             break;
     }
     return false;
 }
 /**
  * Rotate image
  *
  * @param  string   $path               image file
  * @param  int      $degree             rotete degrees
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author nao-pon
  * @author Troex Nevelin
  **/
 protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false || $degree % 360 === 0) {
         return false;
     }
     $result = false;
     // try lossless rotate
     if ($degree % 90 === 0 && in_array($s[2], array(IMAGETYPE_JPEG, IMAGETYPE_JPEG2000))) {
         $count = $degree / 90 % 4;
         $exiftran = array(1 => '-9', 2 => '-1', 3 => '-2');
         $jpegtran = array(1 => '90', 2 => '180', 3 => '270');
         $quotedPath = escapeshellarg($path);
         $cmds = array('exiftran -i ' . $exiftran[$count] . ' ' . $path, 'jpegtran -rotate ' . $jpegtran[$count] . ' -copy all -outfile ' . $quotedPath . ' ' . $quotedPath);
         foreach ($cmds as $cmd) {
             if ($this->procExec($cmd) === 0) {
                 $result = true;
                 break;
             }
         }
         if ($result) {
             return $path;
         }
     }
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             if ($img->getNumberImages() > 1) {
                 $img = $img->coalesceImages();
                 do {
                     $img->rotateImage(new ImagickPixel($bgcolor), $degree);
                 } while ($img->nextImage());
                 $img = $img->optimizeImageLayers();
                 $result = $img->writeImages($path, true);
             } else {
                 $img->rotateImage(new ImagickPixel($bgcolor), $degree);
                 $result = $img->writeImage($path);
             }
             $img->destroy();
             return $result ? $path : false;
             break;
         case 'gd':
             $img = self::gdImageCreate($path, $s['mime']);
             $degree = 360 - $degree;
             list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
             $bgcolor = imagecolorallocate($img, $r, $g, $b);
             $tmp = imageRotate($img, $degree, (int) $bgcolor);
             $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
             imageDestroy($img);
             imageDestroy($tmp);
             return $result ? $path : false;
             break;
     }
     return false;
 }
Example #5
0
 public static function rotateImage($thumbName, $size, $angle = 90, &$errorMsg)
 {
     $params = JComponentHelper::getParams('com_phocagallery');
     $jfile_thumbs = $params->get('jfile_thumbs', 1);
     $jpeg_quality = $params->get('jpeg_quality', 85);
     $jpeg_quality = PhocaGalleryImage::getJpegQuality($jpeg_quality);
     // Try to change the size
     $memory = 8;
     $memoryLimitChanged = 0;
     $memory = (int) ini_get('memory_limit');
     if ($memory == 0) {
         $memory = 8;
     }
     $fileIn = $thumbName->abs;
     $fileOut = $thumbName->abs;
     if ($fileIn !== '' && file_exists($fileIn)) {
         //array of width, height, IMAGETYPE, "height=x width=x" (string)
         list($w, $h, $type) = GetImageSize($fileIn);
         // we got the info from GetImageSize
         if ($w > 0 && $h > 0 && $type != '') {
             // Change the $w against $h because of rotating
             $src = array(0, 0, $w, $h);
             $dst = array(0, 0, $h, $w);
         } else {
             $errorMsg = 'ErrorWorHorType';
             return false;
         }
         // Try to increase memory
         if ($memory < 50) {
             ini_set('memory_limit', '50M');
             $memoryLimitChanged = 1;
         }
         switch ($type) {
             case IMAGETYPE_JPEG:
                 if (!function_exists('ImageCreateFromJPEG')) {
                     $errorMsg = 'ErrorNoJPGFunction';
                     return false;
                 }
                 //$image1 = ImageCreateFromJPEG($fileIn);
                 try {
                     $image1 = ImageCreateFromJPEG($fileIn);
                 } catch (\Exception $exception) {
                     $errorMsg = 'ErrorJPGFunction';
                     return false;
                 }
                 break;
             case IMAGETYPE_PNG:
                 if (!function_exists('ImageCreateFromPNG')) {
                     $errorMsg = 'ErrorNoPNGFunction';
                     return false;
                 }
                 //$image1 = ImageCreateFromPNG($fileIn);
                 try {
                     $image1 = ImageCreateFromPNG($fileIn);
                 } catch (\Exception $exception) {
                     $errorMsg = 'ErrorPNGFunction';
                     return false;
                 }
                 break;
             case IMAGETYPE_GIF:
                 if (!function_exists('ImageCreateFromGIF')) {
                     $errorMsg = 'ErrorNoGIFFunction';
                     return false;
                 }
                 //$image1 = ImageCreateFromGIF($fileIn);
                 try {
                     $image1 = ImageCreateFromGIF($fileIn);
                 } catch (\Exception $exception) {
                     $errorMsg = 'ErrorGIFFunction';
                     return false;
                 }
                 break;
             case IMAGETYPE_WBMP:
                 if (!function_exists('ImageCreateFromWBMP')) {
                     $errorMsg = 'ErrorNoWBMPFunction';
                     return false;
                 }
                 //$image1 = ImageCreateFromWBMP($fileIn);
                 try {
                     $image1 = ImageCreateFromWBMP($fileIn);
                 } catch (\Exception $exception) {
                     $errorMsg = 'ErrorWBMPFunction';
                     return false;
                 }
                 break;
             default:
                 $errorMsg = 'ErrorNotSupportedImage';
                 return false;
                 break;
         }
         if ($image1) {
             // Building image for ROTATING
             /*	$image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
             			if (!$image2) {
             				return 'ErrorNoImageCreateTruecolor';
             			}*/
             /*	if(!function_exists("imagerotate")) {
             				$errorMsg = 'ErrorNoImageRotate';
             				return false;
             			}*/
             switch ($type) {
                 case IMAGETYPE_PNG:
                     //	imagealphablending($image1, false);
                     //	imagesavealpha($image1, true);
                     if (!function_exists("imagecolorallocate")) {
                         $errorMsg = 'ErrorNoImageColorAllocate';
                         return false;
                     }
                     if (!function_exists("imagefill")) {
                         $errorMsg = 'ErrorNoImageFill';
                         return false;
                     }
                     if (!function_exists("imagecolortransparent")) {
                         $errorMsg = 'ErrorNoImageColorTransparent';
                         return false;
                     }
                     $colBlack = imagecolorallocate($image1, 0, 0, 0);
                     if (!function_exists("imagerotate")) {
                         $image2 = PhocaGalleryImageRotate::imageRotate($image1, $angle, $colBlack);
                     } else {
                         $image2 = imagerotate($image1, $angle, $colBlack);
                     }
                     imagefill($image2, 0, 0, $colBlack);
                     imagecolortransparent($image2, $colBlack);
                     break;
                 default:
                     if (!function_exists("imagerotate")) {
                         $image2 = PhocaGalleryImageRotate::imageRotate($image1, $angle, 0);
                     } else {
                         $image2 = imageRotate($image1, $angle, 0);
                     }
                     break;
             }
             // Get the image size and resize the rotated image if necessary
             $rotateWidth = imagesx($image2);
             // Get the size from rotated image
             $rotateHeight = imagesy($image2);
             // Get the size from rotated image
             $parameterSize = PhocaGalleryFileThumbnail::getThumbnailResize($size);
             $newWidth = $parameterSize['width'];
             // Get maximum sizes, they can be displayed
             $newHeight = $parameterSize['height'];
             // Get maximum sizes, they can be displayed
             $scale = $newWidth / $rotateWidth < $newHeight / $rotateHeight ? $newWidth / $rotateWidth : $newHeight / $rotateHeight;
             // smaller rate
             $src = array(0, 0, $rotateWidth, $rotateHeight);
             $dst = array(0, 0, floor($rotateWidth * $scale), floor($rotateHeight * $scale));
             // If original is smaller than thumbnail size, don't resize it
             if ($src[2] > $dst[2] || $src[3] > $dst[3]) {
                 // Building image for RESIZING THE ROTATED IMAGE
                 $image3 = @ImageCreateTruecolor($dst[2], $dst[3]);
                 if (!$image3) {
                     $errorMsg = 'ErrorNoImageCreateTruecolor';
                     return false;
                 }
                 ImageCopyResampled($image3, $image2, $dst[0], $dst[1], $src[0], $src[1], $dst[2], $dst[3], $src[2], $src[3]);
                 switch ($type) {
                     case IMAGETYPE_PNG:
                         //	imagealphablending($image2, true);
                         //	imagesavealpha($image2, true);
                         if (!function_exists("imagecolorallocate")) {
                             $errorMsg = 'ErrorNoImageColorAllocate';
                             return false;
                         }
                         if (!function_exists("imagefill")) {
                             $errorMsg = 'ErrorNoImageFill';
                             return false;
                         }
                         if (!function_exists("imagecolortransparent")) {
                             $errorMsg = 'ErrorNoImageColorTransparent';
                             return false;
                         }
                         $colBlack = imagecolorallocate($image3, 0, 0, 0);
                         imagefill($image3, 0, 0, $colBlack);
                         imagecolortransparent($image3, $colBlack);
                         break;
                 }
             } else {
                 $image3 = $image2;
             }
             switch ($type) {
                 case IMAGETYPE_JPEG:
                     if (!function_exists('ImageJPEG')) {
                         $errorMsg = 'ErrorNoJPGFunction';
                         return false;
                     }
                     if ($jfile_thumbs == 1) {
                         ob_start();
                         if (!@ImageJPEG($image3, NULL, $jpeg_quality)) {
                             ob_end_clean();
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                         $imgJPEGToWrite = ob_get_contents();
                         ob_end_clean();
                         if (!JFile::write($fileOut, $imgJPEGToWrite)) {
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                     } else {
                         if (!@ImageJPEG($image3, $fileOut, $jpeg_quality)) {
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                     }
                     break;
                 case IMAGETYPE_PNG:
                     if (!function_exists('ImagePNG')) {
                         $errorMsg = 'ErrorNoPNGFunction';
                         return false;
                     }
                     if ($jfile_thumbs == 1) {
                         ob_start();
                         if (!@ImagePNG($image3, NULL)) {
                             ob_end_clean();
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                         $imgPNGToWrite = ob_get_contents();
                         ob_end_clean();
                         if (!JFile::write($fileOut, $imgPNGToWrite)) {
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                     } else {
                         if (!@ImagePNG($image3, $fileOut)) {
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                     }
                     break;
                 case IMAGETYPE_GIF:
                     if (!function_exists('ImageGIF')) {
                         $errorMsg = 'ErrorNoGIFFunction';
                         return false;
                     }
                     if ($jfile_thumbs == 1) {
                         ob_start();
                         if (!@ImageGIF($image3, NULL)) {
                             ob_end_clean();
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                         $imgGIFToWrite = ob_get_contents();
                         ob_end_clean();
                         if (!JFile::write($fileOut, $imgGIFToWrite)) {
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                     } else {
                         if (!@ImageGIF($image3, $fileOut)) {
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                     }
                     break;
                 default:
                     $errorMsg = 'ErrorNotSupportedImage';
                     return false;
                     break;
             }
             // free memory
             ImageDestroy($image1);
             // Original
             ImageDestroy($image2);
             // Rotated
             ImageDestroy($image3);
             // Resized
             if ($memoryLimitChanged == 1) {
                 $memoryString = $memory . 'M';
                 ini_set('memory_limit', $memoryString);
             }
             return true;
             // Success
         } else {
             $errorMsg = PhocaGalleryUtils::setMessage($errorMsg, JText::_('COM_PHOCAGALLERY_ERROR_IMAGE_NOT_PROCESS'));
             return false;
         }
         if ($memoryLimitChanged == 1) {
             $memoryString = $memory . 'M';
             ini_set('memory_limit', $memoryString);
         }
     }
     $errorMsg = JText::_('COM_PHOCAGALLERY_FILEORIGINAL_NOT_EXISTS');
     return false;
 }
Example #6
0
 function rotateImage($thumbName, $size, $angle = 90)
 {
     // Try to change the size
     $memory = 8;
     $memoryLimitChanged = 0;
     $memory = (int) ini_get('memory_limit');
     if ($memory == 0) {
         $memory = 8;
     }
     $file_in = $thumbName['abs'];
     $file_out = $thumbName['abs'];
     if ($file_in !== '' && file_exists($file_in)) {
         //array of width, height, IMAGETYPE, "height=x width=x" (string)
         list($w, $h, $type) = GetImageSize($file_in);
         // we got the info from GetImageSize
         if ($w > 0 && $h > 0 && $type != '') {
             // Change the $w against $h because of rotating
             $src = array(0, 0, $w, $h);
             $dst = array(0, 0, $h, $w);
         } else {
             return 'ErrorWorHorType';
         }
         // Try to increase memory
         if ($memory < 50) {
             ini_set('memory_limit', '50M');
             $memoryLimitChanged = 1;
         }
         switch ($type) {
             case IMAGETYPE_JPEG:
                 if (!function_exists('ImageCreateFromJPEG')) {
                     return 'ErrorNoJPGFunction';
                 }
                 $image1 = ImageCreateFromJPEG($file_in);
                 break;
             case IMAGETYPE_PNG:
                 if (!function_exists('ImageCreateFromPNG')) {
                     return 'ErrorNoPNGFunction';
                 }
                 $image1 = ImageCreateFromPNG($file_in);
                 break;
             case IMAGETYPE_GIF:
                 if (!function_exists('ImageCreateFromGIF')) {
                     return 'ErrorNoGIFFunction';
                 }
                 $image1 = ImageCreateFromGIF($file_in);
                 break;
             case IMAGETYPE_WBMP:
                 if (!function_exists('ImageCreateFromWBMP')) {
                     return 'ErrorNoWBMPFunction';
                 }
                 $image1 = ImageCreateFromWBMP($file_in);
                 break;
             default:
                 return 'ErrorNotSupportedImage';
                 break;
         }
         if ($image1) {
             // Building image for ROTATING
             /*	$image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
             			if (!$image2) {
             				return 'ErrorNoImageCreateTruecolor';
             			}*/
             if (!function_exists("imagerotate")) {
                 return 'ErrorNoImageRotate';
             }
             switch ($type) {
                 case IMAGETYPE_PNG:
                     //	imagealphablending($image1, false);
                     //	imagesavealpha($image1, true);
                     if (!function_exists("imagecolorallocate")) {
                         return 'ErrorNoImageColorAllocate';
                     }
                     if (!function_exists("imagefill")) {
                         return 'ErrorNoImageFill';
                     }
                     if (!function_exists("imagecolortransparent")) {
                         return 'ErrorNoImageColorTransparent';
                     }
                     $colBlack = imagecolorallocate($image1, 0, 0, 0);
                     $image2 = imagerotate($image1, $angle, $colBlack);
                     imagefill($image2, 0, 0, $colBlack);
                     imagecolortransparent($image2, $colBlack);
                     break;
                 default:
                     $image2 = imageRotate($image1, $angle, 0);
                     break;
             }
             // Get the image size and resize the rotated image if necessary
             $rotateWidth = imagesx($image2);
             // Get the size from rotated image
             $rotateHeight = imagesy($image2);
             // Get the size from rotated image
             $parameterSize = PhocaGalleryHelper::getFileResize($size);
             $newWidth = $parameterSize['width'];
             // Get maximum sizes, they can be displayed
             $newHeight = $parameterSize['height'];
             // Get maximum sizes, they can be displayed
             $scale = $newWidth / $rotateWidth < $newHeight / $rotateHeight ? $newWidth / $rotateWidth : $newHeight / $rotateHeight;
             // smaller rate
             $src = array(0, 0, $rotateWidth, $rotateHeight);
             $dst = array(0, 0, floor($rotateWidth * $scale), floor($rotateHeight * $scale));
             // If original is smaller than thumbnail size, don't resize it
             if ($src[2] > $dst[2] || $src[3] > $dst[3]) {
                 // Building image for RESIZING THE ROTATED IMAGE
                 $image3 = @ImageCreateTruecolor($dst[2], $dst[3]);
                 if (!$image3) {
                     return 'ErrorNoImageCreateTruecolor';
                 }
                 ImageCopyResampled($image3, $image2, $dst[0], $dst[1], $src[0], $src[1], $dst[2], $dst[3], $src[2], $src[3]);
                 switch ($type) {
                     case IMAGETYPE_PNG:
                         //	imagealphablending($image2, true);
                         //	imagesavealpha($image2, true);
                         if (!function_exists("imagecolorallocate")) {
                             return 'ErrorNoImageColorAllocate';
                         }
                         if (!function_exists("imagefill")) {
                             return 'ErrorNoImageFill';
                         }
                         if (!function_exists("imagecolortransparent")) {
                             return 'ErrorNoImageColorTransparent';
                         }
                         $colBlack = imagecolorallocate($image3, 0, 0, 0);
                         imagefill($image3, 0, 0, $colBlack);
                         imagecolortransparent($image3, $colBlack);
                         break;
                 }
             } else {
                 $image3 = $image2;
             }
             switch ($type) {
                 case IMAGETYPE_JPEG:
                     if (!function_exists('ImageJPEG')) {
                         return 'ErrorNoJPGFunction';
                     }
                     if (!@ImageJPEG($image3, $file_out)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 case IMAGETYPE_PNG:
                     if (!function_exists('ImagePNG')) {
                         return 'ErrorNoPNGFunction';
                     }
                     if (!@ImagePNG($image3, $file_out)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 case IMAGETYPE_GIF:
                     if (!function_exists('ImageGIF')) {
                         return 'ErrorNoGIFFunction';
                     }
                     if (!@ImageGIF($image3, $file_out)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 default:
                     return 'ErrorNotSupportedImage';
                     break;
             }
             // free memory
             ImageDestroy($image1);
             // Original
             ImageDestroy($image2);
             // Rotated
             ImageDestroy($image3);
             // Resized
             if ($memoryLimitChanged == 1) {
                 $memoryString = $memory . 'M';
                 ini_set('memory_limit', $memoryString);
             }
             return 'Success';
             // Success
         } else {
             return 'Error1';
         }
         if ($memoryLimitChanged == 1) {
             $memoryString = $memory . 'M';
             ini_set('memory_limit', $memoryString);
         }
     }
     return 'Error2';
 }
Example #7
0
         $width = $height * $ratio_orig;
     } else {
         $height = $width / $ratio_orig;
     }
     # Resample
     $image_p = imagecreatetruecolor($width, $height);
     $image = imagecreatefromjpeg($konyvtar . '/' . $fajlnev_n);
     if ($degrees != "") {
         // Create a square image the size of the largest side of our src image
         $kulonb = ($width_orig - $height_orig) / 2;
         $tmp = imageCreateTrueColor($width_orig, $width_orig);
         // Exchange sides
         $image_p = imageCreateTrueColor($height, $width);
         // Now copy our src image to tmp where we will rotate and then copy that to $out
         imageCopy($tmp, $image, 0, $kulonb, 0, 0, $width_orig, $height_orig);
         $tmp2 = imageRotate($tmp, $degrees, 0);
         // Now copy tmp2 to $out;
         #majd kicsinyíteni a kívánt méretre
         imagecopyresampled($image_p, $tmp2, 0, 0, $kulonb, 0, $width, $height + 200, $width_orig, $width_orig);
     } else {
         imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
     }
     # Output
     imagejpeg($image_p, $konyvtar . '/' . $fajlnev_n);
     imagedestroy($image_p);
     #a képek adatainak rögzítése az adatbázisba
     if ($nincsfajl != 1) {
         $sql2 = "INSERT INTO " . $_SESSION[adatbazis_etag] . "_galeriakepek (sorszam, fajlnev_nagy, felirat_hu, csoport, kepszam) values ('{$num_rows}', '{$fajlnev_n}', '{$_REQUEST['felirat_hu']}', '{$_REQUEST['csoport']}', '{$num_rowkeps}')";
         mysql_query($sql2);
     }
 }
Example #8
0
 /**
  * Rotates this image
  * @param float $degrees Rotation angle, in degrees
  * @param string $uncoveredColor
  * @param boolean $handleTransparancy
  * @return Image new Image instance with a rotated version of this image
  */
 public function rotate($degrees, $uncoveredColor = '#000000', $handleTransparancy = false)
 {
     $uncoveredColor = $this->allocateColor($uncoveredColor);
     $result = new self($this);
     $result->resource = imageRotate($result->resource, $degrees, $uncoveredColor, $handleTransparancy);
     return $result;
 }
Example #9
0
 protected function rotateToExifOrientation()
 {
     if (!$this->exif || empty($this->exif['Orientation'])) {
         // No Exif Orientation; nothing to do, return original.
         return;
     }
     $flip = false;
     $rotate = 0;
     switch ($this->exif['Orientation']) {
         case 2:
             $flip = true;
             $rotate = 0;
             break;
         case 3:
             $flip = false;
             $rotate = 180;
             break;
         case 4:
             $flip = true;
             $rotate = 180;
             break;
         case 5:
             $flip = true;
             $rotate = 270;
             break;
         case 6:
             $flip = false;
             $rotate = 270;
             break;
         case 7:
             $flip = true;
             $rotate = 90;
             break;
         case 8:
             $flip = false;
             $rotate = 90;
             break;
         default:
             break;
     }
     if ($rotate !== 0) {
         $this->image = imageRotate($this->image, $rotate, 0);
         $this->width = imageSX($this->image);
         $this->height = imageSY($this->image);
         $this->exifRotated = true;
     }
     if ($flip) {
         $mirrored = imageCreateTrueColor($this->width, $this->height);
         imageCopyResampled($mirrored, $this->image, 0, 0, $this->width, 0, $this->width, $this->height, $this->width, $this->height);
         imageDestroy($this->image);
         $this->image = $mirrored;
         $this->exifRotated = true;
     }
 }
Example #10
0
 if ($extension == "gif") {
     $in = imagecreatefromgif($editDirectory . basename($imageName));
 }
 if ($extension == "png") {
     $in = imagecreatefrompng($editDirectory . basename($imageName));
 }
 if ($degrees == 180) {
     $out = imagerotate($in, $degrees, 180);
 } else {
     // 90 or 270
     $x = imagesx($in);
     $y = imagesy($in);
     $max = max($x, $y);
     $square = imagecreatetruecolor($max, $max);
     imagecopy($square, $in, 0, 0, 0, 0, $x, $y);
     $square = imageRotate($square, $degrees, 0);
     $out = imagecreatetruecolor($y, $x);
     if ($degrees == 90) {
         imagecopy($out, $square, 0, 0, 0, $max - $x, $y, $x);
     } elseif ($degrees == 270) {
         imagecopy($out, $square, 0, 0, $max - $y, 0, $y, $x);
     }
     imagedestroy($square);
 }
 if ($extension == "jpg" || $extension == "jpeg") {
     imagejpeg($out, $editDirectory . basename($imageName), 100);
 }
 if ($extension == "gif") {
     imagegif($out, $editDirectory . basename($imageName));
 }
 if ($extension == "png") {
 /**
  * Rotate image
  *
  * @param  string   $path               image file
  * @param  int      $degree             rotete degrees
  * @param  string   $bgcolor            square background color in #rrggbb format
  * @param  string   $destformat         image destination format
  * @param  int      $jpgQuality         JEPG quality (1-100)
  * @return string|false
  * @author nao-pon
  * @author Troex Nevelin
  **/
 protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null, $jpgQuality = null)
 {
     if (($s = getimagesize($path)) == false || $degree % 360 === 0) {
         return false;
     }
     $result = false;
     // try lossless rotate
     if ($degree % 90 === 0 && in_array($s[2], array(IMAGETYPE_JPEG, IMAGETYPE_JPEG2000))) {
         $count = $degree / 90 % 4;
         $exiftran = array(1 => '-9', 2 => '-1', 3 => '-2');
         $jpegtran = array(1 => '90', 2 => '180', 3 => '270');
         $quotedPath = escapeshellarg($path);
         $cmds = array('exiftran -i ' . $exiftran[$count] . ' ' . $path, 'jpegtran -rotate ' . $jpegtran[$count] . ' -copy all -outfile ' . $quotedPath . ' ' . $quotedPath);
         foreach ($cmds as $cmd) {
             if ($this->procExec($cmd) === 0) {
                 $result = true;
                 break;
             }
         }
         if ($result) {
             return $path;
         }
     }
     if (!$jpgQuality) {
         $jpgQuality = $this->options['jpgQuality'];
     }
     elFinder::extendTimeLimit(300);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             if ($s[2] === IMAGETYPE_GIF || $s[2] === IMAGETYPE_PNG) {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             if ($img->getNumberImages() > 1) {
                 $img = $img->coalesceImages();
                 do {
                     $img->rotateImage(new ImagickPixel($bgcolor), $degree);
                 } while ($img->nextImage());
                 $img = $img->optimizeImageLayers();
                 $result = $img->writeImages($path, true);
             } else {
                 $img->rotateImage(new ImagickPixel($bgcolor), $degree);
                 $result = $this->imagickImage($img, $path, $destformat, $jpgQuality);
             }
             $img->clear();
             return $result ? $path : false;
             break;
         case 'convert':
             extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
             if ($s[2] === IMAGETYPE_GIF || $s[2] === IMAGETYPE_PNG) {
                 $bgcolor = 'rgba(255, 255, 255, 0.0)';
             }
             $cmd = sprintf('convert %s%s%s -background "%s" -rotate %d%s %s', $quotedPath, $coalesce, $jpgQuality, $bgcolor, $degree, $deconstruct, $quotedDstPath);
             $result = false;
             if ($this->procExec($cmd) === 0) {
                 $result = true;
             }
             return $result ? $path : false;
             break;
         case 'gd':
             $img = $this->gdImageCreate($path, $s['mime']);
             $degree = 360 - $degree;
             $bgNum = -1;
             $bgIdx = false;
             if ($s[2] === IMAGETYPE_GIF) {
                 $bgIdx = imagecolortransparent($img);
                 if ($bgIdx !== -1) {
                     $c = imagecolorsforindex($img, $bgIdx);
                     $w = imagesx($img);
                     $h = imagesy($img);
                     $newImg = imagecreatetruecolor($w, $h);
                     imagepalettecopy($newImg, $img);
                     $bgNum = imagecolorallocate($newImg, $c['red'], $c['green'], $c['blue']);
                     imagefill($newImg, 0, 0, $bgNum);
                     imagecolortransparent($newImg, $bgNum);
                     imagecopy($newImg, $img, 0, 0, 0, 0, $w, $h);
                     imagedestroy($img);
                     $img = $newImg;
                     $newImg = null;
                 }
             } else {
                 if ($s[2] === IMAGETYPE_PNG) {
                     $bgNum = imagecolorallocatealpha($img, 255, 255, 255, 127);
                 }
             }
             if ($bgNum === -1) {
                 list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
                 $bgNum = imagecolorallocate($img, $r, $g, $b);
             }
             $tmp = imageRotate($img, $degree, $bgNum);
             if ($bgIdx !== -1) {
                 imagecolortransparent($tmp, $bgNum);
             }
             $result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
             imageDestroy($img);
             imageDestroy($tmp);
             return $result ? $path : false;
             break;
     }
     return false;
 }
Example #12
0
 /**
  * Rotate an image the given number of degrees.
  */
 public function rotate($source, $destination, $degrees, $background = 0x0)
 {
     if (!function_exists('imageRotate')) {
         return FALSE;
     }
     $info = $this->getInfo($source);
     if (!$info) {
         return FALSE;
     }
     $im = $this->open($source, $info['extension']);
     if (!$im) {
         return FALSE;
     }
     $res = imageRotate($im, $degrees, $background);
     $result = $this->close($res, $destination, $info['extension']);
     return $result;
 }
Example #13
0
 function rotate($degrees = 90)
 {
     self::getSizes();
     self::$output_type = strtolower(substr(self::getMime(), strpos(self::getMime(), '/') + 1));
     $icfunc = "imagecreatefrom" . self::$output_type;
     $img = @$icfunc(self::$original);
     if ($degrees == 180) {
         $dest = imagerotate($img, $degrees, 180);
     } else {
         $x = imagesx($img);
         $y = imagesy($img);
         $max = max($x, $y);
         $square = imagecreatetruecolor($max, $max);
         imagecopy($square, $img, 0, 0, 0, 0, $x, $y);
         $square = imageRotate($square, $degrees, 0);
         $dest = imagecreatetruecolor($y, $x);
         if ($degrees == 90) {
             imagecopy($dest, $square, 0, 0, 0, $max - $x, $y, $x);
         } else {
             if ($degrees == 270) {
                 imagecopy($dest, $square, 0, 0, $max - $y, 0, $y, $x);
             }
         }
         imagedestroy($square);
     }
     imagejpeg($dest, self::$thumb, self::$quality);
     self::destroy();
 }