コード例 #1
1
ファイル: testgd2.php プロジェクト: ZSShang/mylearn
function waterMark($fileInHD, $wmFile, $transparency = 50, $jpegQuality = 90, $margin = 5)
{
    $wmImg = imageCreateFromJPEG($wmFile);
    $jpegImg = imageCreateFromJPEG($fileInHD);
    // Water mark random position
    $wmX = (bool) rand(0, 1) ? $margin : imageSX($jpegImg) - imageSX($wmImg) - $margin;
    $wmY = (bool) rand(0, 1) ? $margin : imageSY($jpegImg) - imageSY($wmImg) - $margin;
    // Water mark process
    imageCopyMerge($jpegImg, $wmImg, $wmX, $wmY, 0, 0, imageSX($wmImg), imageSY($wmImg), $transparency);
    // Overwriting image
    ImageJPEG($jpegImg, $fileInHD, $jpegQuality);
}
コード例 #2
0
ファイル: Thumbs.php プロジェクト: amorimlima/Hospital
function gerar_tumbs_real($t_x, $t_y, $qualidade, $c_original, $c_final)
{
    $thumbnail = imagecreatetruecolor($t_x, $t_y);
    $original = $c_original;
    $igInfo = getImageSize($c_original);
    switch ($igInfo['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                $originalimage = imageCreateFromGIF($original);
            } else {
                $ermsg = MSG_GIF_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $originalimage = imageCreateFromJPEG($original);
            } else {
                $ermsg = MSG_JPG_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $originalimage = imageCreateFromPNG($original);
            } else {
                $ermsg = MSG_PNG_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $originalimage = imageCreateFromWBMP($original);
            } else {
                $ermsg = MSG_WBMP_NOT_COMPATIBLE . '<br />';
            }
            break;
        default:
            $ermsg = $igInfo['mime'] . MSG_FORMAT_NOT_COMPATIBLE . '<br />';
            break;
    }
    $nLargura = $igInfo[0];
    $nAltura = $igInfo[1];
    if ($nLargura > $t_x and $nAltura > $t_y) {
        if ($t_x <= $t_y) {
            $nLargura = (int) ($igInfo[0] * $t_y / $igInfo[1]);
            $nAltura = $t_y;
        } else {
            $nLargura = $t_x;
            $nAltura = (int) ($igInfo[1] * $t_x / $igInfo[0]);
            if ($nAltura < $t_y) {
                $nLargura = (int) ($igInfo[0] * $t_y / $igInfo[1]);
                $nAltura = $t_y;
            }
        }
    }
    $x_pos = $t_x / 2 - $nLargura / 2;
    $y_pos = $t_y / 2 - $nAltura / 2;
    imagecopyresampled($thumbnail, $originalimage, $x_pos, $y_pos, 0, 0, $nLargura, $nAltura, $igInfo[0], $igInfo[1]);
    imagejpeg($thumbnail, $c_final, $qualidade);
    imagedestroy($thumbnail);
    return 'ok';
}
コード例 #3
0
ファイル: image.php プロジェクト: Norvares/nemex
 public function __construct($path)
 {
     list($this->width, $this->height, $this->type) = @getImageSize($path);
     if ($this->type == IMAGETYPE_JPEG) {
         $this->image = imageCreateFromJPEG($path);
         $this->extension = 'jpg';
         if (function_exists('exif_read_data')) {
             $this->exif = exif_read_data($path);
         }
         $this->rotateToExifOrientation();
     } else {
         if ($this->type == IMAGETYPE_PNG) {
             $this->image = imageCreateFromPNG($path);
             $this->extension = 'png';
         } else {
             if ($this->type == IMAGETYPE_GIF) {
                 $this->image = imageCreateFromGIF($path);
                 $this->extension = 'gif';
             }
         }
     }
     if ($this->image) {
         $this->valid = true;
     }
 }
 private function _getImageResource($image_file, $save = FALSE)
 {
     $image_info = getImageSize($image_file);
     if ($save) {
         $this->_image_mime = $image_info['mime'];
     }
     switch ($image_info['mime']) {
         case 'image/gif':
             if ($save) {
                 $this->_image_type = 'gif';
             }
             $img_rs = imageCreateFromGIF($image_file);
             break;
         case 'image/jpeg':
             if ($save) {
                 $this->_image_type = 'jpeg';
             }
             $img_rs = imageCreateFromJPEG($image_file);
             break;
         case 'image/png':
             if ($save) {
                 $this->_image_type = 'png';
             }
             $img_rs = imageCreateFromPNG($image_file);
             imageAlphaBlending($img_rs, TRUE);
             imageSaveAlpha($img_rs, TRUE);
             break;
     }
     return $img_rs;
 }
コード例 #5
0
 /**
  * Initialize a layer from a given image path
  * 
  * From an upload form, you can give the "tmp_name" path
  * 
  * @param string $path
  * 
  * @return ImageWorkshopLayer
  */
 public static function initFromPath($path)
 {
     if (file_exists($path) && !is_dir($path)) {
         if (!is_readable($path)) {
             throw new ImageWorkshopException('Can\'t open the file at "' . $path . '" : file is not writable, did you check permissions (755 / 777) ?', static::ERROR_NOT_WRITABLE_FILE);
         }
         $imageSizeInfos = @getImageSize($path);
         $mimeContentType = explode('/', $imageSizeInfos['mime']);
         if (!$mimeContentType || !array_key_exists(1, $mimeContentType)) {
             throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
         }
         $mimeContentType = $mimeContentType[1];
         switch ($mimeContentType) {
             case 'jpeg':
                 $image = imageCreateFromJPEG($path);
                 break;
             case 'gif':
                 $image = imageCreateFromGIF($path);
                 break;
             case 'png':
                 $image = imageCreateFromPNG($path);
                 break;
             default:
                 throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
                 break;
         }
         return new ImageWorkshopLayer($image);
     }
     throw new ImageWorkshopException('No such file found at "' . $path . '"', static::ERROR_IMAGE_NOT_FOUND);
 }
