示例#1
0
 /**
  * Contructor method. Will create a new image from the target file.
  * Accepts an image filename as a string. Method also works out how
  * big the image is and stores this in the $image array.
  *
  * @param string $imgFile The image filename.
  */
 public function ImageManipulation($imgfile)
 {
     //detect image format
     $this->image["format"] = strtolower(substr(strrchr($imgfile, '.'), 1));
     $this->image["format"] = strtoupper($this->image["format"]);
     // convert image into usable format.
     if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
         //JPEG
         $this->image["format"] = "JPEG";
         $this->image["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->image["format"] == "PNG") {
         //PNG
         $this->image["format"] = "PNG";
         $this->image["src"] = imagecreatefrompng($imgfile);
     } elseif ($this->image["format"] == "GIF") {
         //GIF
         $this->image["format"] = "GIF";
         $this->image["src"] = ImageCreateFromGif($imgfile);
     } elseif ($this->image["format"] == "WBMP") {
         //WBMP
         $this->image["format"] = "WBMP";
         $this->image["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         return false;
     }
     // Image is ok
     $this->imageok = true;
     // Work out image size
     $this->image["sizex"] = imagesx($this->image["src"]);
     $this->image["sizey"] = imagesy($this->image["src"]);
 }
示例#2
0
 private function thumbnail($imgfile)
 {
     //detect image format
     $this->acHWArr = getimagesize($imgfile);
     $this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File <a href='" . $_SERVER[HTTP_REFERER] . "'>Back</a>";
         exit;
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
 function thumbnail($imgfile)
 {
     //detect image format
     //$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
     $this->img["format"] = preg_replace('/.*\\.(.*)$/', "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File";
         exit;
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
示例#4
0
 function thumbnail($imgfile, $format = "image/jpeg")
 {
     //detect image format
     $pos = strpos($format, "/");
     $this->img["format"] = strtoupper(substr($format, $pos + 1));
     //$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
     //$this->img["format"]=strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File ";
         $this->is_img = false;
         return;
         //exit();
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
 function thumbnail($imgfile)
 {
     // ----- imagepfad speichern
     $this->imgfile = $imgfile;
     // ----- gif support ?
     $this->gifsupport = false;
     if (function_exists('imageGIF')) {
         $this->gifsupport = true;
     }
     // ----- detect image format
     $this->img['format'] = ereg_replace('.*\\.(.*)$', '\\1', $imgfile);
     $this->img['format'] = strtoupper($this->img['format']);
     if (!eregi('cache/', $imgfile)) {
         if ($this->img['format'] == 'JPG' || $this->img['format'] == 'JPEG') {
             // --- JPEG
             $this->img['format'] = 'JPEG';
             $this->img['src'] = @ImageCreateFromJPEG($imgfile);
         } elseif ($this->img['format'] == 'PNG') {
             // --- PNG
             $this->img['src'] = @ImageCreateFromPNG($imgfile);
         } elseif ($this->img['format'] == 'GIF') {
             // --- GIF
             if ($this->gifsupport) {
                 $this->img['src'] = @ImageCreateFromGIF($imgfile);
             }
         } elseif ($this->img['format'] == 'WBMP') {
             // --- WBMP
             $this->img['src'] = @ImageCreateFromWBMP($imgfile);
         }
         // ggf error image senden
         if (!$this->img['src']) {
             global $REX;
             $file = $REX['INCLUDE_PATH'] . '/addons/image_resize/media/warning.jpg';
             header('Content-Type: image/JPG');
             // error image nicht cachen
             header('Cache-Control: false');
             readfile($file);
             exit;
         }
         $this->img['width'] = imagesx($this->img['src']);
         $this->img['height'] = imagesy($this->img['src']);
         $this->img['width_offset_thumb'] = 0;
         $this->img['height_offset_thumb'] = 0;
         // --- default quality jpeg
         $this->img['quality'] = 75;
         $this->filters = array();
     }
 }
示例#6
0
 /**
  * constructor for resizing image
  * @internal
  *  @$this->img["lebar"]     source image X
  *  @$this->img['tinggi']    source image Y
  *
  * @param string $imgfile
  * @return void
  */
 function thumbnail($imgfile)
 {
     if (!file_exists($imgfile)) {
         return false;
     }
     ini_set('display_errors', '0');
     $this->sSourcePath2file = $imgfile;
     $this->img["src"] = $imgfile;
     $aImageSize = getimagesize($imgfile);
     $this->img['format'] = $aImageSize[2];
     if (extension_loaded('gd') || extension_loaded('gd2')) {
         set_time_limit('6000');
         ini_set('memory_limit', '100M');
         ini_set('post_max_size', '7M');
         switch ($this->img['format']) {
             case IMAGETYPE_GIF:
                 $this->img['src'] = ImageCreateFromGIF($imgfile);
                 break;
             case IMAGETYPE_JPEG:
                 $this->img['src'] = ImageCreateFromJPEG($imgfile);
                 break;
             case IMAGETYPE_PNG:
                 $this->img['src'] = ImageCreateFromPNG($imgfile);
                 break;
             case IMAGETYPE_WBMP:
                 $this->img['src'] = ImageCreateFromWBMP($imgfile);
                 break;
             default:
                 echo 'Not Supported File';
                 exit;
         }
     }
     /**
      *     @$this->img["lebar"] image X
      *    @$this->img['tinggi'] image Y
      */
     $this->img['lebar'] = $this->img["lebar_thumb"] = $this->img["width"] = $aImageSize[0];
     //imagesx($this->img["src"]);
     $this->img['tinggi'] = $this->img["tinggi_thumb"] = $this->img["height"] = $aImageSize[1];
     // imagesy($this->img["src"]);
     //default quality jpeg
     $this->img["quality"] = 85;
     $this->img['src_x'] = 0;
     $this->img['src_y'] = 0;
 }
 function rex_thumbnail($imgfile)
 {
     global $REX;
     // ----- imagepfad speichern
     $this->img = array();
     $this->imgfile = $imgfile;
     // ----- gif support ?
     $this->gifsupport = function_exists('imageGIF');
     // ----- detect image format
     $this->img['format'] = strtoupper(OOMedia::_getExtension($imgfile));
     $this->img['src'] = false;
     if (strpos($imgfile, 'cache/') === false) {
         if ($this->img['format'] == 'JPG' || $this->img['format'] == 'JPEG') {
             // --- JPEG
             $this->img['format'] = 'JPEG';
             $this->img['src'] = @ImageCreateFromJPEG($imgfile);
         } elseif ($this->img['format'] == 'PNG') {
             // --- PNG
             $this->img['src'] = @ImageCreateFromPNG($imgfile);
         } elseif ($this->img['format'] == 'GIF') {
             // --- GIF
             if ($this->gifsupport) {
                 $this->img['src'] = @ImageCreateFromGIF($imgfile);
             }
         } elseif ($this->img['format'] == 'WBMP') {
             // --- WBMP
             $this->img['src'] = @ImageCreateFromWBMP($imgfile);
         }
         // ggf error image senden
         if (!$this->img['src']) {
             $this->sendError();
             exit;
         }
         $this->img['width'] = imagesx($this->img['src']);
         $this->img['height'] = imagesy($this->img['src']);
         $this->img['width_offset_thumb'] = 0;
         $this->img['height_offset_thumb'] = 0;
         // --- default quality jpeg
         $this->img['quality'] = $REX['ADDON']['image_resize']['jpg_quality'];
         $this->filters = array();
     }
 }
 function thumbnail($imgfile)
 {
     // ----- imagepfad speichern
     $this->imgfile = $imgfile;
     // ----- gif support ?
     $this->gifsupport = false;
     if (function_exists('imageGIF')) {
         $this->gifsupport = true;
     }
     // ----- detect image format
     $this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if (!eregi('cache/', $imgfile)) {
         if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
             // --- JPEG
             $this->img["format"] = "JPEG";
             $this->img["src"] = ImageCreateFromJPEG($imgfile);
         } elseif ($this->img["format"] == "PNG") {
             // --- PNG
             $this->img["format"] = "PNG";
             $this->img["src"] = ImageCreateFromPNG($imgfile);
         } elseif ($this->img["format"] == "GIF") {
             // --- GIF
             $this->img["format"] = "GIF";
             if ($this->gifsupport) {
                 $this->img["src"] = ImageCreateFromGIF($imgfile);
             }
         } elseif ($this->img["format"] == "WBMP") {
             // --- WBMP
             $this->img["format"] = "WBMP";
             $this->img["src"] = ImageCreateFromWBMP($imgfile);
         } else {
             // --- DEFAULT
             echo "Not Supported File";
             exit;
         }
         @($this->img["width"] = imagesx($this->img["src"]));
         @($this->img["height"] = imagesy($this->img["src"]));
         // --- default quality jpeg
         $this->img["quality"] = 75;
     }
 }
 /**
  * Contructor method. Will create a new image from the target file.
  * Accepts an image filename as a string. Method also works out how
  * big the image is and stores this in the $image array.
  *
  * @param string $imgFile The image filename.
  */
 public function ImageManipulation($imgfile)
 {
     $imageinfo = getimagesize($imgfile);
     // debugLog($imageinfo);
     //detect image format
     //@todo: abstract use mime, and realpathparts not regex
     $this->image["format"] = $this->getFileImageType($imgfile);
     // convert image into usable format.
     if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
         //JPEG
         $this->image["format"] = "JPEG";
         $this->image["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->image["format"] == "PNG") {
         //PNG
         $this->image["format"] = "PNG";
         $this->image["src"] = imagecreatefrompng($imgfile);
     } elseif ($this->image["format"] == "GIF") {
         //GIF
         $this->image["format"] = "GIF";
         $this->image["src"] = ImageCreateFromGif($imgfile);
     } elseif ($this->image["format"] == "WBMP") {
         //WBMP
         $this->image["format"] = "WBMP";
         $this->image["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         $this->imageok = false;
         return false;
     }
     // Image is ok
     $this->imageok = true;
     // Work out image size
     $this->image['srcfile'] = $imgfile;
     $this->image['sizex'] = $imageinfo[0];
     $this->image['sizey'] = $imageinfo[1];
     $this->image['channels'] = $imageinfo[2];
     $this->image['bits'] = $imageinfo['bits'];
     $this->image['mime'] = $imageinfo['mime'];
     $this->image['width'] = $this->image["sizex"];
     $this->image['height'] = $this->image["sizey"];
     $this->image["ratio"] = $this->getRatio();
 }
示例#10
0
 public function createThumb($dir, $prefix, $max_x = false, $max_y = false, $prefixIsRealName = false, $mode = 'square')
 {
     if (!isset($this->hash)) {
         return FALSE;
     }
     if (!$dir) {
         $dir = dirname($this->file);
     }
     if (!$prefix) {
         $prefix = 't';
     }
     if (!$max_x && !$max_y || intval($max_x) <= 0 && intval($max_y) <= 0) {
         throw new PException('Neither thumbnail max-width nor max-height provided!');
     }
     $size_x = $this->imageSize[0];
     $size_y = $this->imageSize[1];
     // old school
     if (!$max_x || !$max_y) {
         if ($max_x && intval($max_x) > 0 && $size_x) {
             $th_size_x = intval($max_x);
             $th_size_y = intval($size_y * $th_size_x / $size_x);
             $size_x = $th_size_x;
             $size_y = $th_size_y;
         }
         if ($max_y && intval($max_y) > 0 && $size_y > $max_y) {
             $th_size_y = intval($max_y);
             $th_size_x = intval($size_x * $th_size_y / $size_y);
         }
         $startx = 0;
         $starty = 0;
         $size_x = $this->imageSize[0];
         $size_y = $this->imageSize[1];
     } else {
         switch ($mode) {
             case "ratio":
                 if ($max_x / $size_x >= $max_y / $size_y) {
                     $ratio = $max_y / $size_y;
                 } else {
                     $ratio = $max_x / $size_x;
                 }
                 $startx = 0;
                 $starty = 0;
                 break;
             default:
                 if ($size_x >= $size_y) {
                     $startx = ($size_x - $size_y) / 2;
                     $starty = 0;
                     $size_x = $size_y;
                 } else {
                     $starty = ($size_y - $size_x) / 2;
                     $startx = 0;
                     $size_y = $size_x;
                 }
                 if ($max_x >= $max_y) {
                     $ratio = $max_y / $size_y;
                 } else {
                     $ratio = $max_x / $size_x;
                 }
                 break;
         }
         $th_size_x = $size_x * $ratio;
         $th_size_y = $size_y * $ratio;
     }
     switch (intval($this->imageSize[2])) {
         // note: fixed this to use the proper constants. IMG_*** are GD constants, IMAGETYPE_*** are PHP constants.
         // The two DO NOT mix
         case IMAGETYPE_GIF:
             $oldImage = ImageCreateFromGIF($this->file);
             break;
         case IMAGETYPE_JPEG:
             $oldImage = ImageCreateFromJPEG($this->file);
             break;
         case IMAGETYPE_PNG:
             $oldImage = ImageCreateFromPNG($this->file);
             break;
         case IMAGETYPE_WBMP:
             $oldImage = ImageCreateFromWBMP($this->file);
             break;
         default:
             $e = new PException('Image type not supported!');
             $e->addInfo(print_r($this->imageSize, TRUE));
             throw $e;
             break;
     }
     $newImage = ImageCreateTrueColor($th_size_x, $th_size_y);
     imageCopyResampled($newImage, $oldImage, 0, 0, $startx, $starty, $th_size_x, $th_size_y, $size_x, $size_y);
     $newFile = tempnam('Lorem ipsum dolor sit amet', 'thumb');
     switch ($this->imageSize[2]) {
         case IMAGETYPE_GIF:
             ImageTrueColorToPalette($newImage, TRUE, 256);
             ImageGIF($newImage, $newFile);
             $mimetype = 'image/gif';
             break;
         case IMAGETYPE_JPEG:
             ImageJPEG($newImage, $newFile);
             $mimetype = 'image/jpeg';
             break;
         case IMAGETYPE_PNG:
             ImagePNG($newImage, $newFile);
             $mimetype = 'image/png';
             break;
         case IMAGETYPE_WBMP:
             ImageWBMP($newImage, $newFile);
             $mimetype = 'image/wbmp';
             break;
     }
     $dest = $dir . '/' . $prefix;
     if (!$prefixIsRealName) {
         $dest .= $this->hash;
     }
     if (!@copy($newFile, $dest)) {
         return false;
     }
     unlink($newFile);
     return true;
 }
示例#11
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;
 }
 function SourceImageToGD()
 {
     if ($this->config_use_exif_thumbnail_for_speed && !empty($this->exif_thumbnail_data)) {
         if ($this->exif_thumbnail_width >= $this->thumbnail_image_width && $this->exif_thumbnail_height >= $this->thumbnail_image_height && $this->thumbnailCropX == 0 && $this->thumbnailCropY == 0 && $this->source_width == $this->thumbnailCropW && $this->source_height == $this->thumbnailCropH) {
             // EXIF thumbnail exists, and is equal to or larger than destination thumbnail, and will be use as source image
             // Only benefit here is greater speed, not lower memory usage
             if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) {
                 $this->gdimg_source = $gdimg_exif_temp;
                 $this->source_width = $this->exif_thumbnail_width;
                 $this->source_height = $this->exif_thumbnail_height;
                 $this->thumbnailCropW = $this->source_width;
                 $this->thumbnailCropH = $this->source_height;
                 return true;
             }
         }
     }
     if (empty($this->gdimg_source)) {
         // try to create GD image source directly via GD, if possible,
         // rather than buffering to memory and creating with ImageCreateFromString
         if (!file_exists($this->sourceFilename)) {
             if (substr($this->sourceFilename, 0, 2) == '//') {
                 header('Location: ' . $this->sourceFilename);
                 exit;
             } else {
                 $this->ErrorImage('"' . $this->sourceFilename . '" does not exist');
             }
         } elseif (!is_file($this->sourceFilename)) {
             $this->ErrorImage('"' . $this->sourceFilename . '" is not a file');
         } elseif (@$this->getimagesizeinfo[2] == 1 && function_exists('ImageCreateFromGIF')) {
             $this->gdimg_source = @ImageCreateFromGIF($this->sourceFilename);
         } elseif (@$this->getimagesizeinfo[2] == 2 && function_exists('ImageCreateFromJPEG')) {
             $this->gdimg_source = @ImageCreateFromJPEG($this->sourceFilename);
         } elseif (@$this->getimagesizeinfo[2] == 3 && function_exists('ImageCreateFromPNG')) {
             $this->gdimg_source = @ImageCreateFromPNG($this->sourceFilename);
         } elseif (@$this->getimagesizeinfo[2] == 15 && function_exists('ImageCreateFromWBMP')) {
             $this->gdimg_source = @ImageCreateFromWBMP($this->sourceFilename);
         } else {
             // cannot create from filename, attempt to create source image with ImageCreateFromString, if possible
             if (empty($this->rawImageData)) {
                 if ($fp = @fopen($this->sourceFilename, 'rb')) {
                     $this->rawImageData = '';
                     $filesize = filesize($this->sourceFilename);
                     $blocksize = 16384;
                     $blockreads = ceil($filesize / $blocksize);
                     for ($i = 0; $i < $blockreads; $i++) {
                         //while (feof($fp) !== false) {
                         $this->rawImageData .= fread($fp, $blocksize);
                     }
                     fclose($fp);
                     $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->rawImageData, true);
                 } else {
                     $this->ErrorImage('cannot open "' . $this->sourceFilename . '"');
                 }
             }
         }
         if (empty($this->gdimg_source)) {
             // cannot create image for whatever reason,
             // simply output original (not resized/modified) data and exit
             switch (substr($this->rawImageData, 0, 3)) {
                 case 'GIF':
                     header('Content-type: image/gif');
                     break;
                 case "ÿØÿ":
                     header('Content-type: image/jpeg');
                     break;
                 case "‰" . 'PN':
                     header('Content-type: image/png');
                     break;
                 default:
                     $this->ErrorImage('Unknown image type identified by "' . substr($this->rawImageData, 0, 3) . '" (' . phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 3)) . ') in SourceImageToGD()');
                     break;
             }
             echo $this->rawImageData;
             exit;
         }
     }
     $this->source_width = ImageSX($this->gdimg_source);
     $this->source_height = ImageSY($this->gdimg_source);
     return true;
 }
