Esempio n. 1
0
 function save($save)
 {
     /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
     $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"], $this->img["tinggi_thumb"]);
     @imagecopyresized($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         imageJPEG($this->img["des"], "{$save}", $this->img["quality"]);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         imagePNG($this->img["des"], "{$save}");
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         imageGIF($this->img["des"], "{$save}");
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         imageWBMP($this->img["des"], "{$save}");
     }
 }
 /**
  * Write the image after being processed
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __write(&$tmp)
 {
     // try to guess format from extension
     //
     if (!$tmp->save) {
         $p = pathinfo($tmp->target_filename);
         ($tmp->save = $this->__mime_metaphone[metaphone($p['extension'])]) || ($tmp->save = $this->__mime_soundex[soundex($p['extension'])]);
     }
     $result = false;
     switch ($tmp->save) {
         case 'image/gif':
             imageTrueColorToPalette($tmp->target, true, 256);
             $result = @imageGIF($tmp->target, $tmp->target_filename);
             break;
         case 'image/jpeg':
             $result = @imageJPEG($tmp->target, $tmp->target_filename, ASIDO_GD_JPEG_QUALITY);
             break;
         case 'image/wbmp':
             $result = @imageWBMP($tmp->target, $tmp->target_filename);
             break;
         default:
         case 'image/png':
             imageSaveAlpha($tmp->target, true);
             imageAlphaBlending($tmp->target, false);
             $result = @imagePNG($tmp->target, $tmp->target_filename);
             break;
     }
     @$this->__destroy_source($tmp);
     @$this->__destroy_target($tmp);
     return $result;
 }
 function generateImage($save = '', $show = true)
 {
     if ($this->img["format"] == "GIF" && !$this->gifsupport) {
         // --- kein caching -> gif ausgeben
         Header("Content-Type: image/" . $this->img["format"]);
         readfile($this->imgfile);
         exit;
     }
     $this->resampleImage();
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         imageJPEG($this->img["des"], $save, $this->img["quality"]);
     } elseif ($this->img["format"] == "PNG") {
         imagePNG($this->img["des"], $save);
     } elseif ($this->img["format"] == "GIF") {
         imageGIF($this->img["des"], $save);
     } elseif ($this->img["format"] == "WBMP") {
         imageWBMP($this->img["des"], $save);
     }
     if ($show) {
         Header("Content-Type: image/" . $this->img["format"]);
         readfile($save);
     }
 }
 function generateImage($file = '', $show = true)
 {
     global $REX;
     if ($this->img['format'] == 'GIF' && !$this->gifsupport) {
         // --- kein caching -> gif ausgeben
         $this->send();
     }
     $this->resampleImage();
     $this->applyFilters();
     $this->checkCacheFiles();
     if ($this->img['format'] == 'JPG' || $this->img['format'] == 'JPEG') {
         imageJPEG($this->img['des'], $file, $this->img['quality']);
     } elseif ($this->img['format'] == 'PNG') {
         imagePNG($this->img['des'], $file);
     } elseif ($this->img['format'] == 'GIF') {
         imageGIF($this->img['des'], $file);
     } elseif ($this->img['format'] == 'WBMP') {
         imageWBMP($this->img['des'], $file);
     }
     chmod($file, $REX['FILEPERM']);
     if ($show) {
         $this->send($file);
     }
 }
Esempio n. 5
0
 /**
  * Saves the image to a given filename, if no filename is given then a default is created.
  *
  * @param string $save The new image filename.
  */
 public function save($save = "")
 {
     //save thumb
     if (empty($save)) {
         $save = strtolower("./thumb." . $this->image["format"]);
     }
     $this->createResampledImage();
     if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
         //JPEG
         imageJPEG($this->image["des"], $save, $this->image["quality"]);
     } elseif ($this->image["format"] == "PNG") {
         //PNG
         imagePNG($this->image["des"], $save);
     } elseif ($this->image["format"] == "GIF") {
         //GIF
         imageGIF($this->image["des"], $save);
     } elseif ($this->image["format"] == "WBMP") {
         //WBMP
         imageWBMP($this->image["des"], $save);
     }
 }
 function generateImage($save = '', $show = true)
 {
     if ($this->img['format'] == 'GIF' && !$this->gifsupport) {
         // --- kein caching -> gif ausgeben
         $this->send();
     }
     $this->resampleImage();
     $this->applyFilters();
     if ($this->img['format'] == 'JPG' || $this->img['format'] == 'JPEG') {
         imageJPEG($this->img['des'], $save, $this->img['quality']);
     } elseif ($this->img['format'] == 'PNG') {
         imagePNG($this->img['des'], $save);
     } elseif ($this->img['format'] == 'GIF') {
         imageGIF($this->img['des'], $save);
     } elseif ($this->img['format'] == 'WBMP') {
         imageWBMP($this->img['des'], $save);
     }
     if ($show) {
         $this->send($save);
     }
 }