コード例 #6
0
ファイル: functions.php プロジェクト: sztanpet/aoiboard
function create_thumb($path, $thumb_path, $width = THUMB_WIDTH, $height = THUMB_HEIGHT)
{
    $image_info = getImageSize($path);
    // see EXIF for faster way
    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                // not the same as IMAGETYPE
                $o_im = @imageCreateFromGIF($path);
            } else {
                throw new Exception('GIF images are not supported');
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $o_im = @imageCreateFromJPEG($path);
            } else {
                throw new Exception('JPEG images are not supported');
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $o_im = @imageCreateFromPNG($path);
            } else {
                throw new Exception('PNG images are not supported');
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $o_im = @imageCreateFromWBMP($path);
            } else {
                throw new Exception('WBMP images are not supported');
            }
            break;
        default:
            throw new Exception($image_info['mime'] . ' images are not supported');
            break;
    }
    list($o_wd, $o_ht, $html_dimension_string) = $image_info;
    $ratio = $o_wd / $o_ht;
    $t_ht = $width;
    $t_wd = $height;
    if (1 > $ratio) {
        $t_wd = round($o_wd * $t_wd / $o_ht);
    } else {
        $t_ht = round($o_ht * $t_ht / $o_wd);
    }
    $t_wd = $t_wd < 1 ? 1 : $t_wd;
    $t_ht = $t_ht < 1 ? 1 : $t_ht;
    $t_im = imageCreateTrueColor($t_wd, $t_ht);
    imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
    imagejpeg($t_im, $thumb_path, 85);
    chmod($thumb_path, 0664);
    imageDestroy($o_im);
    imageDestroy($t_im);
    return array($t_wd, $t_ht);
}
コード例 #7
0
ファイル: c_file.php プロジェクト: Rabotyahoff/xml_engine
 public static function resize_image($path_from, $path_to, $content_ext, $max_width, $max_height)
 {
     //if ($content_ext=='') $content_ext=c_file::get_ext($path_from);
     //else
     $content_ext = mb_strtolower($content_ext);
     $im = '';
     switch ($content_ext) {
         case ".jpg":
         case ".jpeg":
             $im = @imageCreateFromJPEG($path_from);
             break;
         case ".png":
             $im = @imageCreateFromPNG($path_from);
             break;
         case ".gif":
             $im = @imageCreateFromGIF($path_from);
             break;
         default:
             return false;
             break;
     }
     if ($im == '') {
         //may be ext is wrong
         $im = @imageCreateFromJPEG($path_from);
         if ($im == '') {
             $im = @imageCreateFromPNG($path_from);
         }
         if ($im == '') {
             $im = @imageCreateFromGIF($path_from);
         }
     }
     if ($im == '') {
         return false;
     }
     if (ImageSX($im) >= ImageSY($im) && ImageSX($im) > $max_width) {
         $thumb_ratio = ImageSY($im) / (ImageSX($im) / $max_width) / $max_height;
         $im_new_th = @ImageCreateTrueColor($max_width, $max_height);
         @imagecopyresampled($im_new_th, $im, 0, 0, (ImageSX($im) - ImageSX($im) * $thumb_ratio) / 1.5, 0, $max_width, $max_height, ImageSX($im) * $thumb_ratio, ImageSY($im));
         @ImageJPEG($im_new_th, $path_to);
         @ImageDestroy($im_new_th);
     } else {
         if (ImageSY($im) > $max_height) {
             $thumb_ratio = ImageSX($im) / (ImageSY($im) / $max_height) / $max_width;
             $im_new_th = @ImageCreateTrueColor($max_width, $max_height);
             @imagecopyresampled($im_new_th, $im, 0, 0, 0, (ImageSY($im) - ImageSY($im) * $thumb_ratio) / 5, $max_width, $max_height, ImageSX($im), ImageSY($im) * $thumb_ratio);
             @ImageJPEG($im_new_th, $path_to);
             @ImageDestroy($im_new_th);
         } else {
             @ImageJPEG($im, $path_to);
         }
     }
     @ImageDestroy($im);
     c_file::set_chmod_chown_chgrp($path_to);
     return true;
 }
コード例 #8
0
ファイル: corrupt.php プロジェクト: recyclism/Corrupt
function jpegIsValid($filename)
{
    // load the file
    $img = @imageCreateFromJPEG($filename);
    // return 0 if the image is invalid
    if (!$img) {
        return 0;
    }
    // return 1 otherwise
    return 1;
}
コード例 #9
0
 public function getCanvas()
 {
     if ($this->_canvas == null) {
         switch ($this->_metrics->sourceFormat) {
             case 1:
                 #GIF
                 $this->_canvas = imageCreateFromGIF($this->filePath);
                 break;
             case 2:
                 #JPG
                 $this->_canvas = imageCreateFromJPEG($this->filePath);
                 break;
             case 3:
                 #PNG
                 $this->_canvas = imageCreateFromPNG($this->filePath);
                 break;
         }
     }
     return $this->_canvas;
 }
コード例 #10
0
ファイル: c_graph.php プロジェクト: Rabotyahoff/xml_engine
 public static function get_im($src)
 {
     if (empty($src)) {
         return false;
     }
     $info = @getimagesize($src);
     if (is_array($info)) {
         $type_img = $info[2];
         /* 1 = GIF,
            2 = JPG,
            3 = PNG,
            4 = SWF,
            5 = PSD,
            6 = BMP,
            7 = TIFF(intel),
            8 = TIFF(motorola),
            9 = JPC,
            10 = JP2,
            11 = JP*/
         switch ($type_img) {
             case 1:
                 $im = @imageCreateFromGIF($src);
                 break;
             case 2:
                 $im = @imageCreateFromJPEG($src);
                 break;
             case 3:
                 $im = @imageCreateFromPNG($src);
                 break;
             case 6:
                 $im = @imagecreatefromwbmp($src);
                 break;
             default:
                 $im = false;
                 break;
         }
     } else {
         $im = false;
     }
     return $im;
 }
コード例 #11
0
 function imageConverter()
 {
     /* parse arguments */
     $numargs = func_num_args();
     $imagefile = func_get_arg(0);
     $convertedtype = func_get_arg(1);
     $this->finalFilePath = func_get_arg(2);
     $output = 0;
     if ($numargs > 3) {
         $this->output = func_get_arg(3);
     }
     /* ask the type of original file */
     $fileinfo = pathinfo($imagefile);
     $imtype = $fileinfo["extension"];
     $this->imname = basename($fileinfo["basename"], "." . $imtype);
     $this->imtype = $imtype;
     /* create the image variable of original file */
     switch ($imtype) {
         case "gif":
             $this->im = imageCreateFromGIF($imagefile);
             break;
         case "jpg":
             $this->im = imageCreateFromJPEG($imagefile);
             break;
         case "png":
             $this->im = imageCreateFromPNG($imagefile);
             break;
         case "wbmp":
             $this->im = imageCreateFromWBMP($imagefile);
             break;
             /*
             		mail me if you have/find this functionality bellow  */
             /*
             case "swf":
             	$this->im 	= $this->imageCreateFromSWF($imagefile);
             	break;
             */
     }
     /* convert to intended type */
     $this->convertImage($convertedtype);
 }