示例#13
0
 function creatthumb($src_path, $src_name, $thumb_path = 'thumb/')
 {
     $src_img = $src_path . $src_name;
     //源图像为其路径加文件名
     $thumb_img = $src_path . $thumb_path . $src_name;
     //缩略图像为其路径加源图像文件名
     if ($this->checkpath($src_path . $thumb_path) == false) {
         $error['flag'] = 0;
         $error['tip'] = '缩略图存放目录不存在且无法创建';
         return $error;
     }
     $error = array();
     //提示信息
     if (file_exists($src_img) == false) {
         //源文件不存在则返回错误信息
         $error['flag'] = 0;
         $error['tip'] = '源图像不存在';
         return $error;
     }
     //临时用宽高度
     $t_width = $this->thumb_width;
     $t_height = $this->thumb_height;
     $src_info = getimagesize($src_img);
     //[0]=>宽,[1]=>高,[2]=>类型 1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,[3]=>文本索引
     //源图像小于或等于缩略图则拷贝源图像作为缩略图
     if ($src_info[0] <= $t_width && $src_info[1] <= $t_height) {
         if (copy($src_img, $src_path . $thumb_path . $src_name) == false) {
             $error['flag'] = 0;
             $error['tip'] = '复制文件失败';
         }
         $error['flag'] = 1;
         $error['tip'] = '创建缩略图成功';
         return $error;
     }
     //按比例计算缩略图大小
     //        if($this->thumb_force==0){
     //	        if ($src_info[0] - $t_width > $src_info[1] - $t_height) {
     //	            $t_height = ($t_width / $src_info[0]) * $src_info[1];
     //	        } else {
     //	            $t_width = ($t_height / $src_info[1]) * $src_info[0];
     //	        }
     //        }
     //创建临时图像
     $fileext = $this->fileext($src_img);
     switch ($fileext) {
         case 'gif':
             $temp_src_img = ImageCreateFromGIF($src_img);
             break;
         case 'jpg':
             $temp_src_img = ImageCreateFromJPEG($src_img);
             break;
         case 'jpeg':
             $temp_src_img = ImageCreateFromJPEG($src_img);
             break;
         case 'png':
             $temp_src_img = ImageCreateFromPNG($src_img);
             break;
         case 'bmp':
             $temp_src_img = ImageCreateFromWBMP($src_img);
             break;
         default:
             $error['flag'] = 0;
             $error['tip'] = '不支持此类图像创建缩略图';
             return $error;
     }
     //创建一个真彩色的缩略图像
     $temp_img = @ImageCreateTrueColor($t_width, $t_height);
     if (function_exists('imagecopyresampled')) {
         @ImageCopyResampled($temp_img, $temp_src_img, 0, 0, 0, 0, $t_width, $t_height, $src_info[0], $src_info[1]);
     } else {
         @ImageCopyResized($temp_img, $temp_src_img, 0, 0, 0, 0, $t_width, $t_height, $src_info[0], $src_info[1]);
     }
     //生成缩略图
     switch ($fileext) {
         case 'gif':
             ImageGIF($temp_img, $thumb_img);
             break;
         case 'jpg':
             ImageJPEG($temp_img, $thumb_img);
             break;
         case 'jpeg':
             ImageJPEG($temp_img, $thumb_img);
             break;
         case 'png':
             ImagePNG($temp_img, $thumb_img);
             break;
         case 'bmp':
             ImageWBMP($temp_img, $thumb_img);
             break;
         default:
             $error['flag'] = 0;
             $error['tip'] = '不支持此类图像创建缩略图';
             return $error;
     }
     //销毁临时图像
     @ImageDestroy($temp_src_img);
     @ImageDestroy($temp_img);
     $error['flag'] = 1;
     $error['tip'] = '创建缩略图成功';
     return $error;
 }