Esempio n. 7
0
 /**
  * The filename must have an extension and it must be one of the following: jpg, gif, png, jpeg, or bmp.
  * If a thumbnail already exists in the source files' directory, this function automatically appends an
  * incremental numeric suffix.
  *
  * If the output filename already exists on disk, this function will revert to auto-creating a thumbnail filename.
  *
  * @param string  $filename        The filename to process
  * @param string  $outputFilename  The name of the file to write to
  * @param string  $outputDirectory The name of the directory that holds our outputfile
  * @param integer $width           The width in pixels of the created thumbnail
  * @param integer $height          The height in pixels of the created thumbnail
  * @param boolean $max             If set to true then the image aspect ratio is preserved
  *                                   with the max length of either width or height being {@link $width} or {@link $height}
  * @param boolean $crop            If set to true, the image will be cropped to the dimensions specified.
  *                                 If set to false, the image will be resized.
  *
  * @return string the name of the file where the thumbnail can be found
  * @throws ThumbnailsException If any of the parameters are invalid.
  *
  * @see generateThumbnail(...)
  */
 protected function generateThumbnail($filename, $outputFilename, $outputDirectory, $width = 0, $height = 0, $max = false, $crop = false, $ext = null, $quality = null)
 {
     if (!is_file($filename)) {
         throw new ThumbnailsException("Source file does not exist '" . $filename . "'");
     }
     $path = pathinfo($filename);
     if (empty($path['extension'])) {
         throw new ThumbnailsException("Source file does not have an extension '" . $filename . "'");
     }
     $originalExt = strtolower(trim($path['extension']));
     if (empty($ext)) {
         $ext = $originalExt;
     }
     if (!in_array($ext, $this->supportedExtensions)) {
         throw new ThumbnailsException("Thumbnail file extension [{$ext}] is not supported");
     }
     if ($outputDirectory != null && !is_dir($outputDirectory)) {
         throw new ThumbnailsException("Output directory does not exist or is not a valid directory '{$outputDirectory}'");
     }
     //parameter validation
     if ($width === 0 && $height === 0) {
         throw new ThumbnailsException("Width and/or height must be specified");
     }
     if (!is_int($width)) {
         throw new ThumbnailsException("Width [{$width}] is not a valid integer");
     }
     if (!is_int($height)) {
         throw new ThumbnailsException("Height [{$height}] is not a valid integer");
     }
     if ($width < 0) {
         throw new ThumbnailsException("Width cannot be negative");
     }
     if ($height < 0) {
         throw new ThumbnailsException("Height cannot be negative");
     }
     if ($max === true && ($width === 0 || $height === 0)) {
         throw new ThumbnailsException("If max is true then width and height must be positive");
     }
     if ($crop === true && ($width === 0 || $height === 0 || $max === true)) {
         throw new ThumbnailsException("If crop is true then width and height must be positive and max must be false");
     }
     if ($outputDirectory == null) {
         $outputDirectory = $path['dirname'];
     } else {
         $outputDirectory = rtrim($outputDirectory, '/');
     }
     //check for existing thumbnail in same directory, increment filename
     $outfile = $outputFilename == null ? "{$path['filename']}{$this->autoNameSuffix}.{$ext}" : $outputFilename;
     $inc = 1;
     while (is_file("{$outputDirectory}/{$outfile}")) {
         $outfile = "{$path['filename']}{$this->autoNameSuffix}-{$inc}.{$ext}";
         $inc++;
     }
     //list($origwidth, $origheight) = getimagesize($filename);
     //build ImageMagick operation
     if ($this->convertMode == 'exec_imagick') {
         if ($max === true) {
             $op = "-resize {$width}x{$height}\\>";
         } else {
             if ($crop === true) {
                 if ($this->imageMagickCompatMode == false) {
                     // As of IM v6.3.8-3 the special resize option flag '^' was added
                     // to make cutting the image to fit easier.
                     $op = "-resize {$width}x{$height}\\>^ -gravity {$this->cropGravity} -crop {$width}x{$height}+0+0 +repage";
                 } else {
                     // Complex trickiness to perform the cut to fit resize
                     // Calculate the thumbnail aspect ratio.
                     // > 1 is a wide thumb
                     // < 1 is a tall thumb
                     // 1 is a square thumb
                     $thumb_aspect_ratio = $width / $height;
                     // Get the dimensions of the image
                     $dimensions = getimagesize($filename);
                     $image_aspect_ratio = $dimensions[0] / $dimensions[1];
                     // Definitions:
                     //  width-crop = Resize the image to the full width of the thumbnail and trim the top and bottom
                     //  height-crop = Resize the image to the full height of the thumbnail and trip the sides
                     // Behavior:
                     // If image_aspect_ratio < thumb_aspect_ratio perform a width-crop
                     // If image_aspect_ratio >= thumb_aspect_ratio perform a height-crop
                     if ($image_aspect_ratio < $thumb_aspect_ratio) {
                         $op = "-resize {$width}x\\> -gravity {$this->cropGravity} -crop {$width}x{$height}+0+0 +repage";
                     } else {
                         $op = "-resize x{$height}\\> -gravity {$this->cropGravity} -crop {$width}x{$height}+0+0 +repage";
                     }
                 }
             } else {
                 if ($height === 0) {
                     $op = "-resize {$width}x\\>";
                 } else {
                     if ($width === 0) {
                         $op = "-resize x{$height}\\>";
                     } else {
                         $op = "-resize {$width}x{$height}!\\>";
                     }
                 }
             }
         }
         $qualityArg = $quality ? '-quality ' . escapeshellarg($quality) : ($qualityArg = '');
         $outPath = escapeshellarg("{$outputDirectory}/{$outfile}");
         //full ImageMagick command; redirect STDERR to STDOUT
         $filename = escapeshellarg($filename);
         $cmd = "{$this->pathToImageMagickConvert} {$filename} {$op} {$qualityArg} {$outPath} 2>&1";
         $retval = 1;
         $output = array();
         $this->Logger->debug("Excecuting [{$cmd}]");
         exec($cmd, $output, $retval);
         if ($retval > 0) {
             throw new ThumbnailsException("Generation failed '" . $cmd . "\n" . implode("\n", $output) . "'");
         }
     } elseif ($this->convertMode == 'pecl_imagick') {
         $image = new Imagick($filename);
         if ($max == true) {
             $image->scaleImage($width, $height, true);
         } elseif ($crop === true) {
             // Because Imagick::cropThumbnailImage() doesn't support different gravities,
             // we need to expand the functionality out here. PITA!
             if ($this->cropGravity == 'center') {
                 $image->cropThumbnailImage($width, $height);
             } else {
                 // Resize full image by default so the smallest edge is
                 // the max width/height
                 if ($image->getImageWidth() > $image->getImageHeight()) {
                     $image->scaleImage(0, $height);
                 } else {
                     $image->scaleImage($width, 0);
                 }
                 // Then crop out the needed section.
                 $image_width = $image->getImageWidth();
                 $image_height = $image->getImageHeight();
                 switch (strtolower($this->cropGravity)) {
                     case 'northwest':
                         $x = $image_width - $width;
                         $y = 0;
                         break;
                     case 'north':
                         $x = $image_width / 2 - $width / 2;
                         $y = 0;
                         break;
                     case 'northeast':
                         $x = 0;
                         $y = 0;
                         break;
                     case 'west':
                         $x = 0;
                         $y = $image_height / 2 - $height / 2;
                         break;
                     case 'east':
                         $x = $image_width - $width;
                         $y = $image_height / 2 - $height / 2;
                         break;
                     case 'southwest':
                         $x = 0;
                         $y = $image_height - $height;
                         break;
                     case 'south':
                         $x = $image_width / 2 - $width / 2;
                         $y = $image_height - $height;
                         break;
                     case 'southeast':
                         $x = $image_width - $width;
                         $y = $image_height - $height;
                         break;
                     default:
                         throw new ThumbnailsException("Unsupported crop gravity: {$this->cropGravity}");
                 }
                 $x = floor($x);
                 $y = floor($y);
                 $image->cropImage($width, $height, $x, $y);
             }
         } elseif ($height === 0) {
             $image->scaleImage($width, $height);
         } elseif ($width === 0) {
             $image->scaleImage($width, $height);
         } else {
             $image->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1);
         }
         if ($quality) {
             $image->setImageCompressionQuality($quality);
         }
         // Imagick will infer the file format from the filename extension
         $image->writeImage("{$outputDirectory}/{$outfile}");
         $image->clear();
         $image->destroy();
     } elseif ($this->convertMode == 'gd') {
         $origImage = null;
         switch ($originalExt) {
             case 'jpg':
             case 'jpeg':
                 $origImage = imagecreatefromJPEG($filename);
                 break;
             case 'gif':
                 $origImage = imagecreatefromGIF($filename);
                 break;
             case 'png':
                 $origImage = imagecreatefromPNG($filename);
                 break;
             case 'bmp':
                 $origImage = imagecreatefromWBMP($filename);
                 break;
             default:
                 throw new ThumbnailsException('GD does not know how to handle .' . $originalExt . ' files.');
         }
         if (function_exists('imageantialias')) {
             imageantialias($origImage, true);
         }
         $image_attr = getimagesize($filename);
         $image_width = $image_attr[0];
         $image_height = $image_attr[1];
         $dst_x = 0;
         $dst_y = 0;
         $src_x = null;
         $src_y = null;
         $dst_w = null;
         $dst_h = null;
         $src_w = null;
         $src_h = null;
         if ($max === true) {
             // resize to dimensions, preserving aspect ratio
             $src_x = 0;
             $src_y = 0;
             $src_w = $image_width;
             $src_h = $image_height;
             if ($image_width > $image_height) {
                 $dst_w = $width;
                 $dst_h = (int) floor($image_height * ($width / $image_width));
             } else {
                 $dst_h = $height;
                 $dst_w = (int) floor($image_width * ($height / $image_height));
             }
         } else {
             if ($crop === true) {
                 // crop the image with cropGravity
                 $dst_w = $width;
                 $dst_h = $height;
                 // By default, resize the whole image
                 $src_w = $image_attr[0];
                 $src_h = $image_attr[1];
                 $thumb_aspect_ratio = $width / $height;
                 $image_aspect_ratio = $image_attr[0] / $image_attr[1];
                 if ($image_aspect_ratio < $thumb_aspect_ratio) {
                     // width-crop
                     $src_w = $image_attr[0];
                     // original-width
                     $resize_ratio = $image_attr[0] / $width;
                     // original-width / thumbnail-width
                     $src_h = floor($height * $resize_ratio);
                     // thumbnail-height * original-width / thumbnail-width
                 } else {
                     // height-crop
                     $src_h = $image_attr[1];
                     // original-height
                     $resize_ratio = $image_attr[1] / $height;
                     // original-height / thumbnail-height
                     $src_w = floor($width * $resize_ratio);
                     // thumbnail-width * original-height / thumbnail-height
                 }
                 $dst_x = 0;
                 $dst_y = 0;
                 $dst_w = $width;
                 $dst_h = $height;
                 switch (strtolower($this->cropGravity)) {
                     case 'center':
                         $src_x = floor(($image_attr[0] - $src_w) / 2);
                         $src_y = floor(($image_attr[1] - $src_h) / 2);
                         break;
                     case 'northeast':
                         $src_x = 0;
                         $src_y = 0;
                         break;
                     case 'north':
                         $src_x = floor(($image_attr[0] - $src_w) / 2);
                         $src_y = 0;
                         break;
                     case 'south':
                         $src_x = floor($image_attr[0] - $image_width);
                         $src_y = floor($image_attr[1] - $image_height);
                         break;
                     default:
                         throw new ThumbnailsException("Unsupported cropGravity for GD: {$this->cropGravity}");
                 }
             } else {
                 if ($height === 0) {
                     // resize to max width, preserving aspect ratio
                     $src_x = 0;
                     $src_y = 0;
                     $src_w = $image_width;
                     $src_h = $image_height;
                     $dst_w = $width;
                     $dst_h = $image_height * ($width / $image_width);
                 } else {
                     if ($width === 0) {
                         // resize to max height, preserving aspect ratio
                         $src_x = 0;
                         $src_y = 0;
                         $src_w = $image_width;
                         $src_h = $image_height;
                         $dst_h = $height;
                         $dst_w = $image_width * ($height / $image_height);
                     } else {
                         // resize, ignoring aspect ratio
                         $src_x = 0;
                         $src_y = 0;
                         $src_w = $image_width;
                         $src_h = $image_height;
                         $dst_w = $width;
                         $dst_h = $height;
                     }
                 }
             }
         }
         $newImage = imagecreateTrueColor($dst_w, $dst_h);
         //preserve transparency
         $transindex = -1;
         if ($ext == 'gif') {
             imagealphablending($newImage, false);
             $transindex = imagecolortransparent($origImage);
             if ($transindex >= 0) {
                 $transcol = imagecolorsforindex($origImage, $transindex);
                 $transindex = imagecolorallocatealpha($newImage, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
                 imagefill($newImage, 0, 0, $transindex);
             }
         }
         @imagecopyResampled($newImage, $origImage, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
         //preserve transparency
         if ($ext == 'gif') {
             if ($transindex >= 0) {
                 imagecolortransparent($newImage, $transindex);
                 for ($y = 0; $y < $dst_h; ++$y) {
                     for ($x = 0; $x < $dst_w; ++$x) {
                         if ((imagecolorat($newImage, $x, $y) >> 24 & 0x7f) >= 100) {
                             imagesetpixel($newImage, $x, $y, $transindex);
                         }
                     }
                 }
                 imagetruecolortopalette($newImage, true, 255);
                 imagesavealpha($newImage, false);
             }
         }
         // echo "<pre>"; var_dump($dst_h); die("</pre>");
         $outfilepath = "{$outputDirectory}/{$outfile}";
         switch ($ext) {
             case 'jpg':
             case 'jpeg':
                 imageJPEG($newImage, $outfilepath, $quality);
                 break;
             case 'gif':
                 imageGIF($newImage, $outfilepath);
                 break;
             case 'png':
                 imagePNG($newImage, $outfilepath, $quality);
                 break;
             case 'bmp':
                 imageWBMP($newImage, $outfilepath);
                 break;
         }
         imagedestroy($newImage);
         imagedestroy($origImage);
     }
     return $outfile;
 }
 function convertImage($type)
 {
     /* check the converted image type availability,
        if it is not available, it will be casted to jpeg :) */
     $validtype = $this->validateType($type);
     if ($this->output) {
         /* show the image  */
         switch ($validtype) {
             case 'jpeg':
             case 'jpg':
                 header("Content-type: image/jpeg");
                 if ($this->imtype == 'gif' or $this->imtype == 'png') {
                     $image = $this->replaceTransparentWhite($this->im);
                     imageJPEG($image);
                 } else {
                     imageJPEG($this->im);
                 }
                 break;
             case 'gif':
                 header("Content-type: image/gif");
                 imageGIF($this->im);
                 break;
             case 'png':
                 header("Content-type: image/png");
                 imagePNG($this->im);
                 break;
             case 'wbmp':
                 header("Content-type: image/vnd.wap.wbmp");
                 imageWBMP($this->im);
                 break;
             case 'swf':
                 header("Content-type: application/x-shockwave-flash");
                 $this->imageSWF($this->im);
                 break;
         }
         // Memory cleanup
         @imagedestroy($this->im);
     } else {
         /* save the image  */
         switch ($validtype) {
             case 'jpeg':
             case 'jpg':
                 if ($this->imtype == 'gif' or $this->imtype == 'png') {
                     /* replace transparent with white */
                     $image = $this->replaceTransparentWhite($this->im);
                     imageJPEG($image, $this->finalFilePath . $this->imname . ".jpg");
                 } else {
                     imageJPEG($this->im, $this->finalFilePath . $this->imname . ".jpg");
                 }
                 break;
             case 'gif':
                 imageGIF($this->im, $this->finalFilePath . $this->imname . ".gif");
                 break;
             case 'png':
                 imagePNG($this->im, $this->finalFilePath . $this->imname . ".png");
                 break;
             case 'wbmp':
                 imageWBMP($this->im, $this->finalFilePath . $this->imname . ".wbmp");
                 break;
             case 'swf':
                 $this->imageSWF($this->im, $this->finalFilePath . $this->imname . ".swf");
                 break;
         }
         // Memory cleanup
         @imagedestroy($this->im);
     }
 }
 /**
  * Write the image after being processed
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __write(&$tmp)
 {
     // try to guess format from extension
     //
     if (!$tmp->save) {
         $p = pathinfo($tmp->target_filename);
         ($tmp->save = $this->__mime_metaphone[metaphone($p['extension'])]) || ($tmp->save = $this->__mime_soundex[soundex($p['extension'])]);
     }
     $result = false;
     switch ($tmp->save) {
         case 'image/gif':
             imageTrueColorToPalette($tmp->target, true, 256);
             ob_start();
             imageGIF($tmp->target);
             $contents = ob_get_contents();
             ob_end_clean();
             break;
         case 'image/jpeg':
             ob_start();
             imageJPEG($tmp->target, null, ASIDO_GD_JPEG_QUALITY);
             $contents = ob_get_contents();
             ob_end_clean();
             break;
         case 'image/wbmp':
             ob_start();
             imageWBMP($tmp->target);
             $contents = ob_get_contents();
             ob_end_clean();
             break;
         default:
         case 'image/png':
             imageSaveAlpha($tmp->target, true);
             imageAlphaBlending($tmp->target, false);
             ob_start();
             imagePNG($tmp->target);
             $contents = ob_get_contents();
             ob_end_clean();
             break;
     }
     // This needs to go through Joomla as suexec might be present
     jimport('joomla.filesystem');
     $result = JFile::write($tmp->target_filename, $contents);
     $this->__destroy_source($tmp);
     $this->__destroy_target($tmp);
     return $result;
 }
Esempio n. 10
0
 protected function typeCloseImage($pointer, $resource, $filename)
 {
     $mime = $this->mime[$pointer];
     $quality = $this->re_quality[$pointer];
     if (imagetypes() & $mime) {
         switch ($mime) {
             case 2:
                 return imageJPEG($resource, $filename, $quality);
                 break;
             case 15:
                 return imageWBMP($resource, $filename, $quality);
                 break;
             case 1:
                 return imageGIF($resource, $filename, $quality);
                 break;
             case 3:
                 return imagePNG($resource, $filename, $quality);
                 break;
         }
     } else {
         return false;
     }
 }
 /**
  * Сохраняет изображение в файл
  * @param $FileName
  * @param null $SaveFormat
  */
 public function SaveToFile($FileName, $SaveFormat = null)
 {
     if ($SaveFormat !== null) {
         $this->SetSaveFormat($SaveFormat);
     }
     $this->SetSize();
     if ($this->SaveFormat == 'jpeg') {
         imageJPEG($this->gd, $FileName, $this->JpegQuality);
     } elseif ($this->SaveFormat == 'png') {
         imagePNG($this->gd, $FileName);
     } elseif ($this->SaveFormat == 'gif') {
         imageGIF($this->gd, $FileName);
     } elseif ($this->SaveFormat == 'wbmp') {
         imageWBMP($this->gd, $FileName);
     }
 }
Esempio n. 12
0
 private function move()
 {
     if (!isset($this->error)) {
         switch ($this->type) {
             case 1:
                 return imageGIF($this->new_photo, $this->new_name);
                 break;
             case 3:
                 return imagePNG($this->new_photo, $this->new_name);
                 break;
             case 6:
             case 15:
                 return imageWBMP($this->new_photo, $this->new_name);
                 break;
             default:
                 return imageJPEG($this->new_photo, $this->new_name, $this->quality);
         }
     }
 }
Esempio n. 13
0
 function putInColorBox_and_save($fileresult, $resultWidth, $resultHeight, $bgColorRed = 0xff, $bgColorGreen = 0xff, $bgColorBlue = 0xff)
 {
     // get size
     $res = getImageSize($this->sSourcePath2file);
     $width = $res[0];
     $height = $res[1];
     // open image
     $img_src = $this->img["src"];
     // make new size
     $newimg_width = $resultWidth;
     $newimg_height = $newimg_width / $width * $height;
     if ($newimg_height > $resultHeight) {
         $newimg_height = $resultHeight;
         $newimg_width = $newimg_height / $height * $width;
     }
     // create img with specific size resultWidth x resultHeight
     $im_new = ImageCreateTrueColor($resultWidth, $resultHeight);
     // set BG
     $color = ImageColorAllocate($im_new, $bgColorRed, $bgColorGreen, $bgColorBlue);
     $res = ImageFilledRectangle($im_new, 0, 0, $resultWidth, $resultHeight, $color);
     // detact offset
     $dX = $resultWidth - $newimg_width;
     $dY = $resultHeight - $newimg_height;
     $dX /= 2;
     $dY /= 2;
     //put image to new image
     ImageCopyResampled($im_new, $img_src, $dX, $dY, 0, 0, $newimg_width, $newimg_height, $width, $height);
     switch ($this->img['format']) {
         case IMAGETYPE_GIF:
             imageGIF($im_new, $fileresult);
             break;
         case IMAGETYPE_JPEG:
             imageJPEG($im_new, $fileresult, $this->img["quality"]);
             break;
         case IMAGETYPE_PNG:
             imagePNG($im_new, $fileresult);
             break;
         case IMAGETYPE_WBMP:
             imageWBMP($im_new, $fileresult);
             break;
     }
 }
Esempio n. 14
0
 /**
  * Инициализация водяного знака. Если $sWatermark - не файл, то печатается введенный там текст  
  * 
  * @param mixed $sWatermark водяной знак
  * @param mixed $hPosition позиция по горизонтали
  * @param mixed $vPosition позиция по вертикали
  * @param mixed $xPadding отступ от края по oX 
  * @param mixed $yPadding отступ от края по oY 
  * @param mixed $bMakeSourceWatermark флаг, ставить ли знак на оригинале изображения
  */
 private function init_watermark($sWatermark, $hPosition = 'right', $vPosition = 'bottom', $xPadding = 15, $yPadding = 15, $bMakeSourceWatermark = true)
 {
     if (!$this->oImg['watermark_resizeable']) {
         $this->oImg['coef_width'] = 1;
         $this->oImg['coef_height'] = 1;
     }
     if (file_exists($sWatermark)) {
         if ($this->checkIsImage($sWatermark)) {
             //если watermark с таким путем не кэширован, то создается, иначе - берется из кэша
             if (!isset($this->aWatermarkSources[$sWatermark])) {
                 $size = getimagesize($sWatermark);
                 $this->aWatermarkSources[$sWatermark]['width'] = $size[0];
                 $this->aWatermarkSources[$sWatermark]['height'] = $size[1];
                 switch ($size[2]) {
                     case IMAGETYPE_GIF:
                         $this->aWatermarkSources[$sWatermark]['src'] = imageCreateFromGIF($sWatermark);
                         break;
                     case IMAGETYPE_JPEG:
                         $this->aWatermarkSources[$sWatermark]['src'] = imageCreateFromJPEG($sWatermark);
                         break;
                     case IMAGETYPE_PNG:
                         $this->aWatermarkSources[$sWatermark]['src'] = imageCreateFromPNG($sWatermark);
                         break;
                     case IMAGETYPE_WBMP:
                         $this->aWatermarkSources[$sWatermark]['src'] = imageCreateFromWBMP($sWatermark);
                         break;
                     default:
                         return;
                 }
             }
             // определяем нужные размеры wm исходя из коэффициентов
             if ($this->oImg['watermark_resizeable']) {
                 $nCoef = $this->oImg['coef_width'] > $this->oImg['coef_height'] ? $this->oImg['coef_height'] : $this->oImg['coef_width'];
                 $dst_width = intval($this->aWatermarkSources[$sWatermark]['width'] * $nCoef);
                 $dst_height = intval($this->aWatermarkSources[$sWatermark]['height'] * $nCoef);
             } else {
                 $dst_width = $this->aWatermarkSources[$sWatermark]['width'];
                 $dst_height = $this->aWatermarkSources[$sWatermark]['height'];
             }
             $this->oImg['wm'] = imagecreatetruecolor($dst_width, $dst_height);
             ImageAlphaBlending($this->oImg['wm'], false);
             ImageSaveAlpha($this->oImg['wm'], true);
             imagecopyresized($this->oImg['wm'], $this->aWatermarkSources[$sWatermark]['src'], 0, 0, 0, 0, $dst_width, $dst_height, $this->aWatermarkSources[$sWatermark]['width'], $this->aWatermarkSources[$sWatermark]['height']);
             $this->oImg['wm_width'] = $dst_width;
             $this->oImg['wm_height'] = $dst_height;
             $this->oImg['watermark_pos_x'] = $hPosition;
             $this->oImg['watermark_pos_y'] = $vPosition;
             $this->oImg['watermark_padding_h'] = intval($xPadding * $this->oImg['coef_width']);
             $this->oImg['watermark_padding_v'] = intval($yPadding * $this->oImg['coef_height']);
         } else {
             unset($this->oImg['wm']);
             $this->errors->set('watermark_src_isnt_image');
         }
     } else {
         $nCoef = $this->oImg['coef_width'] > $this->oImg['coef_height'] ? $this->oImg['coef_height'] : $this->oImg['coef_width'];
         $nFontSize = round($this->oImg['watermark_font_size'] * $nCoef);
         $nFontSize = round($nFontSize / 1.333);
         //определение координат нужного прямоугольника под WM
         $aImageDimmention = imagettfbbox($nFontSize, 0, $this->sFontDir . $this->oImg['watermark_font'], $sWatermark);
         //ширина (разница по oX между нижними левым и правым углом прямоугольника)
         $nImgWidth = $aImageDimmention[4] - $aImageDimmention[6];
         //высота (разница по oY между левыми верхним и нижним углом прямоугольника)
         $nImgHeight = $aImageDimmention[1] - $aImageDimmention[7];
         if (!$nImgHeight) {
             $this->errors->set('no_language_support');
             $this->oImg['wm'] = false;
         }
         if ($this->errors->no()) {
             $nImgHeight *= 1.6;
             //небольшое увеличение высоты чтобы поместились выступающие края букв
             $this->oImg['wm'] = ImageCreateTrueColor($nImgWidth, $nImgHeight);
             if ($this->oImg['type'] == IMAGETYPE_GIF) {
                 //Определяем индекс прозрачного цвета у gif
                 $colorcount = imagecolorstotal($this->oImg['src']);
                 imagetruecolortopalette($this->oImg['wm'], true, $colorcount);
                 imagepalettecopy($this->oImg['wm'], $this->oImg['wm']);
                 $trans = imagecolortransparent($this->oImg['wm']);
                 imagefill($this->oImg['wm'], 0, 0, $trans);
                 imagecolortransparent($this->oImg['wm'], $trans);
                 $textcolor = imagecolorallocate($this->oImg['wm'], (int) ($this->oImg['watermark_font_color'] % 0x1000000 / 0x10000), (int) ($this->oImg['watermark_font_color'] % 0x10000 / 0x100), $this->oImg['watermark_font_color'] % 0x100);
             } else {
                 //Определяем индекс прозрачного цвета у png
                 $opacity = imagecolorallocatealpha($this->oImg['wm'], 255, 255, 255, 127);
                 imagefill($this->oImg['wm'], 0, 0, $opacity);
                 ImageAlphaBlending($this->oImg['wm'], false);
                 ImageSaveAlpha($this->oImg['wm'], true);
                 $textcolor = imagecolorallocatealpha($this->oImg['wm'], (int) ($this->oImg['watermark_font_color'] % 0x1000000 / 0x10000), (int) ($this->oImg['watermark_font_color'] % 0x10000 / 0x100), $this->oImg['watermark_font_color'] % 0x100, 0);
             }
             // Наносим текст
             imagettftext($this->oImg['wm'], $nFontSize, 0, 0, intval($nImgHeight * 0.8), $textcolor, $this->sFontDir . $this->oImg['watermark_font'], $sWatermark);
             $this->oImg['wm_width'] = $nImgWidth;
             $this->oImg['wm_height'] = $nImgHeight;
             $this->oImg['watermark_pos_x'] = $hPosition;
             $this->oImg['watermark_pos_y'] = $vPosition;
             $this->oImg['watermark_padding_h'] = intval($xPadding * $this->oImg['coef_width']);
             $this->oImg['watermark_padding_v'] = intval($yPadding * $this->oImg['coef_height']);
         }
     }
     // нанесение wm на оригинал
     if ($bMakeSourceWatermark) {
         $this->oImg['only_src'] = imageCreateTrueColor($this->oImg['orig_width'], $this->oImg['orig_height']);
         ImageCopy($this->oImg['only_src'], $this->oImg['src'], 0, 0, 0, 0, $this->oImg['orig_width'], $this->oImg['orig_height']);
         $this->make_watermark($this->oImg['only_src'], intval($this->oImg['orig_width']), intval($this->oImg['orig_height']));
         switch ($this->oImg['format']) {
             case IMAGETYPE_GIF:
                 imageGIF($this->oImg['only_src'], $this->oImg['orig_filename']);
                 break;
             case IMAGETYPE_JPEG:
                 imageJPEG($this->oImg['only_src'], $this->{$this}->oImg['orig_filename'], $this->oImg['quality']);
                 break;
             case IMAGETYPE_PNG:
                 imagePNG($this->oImg['only_src'], $this->{$this}->oImg['orig_filename']);
                 break;
             case IMAGETYPE_WBMP:
                 imageWBMP($this->oImg['only_src'], $this->{$this}->oImg['orig_filename']);
                 break;
         }
         imageDestroy($this->oImg['only_src']);
     }
 }
 function convertImage($type)
 {
     /* check the converted image type availability,
        if it is not available, it will be casted to jpeg :) */
     $validtype = $this->validateType($type);
     if ($this->output) {
         /* show the image  */
         switch ($validtype) {
             case 'jpeg':
                 // Added jpe
             // Added jpe
             case 'jpe':
             case 'jpg':
                 header("Content-type: image/jpeg");
                 if ($this->imtype == 'gif' or $this->imtype == 'png') {
                     $image = $this->replaceTransparentWhite($this->im);
                     @imageJPEG($image);
                 } else {
                     @imageJPEG($this->im);
                 }
                 break;
             case 'gif':
                 header("Content-type: image/gif");
                 @imageGIF($this->im);
                 break;
             case 'png':
                 header("Content-type: image/png");
                 @imagePNG($this->im);
                 break;
             case 'wbmp':
                 header("Content-type: image/vnd.wap.wbmp");
                 @imageWBMP($this->im);
                 break;
             case 'swf':
                 header("Content-type: application/x-shockwave-flash");
                 $this->imageSWF($this->im);
                 break;
         }
     } else {
         // Added Support vor different directory
         if (DEFINED('V_TEMP_DIR')) {
             $this->newimname = V_TEMP_DIR . $this->imname . '.' . $validtype;
         } else {
             $this->newimname = $this->imname . '.' . $validtype;
         }
         /* save the image  */
         switch ($validtype) {
             case 'jpeg':
                 // Added jpe
             // Added jpe
             case 'jpe':
             case 'jpg':
                 if ($this->imtype == 'gif' or $this->imtype == 'png') {
                     /* replace transparent with white */
                     $image = $this->replaceTransparentWhite($this->im);
                     @imageJPEG($image, $this->newimname);
                 } else {
                     @imageJPEG($this->im, $this->newimname);
                 }
                 break;
             case 'gif':
                 @imageGIF($this->im, $this->newimname);
                 break;
             case 'png':
                 @imagePNG($this->im, $this->newimname);
                 break;
             case 'wbmp':
                 @imageWBMP($this->im, $this->newimname);
                 break;
             case 'swf':
                 $this->imageSWF($this->im, $this->newimname);
                 break;
         }
     }
 }
 /**
  * Saves the image to a given filename, if no filename is given then a default is created.
  *
  * @param string $save The new image filename.
  */
 public function save($save = "")
 {
     //save thumb
     if (empty($save)) {
         $save = strtolower("./thumb." . $this->image["outputformat"]);
     } else {
         $this->image["outputformat"] = preg_replace("/.*\\.(.*)\$/", "\\1", $save);
         //$this->image["outputformat"] = preg_replace(".*\.(.*)$", "\\1", $save);
         $this->image["outputformat"] = strtoupper($this->image["outputformat"]);
     }
     $this->createResampledImage();
     if ($this->image["outputformat"] == "JPG" || $this->image["outputformat"] == "JPEG") {
         //JPEG
         imageJPEG($this->image["des"], $save, $this->image["quality"]);
     } elseif ($this->image["outputformat"] == "PNG") {
         //PNG
         imagePNG($this->image["des"], $save, 0);
     } elseif ($this->image["outputformat"] == "GIF") {
         //GIF
         imageGIF($this->image["des"], $save);
     } elseif ($this->image["outputformat"] == "WBMP") {
         //WBMP
         imageWBMP($this->image["des"], $save);
     }
 }
 /**
  * Saves the image to a given filename, if no filename is given then a default is created.
  *
  * @param string $save The new image filename.
  */
 public function save($file = null, $show = false)
 {
     // debugDie(print_r($this,true));
     if (isset($file) && empty($file)) {
         $file = null;
     }
     $showsave = $show && isset($file);
     if (isset($this->image['format_out'])) {
         $format = $this->image["format_out"];
     } else {
         // get type from save filename or filein
         $format = $this->getFileImageType($file);
         if ($format == '') {
             $format = $this->image["format"];
         }
         $this->image["format_out"] = $format;
     }
     if ($show) {
         // if showing output headers
         header("Content-Type: image/" . $format);
     } else {
         if (empty($file)) {
             $this->image['success'] = false;
             return false;
         }
     }
     $this->image['outfile'] = $file;
     $success = false;
     $this->createResampledImage();
     // If $file is null these will output images instead of saving them
     if ($format == "GIF") {
         // GIF
         // gif might not supported in certain versions of GD
         if (function_exists('imageGIF')) {
             $success = imageGIF($this->image["des"], $file);
         } else {
             $success = false;
             debugLog(__FUNCTION__ . 'unsupported output format: ' . $format);
             $this->image['success'] = $success;
             return $success;
         }
     } elseif ($format == "JPG" || $format == "JPEG") {
         // JPEG
         $success = imageJPEG($this->image["des"], $file, $this->image["quality"]);
     } elseif ($format == "PNG") {
         // PNG
         $success = imagePNG($this->image["des"], $file, $this->image["pngquality"]);
     } elseif ($format == "WBMP") {
         // WBMP
         $success = imageWBMP($this->image["des"], $file);
     } else {
         $success = false;
         debugLog(__FUNCTION__ . 'invalid output format');
         $this->image['success'] = $success;
         return $success;
     }
     $this->image['success'] = $success;
     // if saved and we also want to show, readfile
     if ($showsave) {
         readfile($this->image['outfile']);
     }
     return $success;
 }
Esempio n. 18
0
 /**
  * Write the image after being processed
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __write(&$tmp)
 {
     // try to guess format from extension
     //
     if (!$tmp->save) {
         $p = pathinfo($tmp->target_filename);
         ($tmp->save = $this->__mime_metaphone[metaphone($p['extension'])]) || ($tmp->save = $this->__mime_soundex[soundex($p['extension'])]);
     }
     $result = false;
     $imgContent = null;
     switch ($tmp->save) {
         case 'image/gif':
             imageTrueColorToPalette($tmp->target, true, 256);
             ob_start();
             $result = @imageGIF($tmp->target);
             $imgContent = ob_get_clean();
             break;
         case 'image/jpeg':
             ob_start();
             $result = @imageJPEG($tmp->target, null, ASIDO_GD_JPEG_QUALITY);
             $imgContent = ob_get_clean();
             break;
         case 'image/wbmp':
             ob_start();
             $result = @imageWBMP($tmp->target);
             $imgContent = ob_get_clean();
             break;
         default:
         case 'image/png':
             imageSaveAlpha($tmp->target, true);
             imageAlphaBlending($tmp->target, false);
             ob_start();
             $result = @imagePNG($tmp->target, null, ASIDO_GD_PNG_QUALITY);
             $imgContent = ob_get_clean();
             break;
     }
     if ($result) {
         jimport('joomla.filesystem.file');
         JFile::write($tmp->target_filename, $imgContent);
     }
     @$this->__destroy_source($tmp);
     @$this->__destroy_target($tmp);
     return $result;
 }
 function _sendImage()
 {
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         imageJPEG($this->img["des"], "", $this->img["quality"]);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         imagePNG($this->img["des"]);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         // support ist nur mit den neusten GD-LIBS möglich
         if (function_exists("imagegif")) {
             imageGIF($this->img["des"]);
         } else {
             imageJPEG($this->img["des"]);
         }
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         imageWBMP($this->img["des"]);
     }
 }