コード例 #12
0
 /**
  * Initialize a layer from a given image path
  * 
  * From an upload form, you can give the "tmp_name" path
  * 
  * @param string $path
  * @param bool $fixOrientation
  * 
  * @return ImageWorkshopLayer
  */
 public static function initFromPath($path, $fixOrientation = false)
 {
     if (!file_exists($path)) {
         throw new ImageWorkshopException(sprintf('File "%s" not exists.', $path), static::ERROR_IMAGE_NOT_FOUND);
     }
     if (false === ($imageSizeInfos = @getImageSize($path))) {
         throw new ImageWorkshopException('Can\'t open the file at "' . $path . '" : file is not readable, did you check permissions (755 / 777) ?', static::ERROR_NOT_READABLE_FILE);
     }
     $mimeContentType = explode('/', $imageSizeInfos['mime']);
     if (!$mimeContentType || !isset($mimeContentType[1])) {
         throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
     }
     $mimeContentType = $mimeContentType[1];
     $exif = array();
     switch ($mimeContentType) {
         case 'jpeg':
             $image = imageCreateFromJPEG($path);
             if (false === ($exif = @read_exif_data($path))) {
                 $exif = array();
             }
             break;
         case 'gif':
             $image = imageCreateFromGIF($path);
             break;
         case 'png':
             $image = imageCreateFromPNG($path);
             break;
         default:
             throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
             break;
     }
     if (false === $image) {
         throw new ImageWorkshopException('Unable to create image with file found at "' . $path . '"');
     }
     $layer = new ImageWorkshopLayer($image, $exif);
     if ($fixOrientation) {
         $layer->fixOrientation();
     }
     return $layer;
 }
コード例 #13
0
ファイル: ImageWorkshop.php プロジェクト: Yatko/Gifteng
 /**
  * Initialize a layer from a given image path
  * 
  * From an upload form, you can give the "tmp_name" path
  * 
  * @param string $path
  * 
  * @return ImageWorkshopLayer
  */
 public static function initFromPath($path)
 {
     if (file_exists($path) && !is_dir($path)) {
         $imageSizeInfos = getImageSize($path);
         $mimeContentType = explode('/', $imageSizeInfos['mime']);
         $mimeContentType = $mimeContentType[1];
         switch ($mimeContentType) {
             case 'jpeg':
                 $image = imageCreateFromJPEG($path);
                 break;
             case 'gif':
                 $image = imageCreateFromGIF($path);
                 break;
             case 'png':
                 $image = imageCreateFromPNG($path);
                 break;
             default:
                 throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
                 break;
         }
         return new ImageWorkshopLayer($image);
     }
     throw new ImageWorkshopException('No such file found at "' . $path . '"', static::ERROR_IMAGE_NOT_FOUND);
 }
コード例 #14
0
ファイル: upload.class.php プロジェクト: softhui/discuz
 function watermark($target, $watermark_file, $ext, $watermarkstatus = 9, $watermarktrans = 50)
 {
     $gdsurporttype = array();
     if (function_exists('imageAlphaBlending') && function_exists('getimagesize')) {
         if (function_exists('imageGIF')) {
             $gdsurporttype[] = 'gif';
         }
         if (function_exists('imagePNG')) {
             $gdsurporttype[] = 'png';
         }
         if (function_exists('imageJPEG')) {
             $gdsurporttype[] = 'jpg';
             $gdsurporttype[] = 'jpeg';
         }
     }
     if ($gdsurporttype && in_array($ext, $gdsurporttype)) {
         $attachinfo = getimagesize($target);
         $watermark_logo = imageCreateFromGIF($watermark_file);
         $logo_w = imageSX($watermark_logo);
         $logo_h = imageSY($watermark_logo);
         $img_w = $attachinfo[0];
         $img_h = $attachinfo[1];
         $wmwidth = $img_w - $logo_w;
         $wmheight = $img_h - $logo_h;
         $animatedgif = 0;
         if ($attachinfo['mime'] == 'image/gif') {
             $fp = fopen($target, 'rb');
             $targetcontent = fread($fp, 9999999);
             fclose($fp);
             $animatedgif = strpos($targetcontent, 'NETSCAPE2.0') === FALSE ? 0 : 1;
         }
         if ($watermark_logo && $wmwidth > 10 && $wmheight > 10 && !$animatedgif) {
             switch ($attachinfo['mime']) {
                 case 'image/jpeg':
                     $dst_photo = imageCreateFromJPEG($target);
                     break;
                 case 'image/gif':
                     $dst_photo = imageCreateFromGIF($target);
                     break;
                 case 'image/png':
                     $dst_photo = imageCreateFromPNG($target);
                     break;
             }
             switch ($watermarkstatus) {
                 case 1:
                     $x = +5;
                     $y = +5;
                     break;
                 case 2:
                     $x = ($logo_w + $img_w) / 2;
                     $y = +5;
                     break;
                 case 3:
                     $x = $img_w - $logo_w - 5;
                     $y = +5;
                     break;
                 case 4:
                     $x = +5;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 5:
                     $x = ($logo_w + $img_w) / 2;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 6:
                     $x = $img_w - $logo_w;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 7:
                     $x = +5;
                     $y = $img_h - $logo_h - 5;
                     break;
                 case 8:
                     $x = ($logo_w + $img_w) / 2;
                     $y = $img_h - $logo_h;
                     break;
                 case 9:
                     $x = $img_w - $logo_w - 5;
                     $y = $img_h - $logo_h - 5;
                     break;
             }
             imageAlphaBlending($watermark_logo, FALSE);
             imagesavealpha($watermark_logo, TRUE);
             imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
             switch ($attachinfo['mime']) {
                 case 'image/jpeg':
                     imageJPEG($dst_photo, $target);
                     break;
                 case 'image/gif':
                     imageGIF($dst_photo, $target);
                     break;
                 case 'image/png':
                     imagePNG($dst_photo, $target);
                     break;
             }
         }
     }
 }