示例#14
0
文件: tourner.php 项目: rhertzog/lcs
function gdRotate ($src, $dest, $rtt){
	$src_img = '';
	if(preg_match("/\.(png|gif|jpe?g|bmp)$/i", $src, $regs)) {
		switch($regs[1]) {
			case 'png':
			  if (function_exists('ImageCreateFromPNG')) {
				$src_img=ImageCreateFromPNG($src);
				$save = 'imagepng';
			  }
			  break;
			case 'gif':
			  if (function_exists('ImageCreateFromGIF')) {
				$src_img=ImageCreateFromGIF($src);
				$save = 'imagegif';
			  }
			  break;
			case 'jpeg':
			case 'jpg':
			  if (function_exists('ImageCreateFromJPEG')) {
				$src_img=ImageCreateFromJPEG($src);
				$save = 'Imagejpeg';
			  }
			  break;
			case 'bmp':
			  if (function_exists('ImageCreateFromWBMP')) {
				$src_img=@ImageCreateFromWBMP($src);
				$save = 'imagewbmp';
			  }
			  break;
		}
	}

	if (!$src_img) {
		spip_log("gdrotate: image non lue, $src");
		return false;
	}

	$size=@getimagesize($src);
	if (!($size[0] * $size[1])) return false;

	if (function_exists('imagerotate')) {
		$dst_img = imagerotate($src_img, -$rtt, 0);
	} else {

		// Creer l'image destination (hauteur x largeur) et la parcourir
		// pixel par pixel (un truc de fou)
		if ($rtt == 180)
			$size_dest = $size;
		else
			$size_dest = array($size[1],$size[0]);

		if ($GLOBALS['meta']['image_process'] == "gd2")
			$dst_img=ImageCreateTrueColor($size_dest[0],$size_dest[1]);
		else
			$dst_img=ImageCreate($size_dest[0],$size_dest[1]);

		// t=top; b=bottom; r=right; l=left
		for ($t=0;$t<=$size_dest[0]-1; $t++) {
			$b = $size_dest[0] -1 - $t;
			for ($l=0;$l<=$size_dest[1]-1; $l++) {
				$r = $size_dest[1] -1 - $l;
				switch ($rtt) {
					case 90:
						imagecopy($dst_img,$src_img,$t,$r,$r,$b,1,1);
						break;
					case 270:
						imagecopy($dst_img,$src_img,$t,$l,$r,$t,1,1);
						break;
					case 180:
						imagecopy($dst_img,$src_img,$t,$l,$b,$r,1,1);
						break;
				}
			}
		}
	}
	ImageDestroy($src_img);
	ImageInterlace($dst_img,0);

	// obligatoire d'enregistrer dans le meme format, puisqu'on change le doc
	// mais pas son extension
	$save($dst_img,$dest);
}
示例#15
0
 /** Проверяем подключена ли библиотека GD 
  */
 private function setImageHandlerGD()
 {
     if (extension_loaded('gd') || extension_loaded('gd2')) {
         set_time_limit('6000');
         switch ($this->oImg['format']) {
             case IMAGETYPE_GIF:
                 $this->oImg['src'] = ImageCreateFromGIF($this->oImg['src']);
                 break;
             case IMAGETYPE_JPEG:
                 $this->oImg['src'] = ImageCreateFromJPEG($this->oImg['src']);
                 break;
             case IMAGETYPE_PNG:
                 $this->oImg['src'] = ImageCreateFromPNG($this->oImg['src']);
                 break;
             case IMAGETYPE_WBMP:
                 $this->oImg['src'] = ImageCreateFromWBMP($this->oImg['src']);
                 break;
             default:
                 $this->errors->set('wrong_file_format');
         }
         if ($this->errors->no()) {
             return true;
         }
     } else {
         $this->errors->set('gd_not_loaded');
     }
     return false;
 }