コード例 #15
0
 /** 
  * Creates a thumbnail picture (jpg/png) of a big image
  * 
  * @param	boolean 	$rescale
  * @return	string		thumbnail 
  */
 public function makeThumbnail($rescale = false)
 {
     list($width, $height, $this->imageType) = @getImageSize($this->sourceFile);
     // check image size
     if ($this->checkSize($width, $height, $rescale)) {
         return false;
     }
     // try to extract the embedded thumbnail first (faster)
     $thumbnail = false;
     if (!$rescale && $this->useEmbedded) {
         $thumbnail = $this->extractEmbeddedThumbnail();
     }
     if (!$thumbnail) {
         // calculate uncompressed filesize
         // and cancel to avoid a memory_limit error
         $memoryLimit = self::getMemoryLimit();
         if ($memoryLimit && $memoryLimit != -1) {
             $fileSize = $width * $height * ($this->imageType == 3 ? 4 : 3);
             if ($fileSize * 2.1 + memory_get_usage() > $memoryLimit) {
                 return false;
             }
         }
         // calculate new picture size
         $x = $y = 0;
         if ($this->quadratic) {
             $newWidth = $newHeight = $this->maxWidth;
             if ($this->appendSourceInfo) {
                 $newHeight -= self::$sourceInfoLineHeight * 2;
             }
             if ($width > $height) {
                 $x = ceil(($width - $height) / 2);
                 $width = $height;
             } else {
                 $y = ceil(($height - $width) / 2);
                 $height = $width;
             }
         } else {
             $maxHeight = $this->maxHeight;
             if ($this->appendSourceInfo) {
                 $maxHeight -= self::$sourceInfoLineHeight * 2;
             }
             if ($this->maxWidth / $width < $maxHeight / $height) {
                 $newWidth = $this->maxWidth;
                 $newHeight = round($height * ($newWidth / $width));
             } else {
                 $newHeight = $maxHeight;
                 $newWidth = round($width * ($newHeight / $height));
             }
         }
         // resize image
         $imageResource = false;
         // jpeg image
         if ($this->imageType == 2 && function_exists('imagecreatefromjpeg')) {
             $imageResource = @imageCreateFromJPEG($this->sourceFile);
         }
         // gif image
         if ($this->imageType == 1 && function_exists('imagecreatefromgif')) {
             $imageResource = @imageCreateFromGIF($this->sourceFile);
         }
         // png image
         if ($this->imageType == 3 && function_exists('imagecreatefrompng')) {
             $imageResource = @imageCreateFromPNG($this->sourceFile);
         }
         // could not create image
         if (!$imageResource) {
             return false;
         }
         // resize image
         if (function_exists('imageCreateTrueColor') && function_exists('imageCopyResampled')) {
             $imageNew = @imageCreateTrueColor($newWidth, $newHeight);
             imageAlphaBlending($imageNew, false);
             @imageCopyResampled($imageNew, $imageResource, 0, 0, $x, $y, $newWidth, $newHeight, $width, $height);
             imageSaveAlpha($imageNew, true);
         } else {
             if (function_exists('imageCreate') && function_exists('imageCopyResized')) {
                 $imageNew = @imageCreate($newWidth, $newHeight);
                 imageAlphaBlending($imageNew, false);
                 @imageCopyResized($imageNew, $imageResource, 0, 0, $x, $y, $newWidth, $newHeight, $width, $height);
                 imageSaveAlpha($imageNew, true);
             } else {
                 return false;
             }
         }
         // create thumbnail
         ob_start();
         if ($this->imageType == 1 && function_exists('imageGIF')) {
             @imageGIF($imageNew);
             $this->mimeType = 'image/gif';
         } else {
             if (($this->imageType == 1 || $this->imageType == 3) && function_exists('imagePNG')) {
                 @imagePNG($imageNew);
                 $this->mimeType = 'image/png';
             } else {
                 if (function_exists('imageJPEG')) {
                     @imageJPEG($imageNew, null, 90);
                     $this->mimeType = 'image/jpeg';
                 } else {
                     return false;
                 }
             }
         }
         @imageDestroy($imageNew);
         $thumbnail = ob_get_contents();
         ob_end_clean();
     }
     if ($thumbnail && $this->appendSourceInfo && !$rescale) {
         $thumbnail = $this->appendSourceInfo($thumbnail);
     }
     return $thumbnail;
 }
コード例 #16
0
ファイル: Image.php プロジェクト: goragod/kotchasan
 /**
  * ฟังก์ชั่น โหลดภาพ jpg และหมุนภาพอัตโนมัติจากข้อมูลของ Exif
  *
  * @param resource $source resource ของรูปภาพต้นฉบับ
  * @return resource คืนค่า resource ของรูปภาพหลังจากหมุนแล้ว ถ้าไม่สนับสนุนคืนค่า resource เดิม
  */
 public static function orient($source)
 {
     $imgsrc = imageCreateFromJPEG($source);
     if (function_exists('exif_read_data')) {
         // read image exif and rotate
         $exif = @exif_read_data($source);
         if (!isset($exif['Orientation'])) {
             return $imgsrc;
         } elseif ($exif['Orientation'] == 2) {
             // horizontal flip
             $imgsrc = self::flip($imgsrc);
         } elseif ($exif['Orientation'] == 3) {
             // 180 rotate left
             $imgsrc = imagerotate($imgsrc, 180, 0);
         } elseif ($exif['Orientation'] == 4) {
             // vertical flip
             $imgsrc = self::flip($imgsrc);
         } elseif ($exif['Orientation'] == 5) {
             // vertical flip + 90 rotate right
             $imgsrc = imagerotate($imgsrc, 270, 0);
             $imgsrc = self::flip($imgsrc);
         } elseif ($exif['Orientation'] == 6) {
             // 90 rotate right
             $imgsrc = imagerotate($imgsrc, 270, 0);
         } elseif ($exif['Orientation'] == 7) {
             // horizontal flip + 90 rotate right
             $imgsrc = imagerotate($imgsrc, 90, 0);
             $imgsrc = self::flip($imgsrc);
         } elseif ($exif['Orientation'] == 8) {
             // 90 rotate left
             $imgsrc = imagerotate($imgsrc, 90, 0);
         }
     }
     return $imgsrc;
 }
コード例 #17
0
ファイル: cms.php プロジェクト: restorer/deprecated-zame-cms
 public static function load_image($page, $name, $tmp_path)
 {
     $size = self::ensure_image($page, $name, $tmp_path);
     if (!$size) {
         return null;
     }
     switch ($size[2]) {
         case 1:
             $img = imageCreateFromGIF($tmp_path);
             break;
         case 2:
             $img = imageCreateFromJPEG($tmp_path);
             break;
         case 3:
             $img = imageCreateFromPNG($tmp_path);
             break;
     }
     @unlink($tmp_path);
     return array($img, $size);
 }
コード例 #18
0
ファイル: chgimg.php プロジェクト: airfox7412/ps01
<?php

include "ewcfg6.php";
include "ewmysql6.php";
include "phpfn6.php";
if (@$_GET["img"] != "") {
    $img = $_GET["img"];
    $bvalue = $_GET["bv"];
    //判斷輸出檔名
    if ($bvalue < 0) {
        $outimg = 'temp_d.jpg';
    } elseif ($bvalue > 0) {
        $outimg = 'temp_l.jpg';
    } else {
        $outimg = 'temp_o.jpg';
    }
    //判斷輸出檔名
    $fname = @imageCreateFromJPEG(PACS_PATH . $img);
    if ($fname && imagefilter($fname, IMG_FILTER_BRIGHTNESS, $bvalue)) {
        //echo '影像轉換';
        imagejpeg($fname, $outimg);
        echo $outimg;
    } else {
        //echo '影像轉換失敗';
        echo '';
    }
    imagedestroy($fname);
}
コード例 #19
0
ファイル: TFiles.class.php プロジェクト: alexchitoraga/tunet
 public function MakeThumbnail($o_file, $fileName, $quality, $width, $height)
 {
     $image_info = getImageSize($o_file);
     switch ($image_info['mime']) {
         case 'image/gif':
             if (imagetypes() & IMG_GIF) {
                 // not the same as IMAGETYPE
                 $o_im = imageCreateFromGIF($o_file);
             }
             break;
         case 'image/jpeg':
             if (imagetypes() & IMG_JPG) {
                 $o_im = imageCreateFromJPEG($o_file);
             }
             break;
         case 'image/png':
             if (imagetypes() & IMG_PNG) {
                 $o_im = imageCreateFromPNG($o_file);
             }
             break;
         case 'image/wbmp':
             if (imagetypes() & IMG_WBMP) {
                 $o_im = imageCreateFromWBMP($o_file);
             }
             break;
         default:
             break;
     }
     $o_wd = imagesx($o_im);
     $o_ht = imagesy($o_im);
     // thumbnail width = target * original width / original height
     if ($o_ht > $o_wd) {
         $t_wd = round($o_wd * $height / $o_ht);
         $t_ht = $height;
     }
     if ($o_ht < $o_wd) {
         $t_ht = round($o_ht * $width / $o_wd);
         $t_wd = $width;
     }
     if ($t_ht > $height) {
         $t_wd = round($o_wd * $height / $o_ht);
         $t_ht = $height;
     }
     $t_im = imageCreateTrueColor($t_wd, $t_ht);
     imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
     imageJPEG($t_im, $fileName, 100);
     imageDestroy($o_im);
     imageDestroy($t_im);
     return true;
 }
コード例 #20
0
include 'functions/jforg_gettext.php';
$template->set_frame('fullpage', 'green');
if (!$user->login($_SESSION['nick'], $_SESSION['passwd'])) {
    die('You are not logged in');
}
$user_id = $user->get_id($_SESSION['nick']);
if ($_POST['upload'] != '') {
    $file = $_FILES['file'];
    if ($file['error'] != 0) {
        $error = '<br /><br /><em>{LANG_ERROR_WHILE_UPLOADING}</em>';
    } else {
        if ($file['type'] != 'image/jpeg') {
            $error = '<br /><br /><em>{LANG_UNACCEPT_FILEFORMAT}</em>';
        } else {
            $image_src = imageCreateFromJPEG($file['tmp_name']);
            $image = imageCreate(150, 150);
            $image_src_h = imagesx($image_src);
            $image_src_w = imagesy($image_src);
            imagecopyresampled($image, $image_src, 0, 0, 0, 0, 150, 150, $image_src_w, $image_src_h);
            imagejpeg($image, 'upload/userpics/' . $user_id . '.jpg', 100);
        }
    }
}
$content .= '<table style="width: 100%;" cellpadding="2" cellspacing="0" border="0">';
$content .= '<tr><td valign="top" style="width: 150px;">';
if (file_exists('upload/userpics/' . $user_id . '.jpg')) {
    $content .= '<img src="/upload/userpics/' . $user_id . '.jpg" width="150" />';
} else {
    $content .= '&nbsp;';
}
コード例 #21
0
ファイル: imageTransform.php プロジェクト: vcgato29/poff
 /**
  * function imageDefine (void)
  *
  * Check the image format and create a new image with the same format
  *
  * return resource
  */
 function imageDefine()
 {
     switch ($this->data[2]) {
         case 1:
             return imageCreateFromGIF($this->image);
         case 2:
             return imageCreateFromJPEG($this->image);
         case 3:
             return imageCreateFromPNG($this->image);
         default:
             return false;
     }
 }