示例#16
0
 /**
  * need GD library (first PHP line WIN: dl("php_gd.dll"); UNIX: dl("gd.so");
  * www.boutell.com/gd/
  * interval.cz/clanky/php-skript-pro-generovani-galerie-obrazku-2/
  * cz.php.net/imagecopyresampled
  * www.linuxsoft.cz/sw_detail.php?id_item=871
  * www.webtip.cz/art/wt_tech_php/liquid_ir.html
  * php.vrana.cz/zmensovani-obrazku.php
  * diskuse.jakpsatweb.cz/
  *
  * @param string $fileIn Vstupni soubor (mel by existovat)
  * @param string $fileOut Vystupni soubor, null ho jenom zobrazi (taky kdyz nema pravo se zapsat :)
  * @param int $width Vysledna sirka (maximalni)
  * @param int $height Vysledna vyska (maximalni)
  * @param bool $crop Orez (true, obrazek bude presne tak velky), jinak jenom Resample (udane maximalni rozmery)
  * @param int $typeOut IMAGETYPE_type vystupniho obrazku
  * @return bool Chyba kdyz vrati false
  */
 public static function imageMagic($fileIn, $fileOut = null, $width = null, $height = null, $crop = null, $typeOut = null, $watermarkParams = array(), $frontUpload = 0, &$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);
     $fileWatermark = '';
     // While front upload we don't display the process page
     if ($frontUpload == 0) {
         $stopText = PhocaGalleryRenderProcess::displayStopThumbnailsCreating('processpage');
         echo $stopText;
     }
     // Memory - - - - - - - -
     $memory = 8;
     $memoryLimitChanged = 0;
     $memory = (int) ini_get('memory_limit');
     if ($memory == 0) {
         $memory = 8;
     }
     // - - - - - - - - - - -
     if ($fileIn !== '' && JFile::exists($fileIn)) {
         // array of width, height, IMAGETYPE, "height=x width=x" (string)
         list($w, $h, $type) = GetImageSize($fileIn);
         if ($w > 0 && $h > 0) {
             // we got the info from GetImageSize
             // size of the image
             if ($width == null || $width == 0) {
                 // no width added
                 $width = $w;
             } else {
                 if ($height == null || $height == 0) {
                     // no height, adding the same as width
                     $height = $width;
                 }
             }
             if ($height == null || $height == 0) {
                 // no height, no width
                 $height = $h;
             }
             // miniaturizing
             if (!$crop) {
                 // new size - nw, nh (new width/height)
                 $scale = $width / $w < $height / $h ? $width / $w : $height / $h;
                 // smaller rate
                 $src = array(0, 0, $w, $h);
                 $dst = array(0, 0, floor($w * $scale), floor($h * $scale));
             } else {
                 // will be cropped
                 $scale = $width / $w > $height / $h ? $width / $w : $height / $h;
                 // greater rate
                 $newW = $width / $scale;
                 // check the size of in file
                 $newH = $height / $scale;
                 // which side is larger (rounding error)
                 if ($w - $newW > $h - $newH) {
                     $src = array(floor(($w - $newW) / 2), 0, floor($newW), $h);
                 } else {
                     $src = array(0, floor(($h - $newH) / 2), $w, floor($newH));
                 }
                 $dst = array(0, 0, floor($width), floor($height));
             }
             // Watermark - - - - - - - - - - -
             if (!empty($watermarkParams) && ($watermarkParams['create'] == 1 || $watermarkParams['create'] == 2)) {
                 $thumbnailSmall = false;
                 $thumbnailMedium = false;
                 $thumbnailLarge = false;
                 $thumbnailMedium = preg_match("/phoca_thumb_m_/i", $fileOut);
                 $thumbnailLarge = preg_match("/phoca_thumb_l_/i", $fileOut);
                 $path = PhocaGalleryPath::getPath();
                 $fileName = PhocaGalleryFile::getTitleFromFile($fileIn, 1);
                 // Which Watermark will be used
                 // If watermark is in current directory use it else use Default
                 $fileWatermarkMedium = str_replace($fileName, 'watermark-medium.png', $fileIn);
                 $fileWatermarkLarge = str_replace($fileName, 'watermark-large.png', $fileIn);
                 clearstatcache();
                 // Which Watermark will be used
                 if ($thumbnailMedium) {
                     if (JFile::exists($fileWatermarkMedium)) {
                         $fileWatermark = $fileWatermarkMedium;
                     } else {
                         if ($watermarkParams['create'] == 2) {
                             $fileWatermark = $path->image_abs . 'watermark-medium.png';
                         } else {
                             $fileWatermark = '';
                         }
                     }
                 } else {
                     if ($thumbnailLarge) {
                         if (JFile::exists($fileWatermarkLarge)) {
                             $fileWatermark = $fileWatermarkLarge;
                         } else {
                             if ($watermarkParams['create'] == 2) {
                                 $fileWatermark = $path->image_abs . 'watermark-large.png';
                             } else {
                                 $fileWatermark = '';
                             }
                         }
                     } else {
                         $fileWatermark = '';
                     }
                 }
                 if (!JFile::exists($fileWatermark)) {
                     $fileWatermark = '';
                 }
                 if ($fileWatermark != '') {
                     list($wW, $hW, $typeW) = GetImageSize($fileWatermark);
                     switch ($watermarkParams['x']) {
                         case 'left':
                             $locationX = 0;
                             break;
                         case 'right':
                             $locationX = $dst[2] - $wW;
                             break;
                         case 'center':
                         default:
                             $locationX = $dst[2] / 2 - $wW / 2;
                             break;
                     }
                     switch ($watermarkParams['y']) {
                         case 'top':
                             $locationY = 0;
                             break;
                         case 'bottom':
                             $locationY = $dst[3] - $hW;
                             break;
                         case 'middle':
                         default:
                             $locationY = $dst[3] / 2 - $hW / 2;
                             break;
                     }
                 }
             } else {
                 $fileWatermark = '';
             }
         }
         if ($memory < 50) {
             ini_set('memory_limit', '50M');
             $memoryLimitChanged = 1;
         }
         // Resampling
         // in file
         // Watemark
         if ($fileWatermark != '') {
             if (!function_exists('ImageCreateFromPNG')) {
                 $errorMsg = 'ErrorNoPNGFunction';
                 return false;
             }
             $waterImage1 = ImageCreateFromPNG($fileWatermark);
         }
         // End Watermark - - - - - - - - - - - - - - - - - -
         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) {
             $image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
             if (!$image2) {
                 $errorMsg = 'ErrorNoImageCreateTruecolor';
                 return false;
             }
             switch ($type) {
                 case IMAGETYPE_PNG:
                     //imagealphablending($image1, false);
                     @imagealphablending($image2, false);
                     //imagesavealpha($image1, true);
                     @imagesavealpha($image2, true);
                     break;
             }
             ImageCopyResampled($image2, $image1, $dst[0], $dst[1], $src[0], $src[1], $dst[2], $dst[3], $src[2], $src[3]);
             // Watermark - - - - - -
             if ($fileWatermark != '') {
                 ImageCopy($image2, $waterImage1, $locationX, $locationY, 0, 0, $wW, $hW);
             }
             // End Watermark - - - -
             // Display the Image - not used
             if ($fileOut == null) {
                 header("Content-type: " . image_type_to_mime_type($typeOut));
             }
             // Create the file
             if ($typeOut == null) {
                 // no bitmap
                 $typeOut = $type == IMAGETYPE_WBMP ? IMAGETYPE_PNG : $type;
             }
             switch ($typeOut) {
                 case IMAGETYPE_JPEG:
                     if (!function_exists('ImageJPEG')) {
                         $errorMsg = 'ErrorNoJPGFunction';
                         return false;
                     }
                     if ($jfile_thumbs == 1) {
                         ob_start();
                         if (!@ImageJPEG($image2, 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($image2, $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($image2, 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($image2, $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($image2, 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($image2, $fileOut)) {
                             $errorMsg = 'ErrorWriteFile';
                             return false;
                         }
                     }
                     break;
                 default:
                     $errorMsg = 'ErrorNotSupportedImage';
                     return false;
                     break;
             }
             // free memory
             ImageDestroy($image1);
             ImageDestroy($image2);
             if (isset($waterImage1)) {
                 ImageDestroy($waterImage1);
             }
             if ($memoryLimitChanged == 1) {
                 $memoryString = $memory . 'M';
                 ini_set('memory_limit', $memoryString);
             }
             $errorMsg = '';
             // Success
             return true;
         } else {
             $errorMsg = 'Error1';
             return false;
         }
         if ($memoryLimitChanged == 1) {
             $memoryString = $memory . 'M';
             ini_set('memory_limit', $memoryString);
         }
     }
     $errorMsg = 'Error2';
     return false;
 }
 static function crop($_filename, $width, $height)
 {
     $filename = self::pullFilename($_filename);
     if (empty($filename)) {
         return null;
     }
     $absPath = $_SERVER["DOCUMENT_ROOT"] . '/';
     $absPathSource = $absPath;
     $absPathSourceFileName = substr($filename, 1, 1) == '/' ? $absPathSource . $filename : $absPathSource . '/' . $filename;
     $md5Filename = md5($filename) . "-c-{$width}-{$height}";
     $imgExt = pathinfo($filename, PATHINFO_EXTENSION);
     if (file_exists($absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt)) {
         return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
     }
     if (!file_exists($absPathSourceFileName)) {
         return null;
     }
     list($width_orig, $height_orig) = getimagesize($absPathSourceFileName);
     $width_orig_ = $width_orig;
     $height_orig_ = $height_orig;
     //////////// определение пропорций, под которые подгонять картинку.
     $k = $width_orig / $height_orig;
     $k_out = $width / $height;
     if ($k > $k_out) {
         $width_orig = $height_orig * $k_out;
     } else {
         $height_orig = $width_orig / $k_out;
     }
     ///////////////////////// если картинка не попадает под пропорции, то часть оригинала нужно обрезать.
     $ratio_orig = $width_orig / $height_orig;
     if ($width / $height > $ratio_orig) {
         $width = $height * $ratio_orig;
     } else {
         $height = $width / $ratio_orig;
     }
     //// отцентровать будущую картинку отцентровать по центру оригинала
     $x_shift = ($width_orig_ - $width_orig) / 2;
     $y_shift = ($height_orig_ - $height_orig) / 2;
     $image_p = imagecreatetruecolor($width, $height);
     switch (exif_imagetype($absPathSourceFileName)) {
         case IMAGETYPE_JPEG:
             $image = ImageCreateFromJPEG($absPathSourceFileName);
             imagecopyresampled($image_p, $image, 0, 0, $x_shift, $y_shift, $width, $height, $width_orig, $height_orig);
             ImageJPEG($image_p, $absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt, 87);
             return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
         case IMAGETYPE_GIF:
             $image = ImageCreateFromGIF($absPathSourceFileName);
             imagecopyresampled($image_p, $image, 0, 0, $x_shift, $y_shift, $width, $height, $width_orig, $height_orig);
             ImageGIF($image_p, $absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt);
             return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
         case IMAGETYPE_PNG:
             $image = ImageCreateFromPNG($absPathSourceFileName);
             imagecopyresampled($image_p, $image, 0, 0, $x_shift, $y_shift, $width, $height, $width_orig, $height_orig);
             ImagePNG($image_p, $absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt);
             return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
         case IMAGETYPE_WBMP:
             $image = ImageCreateFromWBMP($absPathSourceFileName);
             imagecopyresampled($image_p, $image, 0, 0, $x_shift, $y_shift, $width, $height, $width_orig, $height_orig);
             ImageWBMP($image_p, $absPath . self::$pathToCropImg . $md5Filename . '.' . $imgExt);
             return '/' . self::$pathToCropImg . $md5Filename . '.' . $imgExt;
         default:
             return $filename;
     }
 }
示例#18
0
 function OpenImage($filename)
 {
     if (!file_exists($filename)) {
         return 0;
     }
     $type = strtolower(substr($filename, strrpos($filename, ".") + 1, 4));
     switch ($type) {
         default:
             return 0;
             break;
         case "png":
             if (ImageTypes() & IMG_PNG) {
                 $img_src = ImageCreateFromPNG($filename);
             }
             break;
         case "jpeg":
         case "jpg":
             if (ImageTypes() & IMG_JPG) {
                 $img_src = ImageCreateFromJPEG($filename);
             }
             break;
         case "gif":
             if (ImageTypes() & IMG_GIF) {
                 $img_src = ImageCreateFromGIF($filename);
             }
             break;
         case "wbmp":
             if (ImageTypes() & IMG_WBMP) {
                 $img_src = ImageCreateFromWBMP($filename);
             }
             break;
         case "bmp":
             include_once "ext_scripts/gd/bmp.php";
             $img_src = ImageCreateFromBMP($filename);
             break;
         case "ico":
             include_once "ext_scripts/gd/ico.php";
             $img_src = ImageCreateFromICO($filename);
             break;
         case "cur":
             include_once "ext_scripts/gd/cur.php";
             $img_src = ImageCreateFromCUR($filename);
             break;
             /*			case "ani":
             				include_once("ext_scripts/gd/ani.php");
             				$img_src = ImageCreateFromANI($filename);
             			break;*/
     }
     return $img_src;
 }
示例#19
0
 /**
  * need GD library (first PHP line WIN: dl("php_gd.dll"); UNIX: dl("gd.so");
  * www.boutell.com/gd/
  * interval.cz/clanky/php-skript-pro-generovani-galerie-obrazku-2/
  * cz.php.net/imagecopyresampled
  * www.linuxsoft.cz/sw_detail.php?id_item=871
  * www.webtip.cz/art/wt_tech_php/liquid_ir.html
  * php.vrana.cz/zmensovani-obrazku.php
  * diskuse.jakpsatweb.cz/
  *
  * @param string $file_in Vstupni soubor (mel by existovat)
  * @param string $file_out Vystupni soubor, null ho jenom zobrazi (taky kdyz nema pravo se zapsat :)
  * @param int $width Vysledna sirka (maximalni)
  * @param int $height Vysledna vyska (maximalni)
  * @param bool $crop Orez (true, obrazek bude presne tak velky), jinak jenom Resample (udane maximalni rozmery)
  * @param int $type_out IMAGETYPE_type vystupniho obrazku
  * @return bool Chyba kdyz vrati false
  */
 function imageMagic($file_in, $file_out = null, $width = null, $height = null, $crop = null, $type_out = null, $watermarkParams = array(), $frontUpload = 0)
 {
     $fileWatermark = '';
     // While front upload we don't display the process page
     if ($frontUpload == 0) {
         $stopText = PhocaGalleryHelper::displayStopThumbnailsCreating();
         echo $stopText;
     }
     $memory = 8;
     $memoryLimitChanged = 0;
     $memory = (int) ini_get('memory_limit');
     if ($memory == 0) {
         $memory = 8;
     }
     if ($file_in !== '' && file_exists($file_in)) {
         //array of width, height, IMAGETYPE, "height=x width=x" (string)
         list($w, $h, $type) = GetImageSize($file_in);
         if ($w > 0 && $h > 0) {
             // we got the info from GetImageSize
             // size of the image
             if ($width == null || $width == 0) {
                 // no width added
                 $width = $w;
             } else {
                 if ($height == null || $height == 0) {
                     // no height, adding the same as width
                     $height = $width;
                 }
             }
             if ($height == null || $height == 0) {
                 // no height, no width
                 $height = $h;
             }
             // miniaturizing
             if (!$crop) {
                 // new size - nw, nh (new width/height)
                 $scale = $width / $w < $height / $h ? $width / $w : $height / $h;
                 // smaller rate
                 $src = array(0, 0, $w, $h);
                 $dst = array(0, 0, floor($w * $scale), floor($h * $scale));
             } else {
                 // will be cropped
                 $scale = $width / $w > $height / $h ? $width / $w : $height / $h;
                 // greater rate
                 $newW = $width / $scale;
                 // check the size of in file
                 $newH = $height / $scale;
                 // which side is larger (rounding error)
                 if ($w - $newW > $h - $newH) {
                     $src = array(floor(($w - $newW) / 2), 0, floor($newW), $h);
                 } else {
                     $src = array(0, floor(($h - $newH) / 2), $w, floor($newH));
                 }
                 $dst = array(0, 0, floor($width), floor($height));
             }
             // Watermark
             if (!empty($watermarkParams) && $watermarkParams['create'] == 1) {
                 $thumbnailSmall = false;
                 $thumbnailMedium = false;
                 $thumbnailLarge = false;
                 $thumbnailMedium = preg_match("/phoca_thumb_m_/i", $file_out);
                 $thumbnailLarge = preg_match("/phoca_thumb_l_/i", $file_out);
                 $fileName = PhocaGalleryHelper::getTitleFromFilenameWithExt($file_in);
                 // Which Watermark will be used
                 if ($thumbnailMedium) {
                     $fileWatermark = str_replace($fileName, 'watermark-medium.png', $file_in);
                 } else {
                     if ($thumbnailLarge) {
                         $fileWatermark = str_replace($fileName, 'watermark-large.png', $file_in);
                     } else {
                         $fileWatermark = '';
                     }
                 }
                 if (!file_exists($fileWatermark)) {
                     $fileWatermark = '';
                 }
                 if ($fileWatermark != '') {
                     list($wW, $hW, $typeW) = GetImageSize($fileWatermark);
                     switch ($watermarkParams['x']) {
                         case 'left':
                             $locationX = 0;
                             break;
                         case 'right':
                             $locationX = $dst[2] - $wW;
                             break;
                         case 'center':
                         default:
                             $locationX = $dst[2] / 2 - $wW / 2;
                             break;
                     }
                     switch ($watermarkParams['y']) {
                         case 'top':
                             $locationY = 0;
                             break;
                         case 'bottom':
                             $locationY = $dst[3] - $hW;
                             break;
                         case 'middle':
                         default:
                             $locationY = $dst[3] / 2 - $hW / 2;
                             break;
                     }
                 }
             } else {
                 $fileWatermark = '';
             }
         }
         if ($memory < 50) {
             ini_set('memory_limit', '50M');
             $memoryLimitChanged = 1;
         }
         // Resampling
         // in file
         // Watemark
         if ($fileWatermark != '') {
             if (!function_exists('ImageCreateFromPNG')) {
                 return 'ErrorNoPNGFunction';
             }
             $waterImage1 = ImageCreateFromPNG($fileWatermark);
         }
         // End Watermark
         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) {
             // protection against invalid image dimensions
             /*foreach ($dst as $kdst =>$vdst) {
             			if ($dst[$kdst] == 0 ) {
             			$dst[$kdst] = 1;
             			}
             		} */
             $image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
             if (!$image2) {
                 return 'ErrorNoImageCreateTruecolor';
             }
             switch ($type) {
                 case IMAGETYPE_PNG:
                     //imagealphablending($image1, false);
                     @imagealphablending($image2, false);
                     //imagesavealpha($image1, true);
                     @imagesavealpha($image2, true);
                     break;
             }
             ImageCopyResampled($image2, $image1, $dst[0], $dst[1], $src[0], $src[1], $dst[2], $dst[3], $src[2], $src[3]);
             // Watermark
             if ($fileWatermark != '') {
                 ImageCopy($image2, $waterImage1, $locationX, $locationY, 0, 0, $wW, $hW);
             }
             // End Watermark
             // display the image
             if ($file_out == null) {
                 header("Content-type: " . image_type_to_mime_type($type_out));
             }
             // out file
             if ($type_out == null) {
                 // no bitmap
                 $type_out = $type == IMAGETYPE_WBMP ? IMAGETYPE_PNG : $type;
             }
             switch ($type_out) {
                 case IMAGETYPE_JPEG:
                     if (!function_exists('ImageJPEG')) {
                         return 'ErrorNoJPGFunction';
                     }
                     if (!@ImageJPEG($image2, $file_out, 85)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 case IMAGETYPE_PNG:
                     if (!function_exists('ImagePNG')) {
                         return 'ErrorNoPNGFunction';
                     }
                     if (!@ImagePNG($image2, $file_out)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 case IMAGETYPE_GIF:
                     if (!function_exists('ImageGIF')) {
                         return 'ErrorNoGIFFunction';
                     }
                     if (!@ImageGIF($image2, $file_out)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 default:
                     return 'ErrorNotSupportedImage';
                     break;
             }
             // free memory
             ImageDestroy($image1);
             ImageDestroy($image2);
             if (isset($waterImage1)) {
                 ImageDestroy($waterImage1);
             }
             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';
 }
 /**
  * Создает новое изображение из файла
  * @param $ImgFileName
  * @param int $Width
  * @param int $Height
  * @return mixed
  */
 public function CreateFromFile($ImgFileName, $Width = 0, $Height = 0)
 {
     if (!file_exists($ImgFileName)) {
         ErrorHandler(USER_NOTICE, 'Файл не найден', 'TPicture::CreateFromFile');
         return;
     }
     if ($this->gd != null) {
         $this->Destruct();
     }
     $size = getimagesize($ImgFileName);
     $format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));
     $vformat = false;
     if ($format == 'jpg' || $format == 'jpeg') {
         $vformat = true;
         $this->Format = IMAGE_JPEG;
         $this->gd = ImageCreateFromJPEG($ImgFileName);
     } elseif ($format == 'png') {
         $vformat = true;
         $this->Format = IMAGE_PNG;
         $this->gd = ImageCreateFromPNG($ImgFileName);
     } elseif ($format == 'gif') {
         $vformat = true;
         $this->Format = IMAGE_GIF;
         $this->gd = ImageCreateFromGIF($ImgFileName);
     } elseif ($format == 'wbmp') {
         $vformat = true;
         $this->Format = IMAGE_WBMP;
         $this->gd = ImageCreateFromWBMP($ImgFileName);
     }
     if ($vformat) {
         $this->SaveFormat = $this->Format;
         $this->Width = $size[0];
         $this->Height = $size[1];
         $this->NewWidth = 0;
         $this->NewHeight = 0;
         $this->JpegQuality = 95;
     }
 }
示例#21
0
 private function create()
 {
     if (!isset($this->error) and preg_match("/^[0-9]{1,2}\$/", $this->type)) {
         switch ($this->type) {
             case 1:
                 return ImageCreateFromGIF($this->photo);
                 break;
             case 3:
                 return ImageCreateFromPNG($this->photo);
                 break;
             case 6:
             case 15:
                 return ImageCreateFromWBMP($this->photo);
                 break;
             default:
                 return ImageCreateFromJPEG($this->photo);
         }
     }
 }
示例#22
0
function picture_openrandomformat($image, $mime = false){
	if ($mime == false && strtolower(substr($image, 0, 7)) == "http://"){
		$last4 = strtolower(substr($image, -4));
		$last5 = strtolower(substr($image, -5));
		
		if ($last4 == ".jpg" || $last5 == ".jpeg"){
			$mime = "image/jpeg";
		}elseif($last4 == ".gif"){
			$mime = "image/gif";
		}elseif($last4 == ".bmp"){
			$mime = "image/bmp";
		}elseif($last4 == ".png"){
			$mime = "image/png";
		}
	}
	
	if ($mime == false){
		$mime = GetImageSize($image);
		$mime = $mime["mime"];
	}
	
	if ($mime == "image/jpeg"){
		return ImageCreateFromJPEG($image);
	}elseif($mime == "image/gif"){
		$img = ImageCreateFromGIF($image);
	}elseif($mime == "image/bmp"){
		require_once("knj/functions_knj_picture_bmp.php");
		return ImageCreateFromBMP($image);
	}elseif($mime == "image/vnd.wbmp"){
		return ImageCreateFromWBMP($image);
	}elseif($mime == "image/png"){
		$img = ImageCreateFromPNG($image);
	}else{
		return false;
	}
	
	return $img;
}
示例#23
0
文件: watermark.php 项目: romlg/cms36
 function AddWatermark($type, $str)
 {
     $type = StrToUpper($type);
     switch ($type) {
         case STREAM:
             $this->mark_image = ImageCreateFromString($str);
             break;
         case FILE_JPEG:
             $this->mark_image = ImageCreateFromJPEG($str);
             break;
         case FILE_GIF:
             $this->mark_image = ImageCreateFromGIF($str);
             break;
         case FILE_PNG:
             $this->mark_image = ImageCreateFromPNG($str);
             break;
         case FILE_WBMP:
             $this->mark_image = ImageCreateFromWBMP($str);
             break;
         case FILE_XBM:
             $this->mark_image = ImageCreateFromXBM($str);
             break;
         case FILE_XPM:
             $this->mark_image = ImageCreateFromXPM($str);
             break;
         case HANDLE:
             $this->mark_image = $str;
             break;
         default:
             $this->dieError("Unknown input type in addWatermark method!");
             return false;
     }
     if (!$this->mark_image) {
         $this->dieError("GD command error in addWatermark method!");
         return false;
     }
     // get size of mark
     $this->mark_width = ImageSX($this->mark_image);
     $this->mark_height = ImageSY($this->mark_image);
     // calculate offsets
     $this->getOffsets();
     // merge images
     $this->createMarkedImage($type);
     return true;
 }
示例#24
0
/**
 * make thumbnail image and save
 */
function thumbnail($file, $save_filename, $max_width = 100, $max_height = 100, $sizeChg = 1)
{
    $img_info = @getimagesize($file);
    //이미지 사이즈를 확인합니다.
    //이미지 타입을 이용해 변수를 재지정해줍니다.
    //------------------------------------------------------
    // Imagetype Constants
    //------------------------------------------------------
    // 1 IMAGETYPE_GIF
    // 2 IMAGETYPE_JPEG
    // 3 IMAGETYPE_PNG
    // 4 IMAGETYPE_SWF
    // 5 IMAGETYPE_PSD
    // 6 IMAGETYPE_BMP
    // 7 IMAGETYPE_TIFF_II (intel byte order)
    // 8 IMAGETYPE_TIFF_MM (motorola byte order)
    // 9 IMAGETYPE_JPC
    // 10 IMAGETYPE_JP2
    // 11 IMAGETYPE_JPX
    // 12 IMAGETYPE_JB2
    // 13 IMAGETYPE_SWC
    // 14 IMAGETYPE_IFF
    // 15 IMAGETYPE_WBMP
    // 16 IMAGETYPE_XBM
    //------------------------------------------------------
    if ($img_info[2] == 1) {
        $src_img = ImageCreateFromGIF($file);
    } elseif ($img_info[2] == 2) {
        $src_img = ImageCreateFromJPEG($file);
    } elseif ($img_info[2] == 3) {
        $src_img = ImageCreateFromPNG($file);
    } elseif ($img_info[2] == 4) {
        $src_img = ImageCreateFromWBMP($file);
    } else {
        return false;
    }
    $img_info = getImageSize($file);
    //원본이미지의 정보를 얻어옵니다
    $img_width = $img_info[0];
    $img_height = $img_info[1];
    $crt_width = $max_width;
    //생성되면 이미지 사이즈
    $crt_height = $max_height;
    //1.가로 세로 원본비율을 맞추고, 남은 영역에 색채워서 정해진 크기로 생성
    if ($sizeChg == 1) {
        if ($img_width / $max_width == $img_height / $max_height) {
            //원본과 썸네일의 가로세로비율이 같은경우
            $dst_x = 0;
            $dst_y = 0;
            $dst_width = $max_width;
            $dst_height = $max_height;
        } elseif ($img_width / $max_width < $img_height / $max_height) {
            //세로에 기준을 둔경우
            $dst_x = ($max_width - $img_width * ($max_height / $img_height)) / 2;
            $dst_y = 0;
            $dst_width = $max_height * ($img_width / $img_height);
            $dst_height = $max_height;
        } else {
            //가로에 기준을 둔경우
            $dst_x = 0;
            $dst_y = ($max_height - $img_height * ($max_width / $img_width)) / 2;
            $dst_width = $max_width;
            $dst_height = $max_width * ($img_height / $img_width);
        }
        //2.가로 세로 원본비율을 맞추고, 남은 영역없이 이미지만 컷 생성
    } else {
        if ($sizeChg == 2) {
            if ($img_width / $max_width == $img_height / $max_height) {
                //원본과 썸네일의 가로세로비율이 같은경우
                $dst_width = $max_width;
                $dst_height = $max_height;
            } elseif ($img_width / $max_width < $img_height / $max_height) {
                //세로에 기준을 둔경우
                $dst_width = $max_height * ($img_width / $img_height);
                $dst_height = $max_height;
            } else {
                //가로에 기준을 둔경우
                $dst_width = $max_width;
                $dst_height = $max_width * ($img_height / $img_width);
            }
            $dst_x = 0;
            $dst_y = 0;
            $crt_width = $dst_width;
            $crt_height = $dst_height;
            //3.가로 세로 원본비율을 맞추지 않고, 정해진 크기대로 생성
        } else {
            $dst_width = $max_width;
            $dst_height = $max_height;
            $dst_x = 0;
            $dst_y = 0;
        }
    }
    $dst_img = imagecreatetruecolor($crt_width, $crt_height);
    //타겟이미지를 생성합니다
    $white = imagecolorallocate($dst_img, 255, 255, 255);
    imagefill($dst_img, 0, 0, $white);
    ImageCopyResized($dst_img, $src_img, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $img_width, $img_height);
    //타겟이미지에 원하는 사이즈의 이미지를 저장합니다
    ImageInterlace($dst_img);
    switch ($img_info[2]) {
        case "1":
            ImageGIF($dst_img, $save_filename);
            break;
        case "2":
            ImageJPEG($dst_img, $save_filename);
            break;
        case "3":
            imagealphablending($dst_img, false);
            imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $img_width, $img_height);
            //(생성이미지,원소스이미지,시작점X,시작점Y,원본소스상 시작점X,원본소스상 시작점Y,생성이미지너비, 생성이미지높이,원이미지너비,원이미지높이)
            imagesavealpha($dst_img, true);
            ImagePNG($dst_img, $save_filename, 0);
            break;
        case "4":
            ImageWBMP($dst_img, $save_filename);
            break;
    }
    ImageDestroy($dst_img);
    ImageDestroy($src_img);
}
示例#25
0
 $image_data = fread($fd_in, $img_maxsize);
 if (!feof($fd_in)) {
     // buffer full ==> XML file too large!
     exit;
 }
 fclose($fd_in);
 $tmpfname = tempnam("/tmp", "hawxy");
 $fd_out = fopen($tmpfname, "wb");
 fwrite($fd_out, $image_data);
 fclose($fd_out);
 if (ereg(".gif\$", $remote_file) || ereg(".GIF\$", $remote_file)) {
     $im = @ImageCreateFromGIF($tmpfname);
 } elseif (ereg(".png\$", $remote_file) || ereg(".PNG\$", $remote_file)) {
     $im = @ImageCreateFromPNG($tmpfname);
 } elseif (ereg(".wbmp\$", $remote_file) || ereg(".WBMP\$", $remote_file)) {
     $im = @ImageCreateFromWBMP($tmpfname);
 }
 if (!$im) {
     unlink($tmpfname);
     // delete temporary file
     exit;
     // could not create image from file
 }
 if ($_SESSION['img_ml'] == HAW_HTML) {
     header("content-type: image/png");
     ImagePng($im);
 } else {
     header("content-type: image/vnd.wap.wbmp");
     ImageWBMP($im);
 }
 unlink($tmpfname);
 /**
  * Contructor method. Will create a new image from the target file.
  * Accepts an image filename as a string. Method also works out how
  * big the image is and stores this in the $image array.
  *
  * @param string $imgFile The image filename.
  */
 public function ImageManipulation($imgfile)
 {
     //detect image format
     $this->image["format"] = preg_replace("/.*\\.(.*)\$/", "\\1", $imgfile);
     //$this->image["format"] = preg_replace(".*\.(.*)$", "\\1", $imgfile);
     $this->image["format"] = strtoupper($this->image["format"]);
     // convert image into usable format.
     if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
         //JPEG
         $this->image["format"] = "JPEG";
         $this->image["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->image["format"] == "PNG") {
         //PNG
         $this->image["format"] = "PNG";
         $this->image["src"] = imagecreatefrompng($imgfile);
     } elseif ($this->image["format"] == "GIF") {
         //GIF
         $this->image["format"] = "GIF";
         $this->image["src"] = ImageCreateFromGif($imgfile);
     } elseif ($this->image["format"] == "WBMP") {
         //WBMP
         $this->image["format"] = "WBMP";
         $this->image["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         return false;
     }
     // Image is ok
     $this->imageok = true;
     // Work out image size
     $this->image["sizex"] = imagesx($this->image["src"]);
     $this->image["sizey"] = imagesy($this->image["src"]);
 }