コード例 #22
0
ファイル: image_crop.php プロジェクト: zawzawzaw/scoop
 /**
  * Creates a new image given an original path, a new path, a target width and height.
  * Optionally crops image to exactly match given width and height.
  * @params string $originalPath, string $newpath, int $width, int $height, bool $crop
  * @return void
  */
 public function create($originalPath, $newPath, $width, $height, $crop = false)
 {
     // first, we grab the original image. We shouldn't ever get to this function unless the image is valid
     $imageSize = @getimagesize($originalPath);
     $oWidth = $imageSize[0];
     $oHeight = $imageSize[1];
     $finalWidth = 0;
     //For cropping, this is really "scale to width before chopping extra height"
     $finalHeight = 0;
     //For cropping, this is really "scale to height before chopping extra width"
     $do_crop_x = false;
     $do_crop_y = false;
     $crop_src_x = 0;
     $crop_src_y = 0;
     // first, if what we're uploading is actually smaller than width and height, we do nothing
     if ($oWidth < $width && $oHeight < $height) {
         $finalWidth = $oWidth;
         $finalHeight = $oHeight;
         $width = $oWidth;
         $height = $oHeight;
     } else {
         if ($crop && ($height >= $oHeight && $width <= $oWidth)) {
             //crop to width only -- don't scale anything
             $finalWidth = $oWidth;
             $finalHeight = $oHeight;
             $height = $oHeight;
             $do_crop_x = true;
         } else {
             if ($crop && ($width >= $oWidth && $height <= $oHeight)) {
                 //crop to height only -- don't scale anything
                 $finalHeight = $oHeight;
                 $finalWidth = $oWidth;
                 $width = $oWidth;
                 $do_crop_y = true;
             } else {
                 // otherwise, we do some complicated stuff
                 // first, we divide original width and height by new width and height, and find which difference is greater
                 $wDiff = $oWidth / $width;
                 $hDiff = $oHeight / $height;
                 if (!$crop && $wDiff > $hDiff) {
                     //no cropping, just resize down based on target width
                     $finalWidth = $width;
                     $finalHeight = $oHeight / $wDiff;
                 } else {
                     if (!$crop) {
                         //no cropping, just resize down based on target height
                         $finalWidth = $oWidth / $hDiff;
                         $finalHeight = $height;
                     } else {
                         if ($crop && $wDiff > $hDiff) {
                             //resize down to target height, THEN crop off extra width
                             $finalWidth = $oWidth / $hDiff;
                             $finalHeight = $height;
                             $do_crop_x = true;
                         } else {
                             if ($crop) {
                                 //resize down to target width, THEN crop off extra height
                                 $finalWidth = $width;
                                 $finalHeight = $oHeight / $wDiff;
                                 $do_crop_y = true;
                             }
                         }
                     }
                 }
             }
         }
     }
     //Calculate cropping to center image
     if ($do_crop_x) {
         /*
         //Get half the difference between scaled width and target width,
         // and crop by starting the copy that many pixels over from the left side of the source (scaled) image.
         $nudge = ($width / 10); //I have *no* idea why the width isn't centering exactly -- this seems to fix it though.
         $crop_src_x = ($finalWidth / 2.00) - ($width / 2.00) + $nudge;
         */
         $crop_src_x = round(($oWidth - $width * $oHeight / $height) * 0.5);
     }
     if ($do_crop_y) {
         /*
         //Calculate cropping...
         //Get half the difference between scaled height and target height,
         // and crop by starting the copy that many pixels down from the top of the source (scaled) image.
         $crop_src_y = ($finalHeight / 2.00) - ($height / 2.00);
         */
         $crop_src_y = round(($oHeight - $height * $oWidth / $width) * 0.5);
     }
     //create "canvas" to put new resized and/or cropped image into
     if ($crop) {
         $image = @imageCreateTrueColor($width, $height);
     } else {
         $image = @imageCreateTrueColor($finalWidth, $finalHeight);
     }
     switch ($imageSize[2]) {
         case IMAGETYPE_GIF:
             $im = @imageCreateFromGIF($originalPath);
             break;
         case IMAGETYPE_JPEG:
             $im = @imageCreateFromJPEG($originalPath);
             break;
         case IMAGETYPE_PNG:
             $im = @imageCreateFromPNG($originalPath);
             break;
     }
     if ($im) {
         // Better transparency - thanks for the ideas and some code from mediumexposure.com
         if ($imageSize[2] == IMAGETYPE_GIF || $imageSize[2] == IMAGETYPE_PNG) {
             $trnprt_indx = imagecolortransparent($im);
             // If we have a specific transparent color
             if ($trnprt_indx >= 0) {
                 // Get the original image's transparent color's RGB values
                 $trnprt_color = imagecolorsforindex($im, $trnprt_indx);
                 // Allocate the same color in the new image resource
                 $trnprt_indx = imagecolorallocate($image, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                 // Completely fill the background of the new image with allocated color.
                 imagefill($image, 0, 0, $trnprt_indx);
                 // Set the background color for new image to transparent
                 imagecolortransparent($image, $trnprt_indx);
             } else {
                 if ($imageSize[2] == IMAGETYPE_PNG) {
                     // Turn off transparency blending (temporarily)
                     imagealphablending($image, false);
                     // Create a new transparent color for image
                     $color = imagecolorallocatealpha($image, 0, 0, 0, 127);
                     // Completely fill the background of the new image with allocated color.
                     imagefill($image, 0, 0, $color);
                     // Restore transparency blending
                     imagesavealpha($image, true);
                 }
             }
         }
         $res = @imageCopyResampled($image, $im, 0, 0, $crop_src_x, $crop_src_y, $finalWidth, $finalHeight, $oWidth, $oHeight);
         if ($res) {
             switch ($imageSize[2]) {
                 case IMAGETYPE_GIF:
                     $res2 = imageGIF($image, $newPath);
                     break;
                 case IMAGETYPE_JPEG:
                     $compression = defined('AL_THUMBNAIL_JPEG_COMPRESSION') ? AL_THUMBNAIL_JPEG_COMPRESSION : 80;
                     $res2 = imageJPEG($image, $newPath, $compression);
                     break;
                 case IMAGETYPE_PNG:
                     $res2 = imagePNG($image, $newPath);
                     break;
             }
         }
     }
 }
コード例 #23
0
ファイル: upload.func.php プロジェクト: hongz1125/devil
function makewatermark($srcfile)
{
    global $_SCONFIG;
    if ($_SCONFIG['watermark'] && function_exists('imageCreateFromJPEG') && function_exists('imageCreateFromPNG') && function_exists('imageCopyMerge')) {
        $srcfile = A_DIR . '/' . $srcfile;
        $watermark_file = $_SCONFIG['watermarkfile'];
        $watermarkstatus = $_SCONFIG['watermarkstatus'];
        $fileext = fileext($watermark_file);
        $ispng = $fileext == 'png' ? true : false;
        $attachinfo = @getimagesize($srcfile);
        if (!empty($attachinfo) && is_array($attachinfo) && $attachinfo[2] != 1 && $attachinfo['mime'] != 'image/gif') {
        } else {
            return '';
        }
        $watermark_logo = $ispng ? @imageCreateFromPNG($watermark_file) : @imageCreateFromGIF($watermark_file);
        if (!$watermark_logo) {
            return '';
        }
        $logo_w = imageSX($watermark_logo);
        $logo_h = imageSY($watermark_logo);
        $img_w = $attachinfo[0];
        $img_h = $attachinfo[1];
        $wmwidth = $img_w - $logo_w;
        $wmheight = $img_h - $logo_h;
        if (is_readable($watermark_file) && $wmwidth > 100 && $wmheight > 100) {
            switch ($attachinfo['mime']) {
                case 'image/jpeg':
                    $dst_photo = imageCreateFromJPEG($srcfile);
                    break;
                case 'image/gif':
                    $dst_photo = imageCreateFromGIF($srcfile);
                    break;
                case 'image/png':
                    $dst_photo = imageCreateFromPNG($srcfile);
                    break;
                default:
                    break;
            }
            switch ($watermarkstatus) {
                case 1:
                    $x = +5;
                    $y = +5;
                    break;
                case 2:
                    $x = ($img_w - $logo_w) / 2;
                    $y = +5;
                    break;
                case 3:
                    $x = $img_w - $logo_w - 5;
                    $y = +5;
                    break;
                case 4:
                    $x = +5;
                    $y = ($img_h - $logo_h) / 2;
                    break;
                case 5:
                    $x = ($img_w - $logo_w) / 2;
                    $y = ($img_h - $logo_h) / 2;
                    break;
                case 6:
                    $x = $img_w - $logo_w - 5;
                    $y = ($img_h - $logo_h) / 2;
                    break;
                case 7:
                    $x = +5;
                    $y = $img_h - $logo_h - 5;
                    break;
                case 8:
                    $x = ($img_w - $logo_w) / 2;
                    $y = $img_h - $logo_h - 5;
                    break;
                case 9:
                    $x = $img_w - $logo_w - 5;
                    $y = $img_h - $logo_h - 5;
                    break;
            }
            if ($ispng) {
                $watermark_photo = imagecreatetruecolor($img_w, $img_h);
                imageCopy($watermark_photo, $dst_photo, 0, 0, 0, 0, $img_w, $img_h);
                imageCopy($watermark_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);
                $dst_photo = $watermark_photo;
            } else {
                imageAlphaBlending($watermark_logo, true);
                imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $_SCONFIG['watermarktrans']);
            }
            switch ($attachinfo['mime']) {
                case 'image/jpeg':
                    imageJPEG($dst_photo, $srcfile, $_SCONFIG['watermarkjpgquality']);
                    break;
                case 'image/gif':
                    imageGIF($dst_photo, $srcfile);
                    break;
                case 'image/png':
                    imagePNG($dst_photo, $srcfile);
                    break;
            }
        }
    }
}
コード例 #24
0
ファイル: index.php プロジェクト: brustj/tracmor
 protected function btnSave_Click()
 {
     $this->pnlSaveNotification->Display = false;
     QApplication::$TracmorSettings->MinAssetCode = $this->txtMinAssetCode->Text;
     // Make sure a valid number is entered for Search Results Per Page setting
     if (!is_numeric(trim($this->txtSearchResultsPerPage->Text)) || intval(trim($this->txtSearchResultsPerPage->Text)) < 1) {
         $this->txtSearchResultsPerPage->Warning = QApplication::Translate('Please enter a valid number');
         $this->txtSearchResultsPerPage->Blink();
         $this->txtSearchResultsPerPage->Focus();
         return;
     } else {
         QApplication::$TracmorSettings->SearchResultsPerPage = intval(trim($this->txtSearchResultsPerPage->Text));
     }
     // If a customer logo was uploaded, save it to the appropriate location
     if ($this->flaCompanyLogo->File) {
         $arrImageInfo = getimagesize($this->flaCompanyLogo->File);
         // Resize the image if necessary
         $strMimeType = image_type_to_mime_type($arrImageInfo[2]);
         $intSrcWidth = $arrImageInfo[0];
         $intSrcHeight = $arrImageInfo[1];
         if ($intSrcHeight > 50) {
             $intDstHeight = 50;
             $intDstWidth = round(50 / $intSrcHeight * $intSrcWidth);
             $imgResampled = imagecreatetruecolor($intDstWidth, $intDstHeight);
             $strTransparentColor = imagecolorallocatealpha($imgResampled, 0, 0, 0, 127);
             imagealphablending($imgResampled, false);
             imagefilledrectangle($imgResampled, 0, 0, $intDstWidth, $intDstHeight, $strTransparentColor);
             imagealphablending($imgResampled, true);
             imagesavealpha($imgResampled, true);
             switch ($strMimeType) {
                 case 'image/gif':
                     $image = imageCreateFromGIF($this->flaCompanyLogo->File);
                     break;
                 case 'image/jpeg':
                 case 'image/pjpeg':
                     $image = imageCreateFromJPEG($this->flaCompanyLogo->File);
                     break;
                 case 'image/png':
                 case 'image/x-png':
                     $image = imageCreateFromPNG($this->flaCompanyLogo->File);
                     break;
             }
             imagecopyresampled($imgResampled, $image, 0, 0, 0, 0, $intDstWidth, $intDstHeight, $intSrcWidth, $intSrcHeight);
             switch ($strMimeType) {
                 case 'image/gif':
                     imagegif($imgResampled, $this->flaCompanyLogo->File);
                     break;
                 case 'image/jpeg':
                 case 'image/pjpeg':
                     imagejpeg($imgResampled, $this->flaCompanyLogo->File);
                     break;
                 case 'image/png':
                 case 'image/x-png':
                     imagepng($imgResampled, $this->flaCompanyLogo->File);
                     break;
             }
         }
         rename($this->flaCompanyLogo->File, '../images/' . $this->flaCompanyLogo->FileName);
         if (AWS_S3) {
             QApplication::MoveToS3(__DOCROOT__ . __IMAGE_ASSETS__, $this->flaCompanyLogo->FileName, $strMimeType, '/images');
         }
         // Save the setting to the database
         QApplication::$TracmorSettings->CompanyLogo = $this->flaCompanyLogo->FileName;
     }
     // We have to cast these to string because the admin_settings value column is TEXT, and checkboxes give boolean values
     QApplication::$TracmorSettings->PortablePinRequired = (string) $this->chkPortablePinRequired->Checked;
     //QApplication::$TracmorSettings->StrictCheckinPolicy = (string) $this->chkStrictCheckinPolicy->Checked;
     // Show saved notification
     $this->pnlSaveNotification->Display = true;
 }
コード例 #25
0
ファイル: image.php プロジェクト: redx/LifeNote
    }
    if (55685 < $head && $head < 57083 && 39995 < $body && $body < 41060 && 26456 < $foot && $foot < 27319) {
        echo "6!!!";
    }
    if (60423 < $head && $head < 62245 && 46162 < $body && $body < 47739 && 20212 < $foot && $foot < 31258) {
        echo "7!!!";
    }
    if (54651 < $head && $head < 55610 && 39235 < $body && $body < 41769 && 26674 < $foot && $foot < 28516) {
        echo "8!!!";
    }
}
$color = array(0, 0, 0, 0);
for ($i = 0; $i < 199; $i++) {
    for ($j = 0; $j < 5; $j++) {
        $image = "cut/{$i}({$j}).jpg";
        $im = imageCreateFromJPEG($image);
        for ($cut = 0; $cut < 4; $cut++) {
            for ($x = 1; $x < 15; $x++) {
                for ($y = $cut * 5 + 1; $y < 20; $y++) {
                    $rgb = imagecolorat($im, $x, $y);
                    $r = $rgb >> 16 & 0xff;
                    $color[$cut] += $r;
                }
            }
            echo "{$color[$cut]}/";
        }
        recongnize($color[0], $color[1], $color[2]);
        for ($m = 0; $m < 4; $m++) {
            $color[$m] = 0;
        }
        echo "<img src={$image} /><br/>";
コード例 #26
0
ファイル: Upload.class.php プロジェクト: alexchitoraga/tunet
 public static function thumbComplete($o_file, $fileName, $t_ht = 100, $x, $y, $width, $height, $ow, $sizes = array())
 {
     $image_info = getImageSize($o_file);
     // see EXIF for faster way
     switch ($image_info['mime']) {
         case 'image/gif':
             if (imagetypes() & IMG_GIF) {
                 // not the same as IMAGETYPE
                 $o_im = imageCreateFromGIF($o_file);
             }
             break;
         case 'image/jpeg':
             if (imagetypes() & IMG_JPG) {
                 $o_im = imageCreateFromJPEG($o_file);
             }
             break;
         case 'image/png':
             if (imagetypes() & IMG_PNG) {
                 $o_im = imageCreateFromPNG($o_file);
             }
             break;
         case 'image/wbmp':
             if (imagetypes() & IMG_WBMP) {
                 $o_im = imageCreateFromWBMP($o_file);
             }
             break;
         default:
             break;
     }
     $o_wd = imagesx($o_im);
     $o_ht = imagesy($o_im);
     $size = $o_wd / $ow;
     echo $size . '<br>';
     echo $x * $size . '<br>';
     echo $y * $size . '<br>';
     echo $sizes['width'] . '<br>';
     echo $sizes['height'] . '<br>';
     echo $width * $size . '<br>';
     echo $height * $size . '<br>';
     //        die;
     $new_im = imageCreateTrueColor($width, $height);
     if (empty($sizes)) {
         imagecopyresampled($new_im, $o_im, 0, 0, $x * $size, $y * $size, $width * $size, $height * $size, $width * $size, $height * $size);
     } else {
         imagecopyresampled($new_im, $o_im, 0, 0, $x * $size, $y * $size, $sizes['width'], $sizes['height'], $width * $size, $height * $size);
     }
     imageJPEG($new_im, $fileName, 100);
     chmod($fileName, 0777);
     imageDestroy($o_im);
     imageDestroy($new_im);
     return true;
 }
コード例 #27
0
 /**
  * Test initFromResourceVar
  */
 public function testInitFromResourceVar()
 {
     $layer = ImageWorkshop::initFromResourceVar(imageCreateFromJPEG(__DIR__ . static::IMAGE_SAMPLE_PATH));
     $this->assertTrue(is_object($layer) === true, 'Expect $layer to be an object');
     $this->assertTrue(get_class($layer) === 'PHPImageWorkshop\\Core\\ImageWorkshopLayer', 'Expect $layer to be an ImageWorkshopLayer object');
 }
コード例 #28
0
function makeThumbnail($o_file, $t_file, $t_ht = 100)
{
    $image_info = getImageSize($o_file);
    // see EXIF for faster way
    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                // not the same as IMAGETYPE
                $o_im = imageCreateFromGIF($o_file);
            } else {
                $ermsg = 'GIF images are not supported<br />';
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $o_im = imageCreateFromJPEG($o_file);
            } else {
                $ermsg = 'JPEG images are not supported<br />';
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $o_im = imageCreateFromPNG($o_file);
            } else {
                $ermsg = 'PNG images are not supported<br />';
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $o_im = imageCreateFromWBMP($o_file);
            } else {
                $ermsg = 'WBMP images are not supported<br />';
            }
            break;
        default:
            $ermsg = $image_info['mime'] . ' images are not supported<br />';
            break;
    }
    if (!isset($ermsg)) {
        $o_wd = imagesx($o_im);
        $o_ht = imagesy($o_im);
        // thumbnail width = target * original width / original height
        //
        if ($o_ht > $o_wd && $o_ht > $t_ht) {
            $new_w = $t_ht / $o_ht * $o_wd;
            $new_h = $t_ht;
        } else {
            if ($o_wd > $t_ht) {
                $new_h = $t_ht / $o_wd * $o_ht;
                $new_w = $t_ht;
            } else {
                $new_h = $o_ht;
                $new_w = $o_wd;
            }
        }
        //
        //$t_wd = round($o_wd * $t_ht / $o_ht) ;
        $t_im = imageCreateTrueColor($new_w, $new_h);
        imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $new_w, $new_h, $o_wd, $o_ht);
        imageJPEG($t_im, $t_file);
        imageDestroy($o_im);
        imageDestroy($t_im);
    }
    return isset($ermsg) ? $ermsg : NULL;
}
コード例 #29
0
 /**
  * Open the source and target image for processing it
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __open(&$tmp)
 {
     $error_source = false;
     $error_target = false;
     // get image dimensions
     //
     if ($i = @getImageSize($tmp->source_filename)) {
         $tmp->image_width = $i[0];
         $tmp->image_height = $i[1];
     }
     // image type ?
     //
     switch (@$i[2]) {
         case 1:
             // GIF
             $error_source = false == ($tmp->source = @imageCreateFromGIF($tmp->source_filename));
             $error_target = false == ($tmp->target = imageCreateTrueColor($tmp->image_width, $tmp->image_height));
             $error_target &= imageCopyResampled($tmp->target, $tmp->source, 0, 0, 0, 0, $tmp->image_width, $tmp->image_height, $tmp->image_width, $tmp->image_height);
             break;
         case 2:
             // JPG
             $error_source = false == ($tmp->source = imageCreateFromJPEG($tmp->source_filename));
             $error_target = false == ($tmp->target = imageCreateFromJPEG($tmp->source_filename));
             break;
         case 3:
             // PNG
             $error_source = false == ($tmp->source = @imageCreateFromPNG($tmp->source_filename));
             $error_target = false == ($tmp->target = @imageCreateFromPNG($tmp->source_filename));
             break;
         case 15:
             // WBMP
             $error_source = false == ($tmp->source = @imageCreateFromWBMP($tmp->source_filename));
             $error_target = false == ($tmp->target = @imageCreateFromWBMP($tmp->source_filename));
             break;
         case 16:
             // XBM
             $error_source = false == ($tmp->source = @imageCreateFromXBM($tmp->source_filename));
             $error_target = false == ($tmp->target = @imageCreateFromXBM($tmp->source_filename));
             break;
         case 4:
             // SWF
         // SWF
         case 5:
             // PSD
         // PSD
         case 6:
             // BMP
         // BMP
         case 7:
             // TIFF(intel byte order)
         // TIFF(intel byte order)
         case 8:
             // TIFF(motorola byte order)
         // TIFF(motorola byte order)
         case 9:
             // JPC
         // JPC
         case 10:
             // JP2
         // JP2
         case 11:
             // JPX
         // JPX
         case 12:
             // JB2
         // JB2
         case 13:
             // SWC
         // SWC
         case 14:
             // IFF
         // IFF
         default:
             $error_source = false == ($tmp->source = @imageCreateFromString(file_get_contents($tmp->source_filename)));
             $error_target = false == ($tmp->source = @imageCreateFromString(file_get_contents($tmp->source_filename)));
             break;
     }
     return !($error_source || $error_target);
 }
コード例 #30
0
	public function edit($path, $crop_x, $crop_y, $crop_w, $crop_h, $target_w, $target_h) {
		$imageSize = @getimagesize($path);
		$img_type = $imageSize[2];
		
		//create "canvas" to put new resized and/or cropped image into
		$image = @imageCreateTrueColor($target_w, $target_h);
		
		switch($img_type) {
			case IMAGETYPE_GIF:
				$im = @imageCreateFromGIF($path);
				break;
			case IMAGETYPE_JPEG:
				$im = @imageCreateFromJPEG($path);
				break;
			case IMAGETYPE_PNG:
				$im = @imageCreateFromPNG($path);
				break;
		}
		
		if ($im) {
			// Better transparency - thanks for the ideas and some code from mediumexposure.com
			if (($img_type == IMAGETYPE_GIF) || ($img_type == IMAGETYPE_PNG)) {
				$trnprt_indx = imagecolortransparent($im);
				
				// If we have a specific transparent color
				if ($trnprt_indx >= 0) {
			
					// Get the original image's transparent color's RGB values
					$trnprt_color = imagecolorsforindex($im, $trnprt_indx);
					
					// Allocate the same color in the new image resource
					$trnprt_indx = imagecolorallocate($image, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
					
					// Completely fill the background of the new image with allocated color.
					imagefill($image, 0, 0, $trnprt_indx);
					
					// Set the background color for new image to transparent
					imagecolortransparent($image, $trnprt_indx);
					
				
				} else if ($img_type == IMAGETYPE_PNG) {
				
					// Turn off transparency blending (temporarily)
					imagealphablending($image, false);
					
					// Create a new transparent color for image
					$color = imagecolorallocatealpha($image, 0, 0, 0, 127);
					
					// Completely fill the background of the new image with allocated color.
					imagefill($image, 0, 0, $color);
					
					// Restore transparency blending
					imagesavealpha($image, true);
			
				}
			}
			
			$res = @imageCopyResampled($image, $im, 0, 0, $crop_x, $crop_y, $target_w, $target_h, $crop_w, $crop_h);
			if ($res) {
				switch($img_type) {
					case IMAGETYPE_GIF:
						$res2 = imageGIF($image, $path);
						break;
					case IMAGETYPE_JPEG:
						$compression = defined('AL_THUMBNAIL_JPEG_COMPRESSION') ? AL_THUMBNAIL_JPEG_COMPRESSION : 80;
						$res2 = imageJPEG($image, $path, $compression);
						break;
					case IMAGETYPE_PNG:
						$res2 = imagePNG($image, $path);
						break;
				}
			}
		}
	}