コード例 #1
0
 /**
  * Loads the image from given file.
  *
  * @param string $imagePath
  *
  * @return null
  */
 public function load($imagePath)
 {
     if (!file_exists($imagePath)) {
         throw new Exception('WiseChatImageEditor: File does not exist');
     }
     $imageData = getimagesize($imagePath);
     if ($imageData === false) {
         throw new Exception('WiseChatImageEditor: The file is not an image');
     }
     switch ($imageData[2]) {
         case IMAGETYPE_GIF:
             $this->image = imagecreatefromgif($imagePath);
             break;
         case IMAGETYPE_JPEG:
             $this->image = imagecreatefromjpeg($imagePath);
             break;
         case IMAGETYPE_PNG:
             $this->image = imagecreatefrompng($imagePath);
             break;
         case IMAGETYPE_WBMP:
             $this->image = imagecreatefromwbmp($imagePath);
             break;
         default:
             throw new Exception('WiseChatImageEditor: Image format is not supported');
     }
     $this->imageData = $imageData;
     $this->imagePath = $imagePath;
 }
コード例 #2
0
ファイル: resizeImg.php プロジェクト: bugaydima/photogallery
 public function __construct($path)
 {
     if (!file_exists($path)) {
         throw new Exception("Данного файла нет");
     }
     $this->type = $this->getType($path);
     switch ($this->type) {
         case IMAGETYPE_JPEG:
             $img = imagecreatefromjpeg($path);
             break;
         case IMAGETYPE_PNG:
             $img = imagecreatefrompng($path);
             break;
         case IMAGETYPE_PNG:
             $img = imagecreatefrompng($path);
             break;
         case IMAGETYPE_BMP:
             $img = imagecreatefromwbmp($path);
             break;
         default:
             $img = false;
     }
     $this->img = $img;
     if (!$this->img) {
         throw new Exception('Не удалость создать дескриптор изображения');
     }
     $this->width = imagesx($this->img);
     $this->height = imagesy($this->img);
 }
コード例 #3
0
ファイル: image.php プロジェクト: reneolivo/PHP-Toolkit
 static function init($file)
 {
     ini_set("memory_limit", "60M");
     if (is_file($file)) {
         $info = getimagesize($file);
         $img = NULL;
         switch ($info['mime']) {
             case 'image/jpeg':
                 $img = imagecreatefromjpeg($file);
                 break;
             case 'image/gif':
                 $img = imagecreatefromgif($file);
                 break;
             case 'image/png':
                 $img = imagecreatefrompng($file);
                 break;
             case 'image/bmp':
                 $img = imagecreatefromwbmp($file);
                 break;
             default:
                 return false;
                 break;
         }
         return $img;
     } else {
         return false;
     }
 }
コード例 #4
0
ファイル: Resamplr.php プロジェクト: mdular/resamplr
 public function setImage($resource, $versionName)
 {
     // get image info, validate it's an image
     if (!(list($width, $height, $type) = getimagesize($resource))) {
         throw new Exception("Must be an image");
     }
     // get file info
     $info = pathinfo($resource);
     // create image from resource
     switch ($type) {
         case IMAGETYPE_JPEG:
             $img = imagecreatefromjpeg($resource);
             break;
         case IMAGETYPE_PNG:
             $img = imagecreatefrompng($resource);
             break;
         case IMAGETYPE_GIF:
             $img = imagecreatefromgif($resource);
             break;
         case IMAGETYPE_BMP:
             $img = imagecreatefromwbmp($resource);
             break;
         default:
             throw new Exception("Supplied image must be bmp, gif, jpg or png");
     }
     // store image & data
     $this->_resource = $img;
     $this->_width = $width;
     $this->_height = $height;
     $this->_filename = $info['dirname'] . '/' . $info['filename'] . (!empty($versionName) ? '_' . $versionName : '');
     // NOTE: without extension!
     $this->_type = $type;
 }
コード例 #5
0
ファイル: simpleimage.php プロジェクト: brainsqueezer/fffff
 function load($filename)
 {
     $image_info = getimagesize($filename);
     $this->image_type = $image_info[2];
     $this->filename = $filename;
     switch ($this->image_type) {
         case IMAGETYPE_JPEG:
             $this->image = @imagecreatefromjpeg($filename);
             return true;
         case IMAGETYPE_GIF:
             $this->image = @imagecreatefromgif($filename);
             return true;
         case IMAGETYPE_PNG:
             $this->image = @imagecreatefrompng($filename);
             return true;
         case IMAGETYPE_WBMP:
             $this->image = @imagecreatefromwbmp($filename);
             return true;
         default:
             $this->image = false;
     }
     if ($this->image) {
         return true;
     } else {
         return false;
     }
 }
コード例 #6
0
ファイル: ImageHandler.class.php プロジェクト: reytuty/facil
 /**
  * Creation of the original image object.
  *
  * @return object of the image created.
  */
 function createImage()
 {
     //est� conferindo o arquivo pela exten��o contando que foi conferido o tipo de arquivo ao recebe-lo
     $extensao = DataHandler::returnExtensionOfFile($this->image);
     //		echo Debug::li(filetype($this->image));
     //		exit();
     switch (strtolower($extensao)) {
         case 'jpg':
         case 'jpeg':
             return imagecreatefromjpeg($this->image);
             break;
         case 'gif':
             return imagecreatefromgif($this->image);
             break;
         case 'png':
             return imagecreatefrompng($this->image);
             break;
         case 'bmp':
             return imagecreatefromwbmp($this->image);
             break;
         default:
             return imagecreatefromjpeg($this->image);
             break;
     }
 }
コード例 #7
0
ファイル: LitmusService.php プロジェクト: aaronbullard/litmus
 public static function getImageFromUrl($image_url)
 {
     try {
         $mime = image_type_to_mime_type(exif_imagetype($image_url));
     } catch (Exception $e) {
         throw new MimeTypeException($e->getMessage());
     }
     //Get image based on mime and set to $im
     switch ($mime) {
         case 'image/jpeg':
             $im = imagecreatefromjpeg($image_url);
             break;
         case 'image/gif':
             $im = imagecreatefromgif($image_url);
             break;
         case 'image/png':
             $im = imagecreatefrompng($image_url);
             break;
         case 'image/wbmp':
             $im = imagecreatefromwbmp($image_url);
             break;
         default:
             throw new MimeTypeException("An image of '{$mime}' mime type is not supported.");
             break;
     }
     return $im;
 }
コード例 #8
0
ファイル: upload.php プロジェクト: dgerena/SSL
function imageResize($file, $name, $h, $w)
{
    // Get File Extension
    $type = substr($file, -3);
    switch ($type) {
        case $type == 'jpg':
            $canvas = imagecreatefromjpeg($file);
            break;
        case $type == 'png':
            $canvas = imagecreatefrompng($file);
            break;
        case $type == 'bmp':
            $canvas = imagecreatefromwbmp($file);
            break;
        case $type == 'gif':
            $canvas = imagecreatefromgif($file);
            break;
    }
    // getimagesize(); => returns arr[width,height]
    $size = getimagesize($file);
    $fileWidth = $size[0];
    $fileHeight = $size[1];
    // imagecreatetruecolor(width, height)
    $content = imagecreatetruecolor($w, $h);
    // imagecopyresampled(dst_image, src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
    imagecopyresampled($content, $canvas, 0, 0, 0, 0, $w, $h, $fileWidth, $fileHeight);
    // imagepng($content, src file, quality 0-9);
    imagepng($content, $name, 9);
    // Frees up the resources by remove the canvas from the RAM
    imagedestroy($canvas);
}
コード例 #9
0
ファイル: mrthumb.class.php プロジェクト: aliihaidar/pso
 public function render($source)
 {
     $this->s_image = $source;
     list($this->image['width'], $this->image['height']) = getimagesize($source);
     $this->image['extension'] = strtolower(preg_replace('/^.*\\.([^.]+)$/D', '$1', $this->s_image));
     if (!in_array($this->image['extension'], $this->valid_ext)) {
         echo 'Invalid format!';
         $this->halt = true;
     }
     switch ($this->image['extension']) {
         case 'png':
             $this->image['render'] = imagecreatefrompng($this->s_image);
             imagealphablending($this->image['render'], false);
             imagesavealpha($this->image['render'], true);
             break;
         case 'jpg':
             $this->image['render'] = imagecreatefromjpeg($this->s_image);
             break;
         case 'jpeg':
             $this->image['render'] = imagecreatefromjpeg($this->s_image);
             break;
         case 'gif':
             $this->image['render'] = imagecreatefromgif($this->s_image);
             break;
         case 'bmp':
             $this->image['render'] = imagecreatefromwbmp($this->s_image);
             break;
         case 'wbmp':
             $this->image['render'] = imagecreatefromwbmp($this->s_image);
             break;
     }
 }
コード例 #10
0
ファイル: RemoteImage.php プロジェクト: aaronbullard/litmus
 protected function getImage($image_url)
 {
     $this->url = $image_url;
     $mime = image_type_to_mime_type(exif_imagetype($image_url));
     $im;
     //Get image based on mime and set to $im
     switch ($mime) {
         case 'image/jpeg':
             $im = imagecreatefromjpeg($image_url);
             break;
         case 'image/gif':
             $im = imagecreatefromgif($image_url);
             break;
         case 'image/png':
             $im = imagecreatefrompng($image_url);
             break;
         case 'image/wbmp':
             $im = imagecreatefromwbmp($image_url);
             break;
         default:
             return NULL;
             break;
     }
     $this->image = $im;
     return $this;
 }
コード例 #11
0
ファイル: global.func.php プロジェクト: yunsite/cyaskuc
function create_pic($upfile, $new_path, $width)
{
    $quality = 100;
    $image_path = $upfile;
    $image_info = getimagesize($image_path);
    $exname = '';
    //1  =  GIF,  2  =  JPG,  3  =  PNG,  4  =  SWF,  5  =  PSD,  6  =  BMP,  7  =  TIFF(intel  byte  order),  8  =  TIFF(motorola  byte  order),  9  =  JPC,  10  =  JP2,  11  =  JPX,  12  =  JB2,  13  =  SWC,  14  =  IFF
    switch ($image_info[2]) {
        case 1:
            @($image = imagecreatefromgif($image_path));
            $exname = 'gif';
            break;
        case 2:
            @($image = imagecreatefromjpeg($image_path));
            $exname = 'jpg';
            break;
        case 3:
            @($image = imagecreatefrompng($image_path));
            $exname = 'png';
            break;
        case 6:
            @($image = imagecreatefromwbmp($image_path));
            $exname = 'wbmp';
            break;
    }
    $T_width = $image_info[0];
    $T_height = $image_info[1];
    if (!empty($image)) {
        $image_x = imagesx($image);
        $image_y = imagesy($image);
    } else {
        return FALSE;
    }
    @chmod($new_path, 0777);
    if ($image_x > $width) {
        $x = $width;
        $y = intval($x * $image_y / $image_x);
    } else {
        @copy($image_path, $new_path . '.' . $exname);
        return $exname;
    }
    $newimage = imagecreatetruecolor($x, $y);
    imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $image_x, $image_y);
    switch ($image_info[2]) {
        case 1:
            imagegif($newimage, $new_path . '.gif', $quality);
            break;
        case 2:
            imagejpeg($newimage, $new_path . '.jpg', $quality);
            break;
        case 3:
            imagepng($newimage, $new_path . '.png', $quality);
            break;
        case 6:
            imagewbmp($newimage, $new_path . '.wbmp', $quality);
            break;
    }
    imagedestroy($newimage);
    return $exname;
}
コード例 #12
0
ファイル: class_gd.php プロジェクト: Evrika/Vidal
 /** Returns an array. Element 0 - GD resource. Element 1 - width. Element 2 - height.
  * Returns FALSE on failure. The only one parameter $image can be an instance of this class,
  * a GD resource, an array(width, height) or path to image file.
  * @param mixed $image
  * @return array */
 protected function build_image($image)
 {
     if ($image instanceof gd) {
         $width = $image->get_width();
         $height = $image->get_height();
         $image = $image->get_image();
     } elseif (is_resource($image) && get_resource_type($image) == "gd") {
         $width = @imagesx($image);
         $height = @imagesy($image);
     } elseif (is_array($image)) {
         list($key, $width) = each($image);
         list($key, $height) = each($image);
         $image = imagecreatetruecolor($width, $height);
     } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
         $image = $type == IMAGETYPE_GIF ? @imagecreatefromgif($image) : ($type == IMAGETYPE_WBMP ? @imagecreatefromwbmp($image) : ($type == IMAGETYPE_JPEG ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_JPEG2000 ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_PNG ? imagecreatefrompng($image) : ($type == IMAGETYPE_XBM ? @imagecreatefromxbm($image) : false)))));
         if ($type == IMAGETYPE_PNG) {
             imagealphablending($image, false);
         }
     }
     $return = is_resource($image) && get_resource_type($image) == "gd" && isset($width) && isset($height) && preg_match('/^[1-9][0-9]*$/', $width) !== false && preg_match('/^[1-9][0-9]*$/', $height) !== false ? array($image, $width, $height) : false;
     if ($return !== false && isset($type)) {
         $this->type = $type;
     }
     return $return;
 }
コード例 #13
0
ファイル: image.php プロジェクト: CrazyBobik/allotaxi.test
 public function setImage($path)
 {
     $info = getimagesize($path);
     if ($info) {
         $this->imageType = $info['mime'];
         $this->originalWidth = $info[0];
         $this->originalHeight = $info[1];
         $this->originalPath = $path;
         switch ($this->imageType) {
             case 'image/gif':
                 $this->gd = imagecreatefromgif($path);
                 break;
             case 'image/jpeg':
                 $this->gd = imagecreatefromjpeg($path);
                 break;
             case 'image/png':
                 $this->gd = imagecreatefrompng($path);
                 break;
             case 'image/wbmp':
                 $this->gd = imagecreatefromwbmp($path);
                 break;
         }
     }
     return $info;
 }
コード例 #14
0
ファイル: image.php プロジェクト: nguyennamtien/appleseed
 public function Convert($pFilename)
 {
     // Retrieve file attributes.
     list($width, $height, $type, $attr) = getimagesize($pFilename);
     // Determine which type of file to convert from.
     switch ($type) {
         case IMAGETYPE_PNG:
             $src_img = imagecreatefrompng($pFilename);
             break;
         case IMAGETYPE_WBMP:
             $src_img = imagecreatefromwbmp($pFilename);
             break;
         case IMAGETYPE_JPEG:
             $src_img = imagecreatefromjpeg($pFilename);
             break;
         case IMAGETYPE_GIF:
             $src_img = imagecreatefromgif($pFilename);
             break;
     }
     // switch
     // Copy the source image.
     $this->_Resource = imagecreatetruecolor($width, $height);
     $result = imagecopy($this->_Resource, $src_img, 0, 0, 0, 0, $width, $height);
     return $result;
 }
コード例 #15
0
 public function prepare()
 {
     if (!isset($this->img['src'])) {
         $this->gifsupport = function_exists('imagegif');
         // if mimetype detected and in imagemap -> change format
         if (class_exists("finfo") && ($finfo = new finfo(FILEINFO_MIME_TYPE))) {
             if ($ftype = @$finfo->file($this->img['filepath'])) {
                 if (array_key_exists($ftype, $this->image_mimetype_map)) {
                     $this->img['format'] = $this->image_mimetype_map[$ftype];
                 }
             }
         }
         // ----- detect image format
         if ($this->img['format'] == 'jpg' || $this->img['format'] == 'jpeg') {
             $this->img['format'] = 'jpeg';
             $this->img['src'] = @imagecreatefromjpeg($this->img['filepath']);
         } elseif ($this->img['format'] == 'png') {
             $this->img['src'] = @imagecreatefrompng($this->img['filepath']);
             imagealphablending($this->img['src'], false);
             imagesavealpha($this->img['src'], true);
         } elseif ($this->img['format'] == 'gif') {
             if ($this->gifsupport) {
                 $this->img['src'] = @imagecreatefromgif($this->img['filepath']);
             }
         } elseif ($this->img['format'] == 'wbmp') {
             $this->img['src'] = @imagecreatefromwbmp($this->img['filepath']);
         }
         if (isset($this->img['src'])) {
             $this->refreshDimensions();
         }
     }
 }
コード例 #16
0
ファイル: simpleimage.php プロジェクト: GallardoAlba/Meneame
 function load($filename)
 {
     $image_info = getimagesize($filename);
     $this->image_type = $image_info[2];
     $this->filename = $filename;
     switch ($this->image_type) {
         case IMAGETYPE_JPEG:
             $this->image = @imagecreatefromjpeg($filename);
             break;
         case IMAGETYPE_GIF:
             $this->image = @imagecreatefromgif($filename);
             break;
         case IMAGETYPE_PNG:
             $this->image = @imagecreatefrompng($filename);
             break;
         case IMAGETYPE_WBMP:
             $this->image = @imagecreatefromwbmp($filename);
             break;
         default:
             $this->image = false;
     }
     if ($this->image) {
         $this->extension = @image_type_to_extension($this->image_type, false);
         return true;
     } else {
         $this->extension = '';
         syslog(LOG_INFO, "SimpleImage::load(): Image not loaded, {$filename}, {$this->image_type}");
         return false;
     }
 }
コード例 #17
0
 function prepare()
 {
     if (!isset($this->img['src'])) {
         // ----- gif support ?
         $this->gifsupport = function_exists('imagegif');
         // ----- detect image format
         $this->img['src'] = false;
         if ($this->img['format'] == 'JPG' || $this->img['format'] == 'JPEG') {
             // --- JPEG
             $this->img['format'] = 'JPEG';
             $this->img['src'] = @imagecreatefromjpeg($this->img["filepath"]);
         } elseif ($this->img['format'] == 'PNG') {
             // --- PNG
             $this->img['src'] = @imagecreatefrompng($this->img["filepath"]);
         } elseif ($this->img['format'] == 'GIF') {
             // --- GIF
             if ($this->gifsupport) {
                 $this->img['src'] = @imagecreatefromgif($this->img["filepath"]);
             }
         } elseif ($this->img['format'] == 'WBMP') {
             // --- WBMP
             $this->img['src'] = @imagecreatefromwbmp($this->img["filepath"]);
         }
         // ggf error image senden
         if (!$this->img['src']) {
             $this->sendError('Unable to create gdressource from file "' . $this->img["filepath"] . '"!');
             exit;
         } else {
             $this->refreshDimensions();
         }
     }
 }
コード例 #18
0
function do_image_open_wrapped($filename)
{
    // FIXME: it will definitely cause problems;
    global $g_config;
    if (!$g_config['renderimages']) {
        return null;
    }
    // get the information about the image
    if (!($data = @getimagesize($filename))) {
        return null;
    }
    switch ($data[2]) {
        case 1:
            // GIF
            // Handle lack of GIF support in older versions of PHP
            if (function_exists('imagecreatefromgif')) {
                return @imagecreatefromgif($filename);
            } else {
                return null;
            }
        case 2:
            // JPG
            return @imagecreatefromjpeg($filename);
        case 3:
            // PNG
            $image = @imagecreatefrompng($filename);
            //     imagealphablending($image, false);
            //     imagesavealpha($image, true);
            return $image;
        case 15:
            // WBMP
            return @imagecreatefromwbmp($filename);
    }
    return null;
}
コード例 #19
0
ファイル: functions.php プロジェクト: arkosoft/sitoweb-sadmin
function resize($src,$dst,$dstw,$dsth,$scala,$percorsosave) {

	$src = $percorsosave.$src;
	$dst = $percorsosave.$dst;
	list($width, $height, $type, $attr) = getimagesize($src);
    switch($type){
      case 1:$im = imagecreatefromgif($src);break;
      case 2:$im = imagecreatefromjpeg($src);break;
      case 3:$im = imagecreatefrompng($src);break;
      case 8:$im = imagecreatefromwbmp($src);break;
      default:break;
    }
	If ($dstw == "0" && $dsth == "0") { 
			$dstw = $width;
			$dsth = $height;
	}
	switch($scala){
		//scala in base alla lunghezza
		case 1:
			$dsth=($height*$dstw)/$width;
			break;
		//scala in base all'altezza
		case 2:
			$dstw=($width*$dsth)/$height;
			break;
		default:break;
	};
	$tim = imagecreatetruecolor($dstw,$dsth);	
    imagesavealpha($tim,true);
    imagealphablending($tim,false);
    imagecopyresampled($tim,$im,0,0,0,0,$dstw,$dsth,$width,$height);
    ImageJPEG($tim,$dst,90);
    imagedestroy($tim);
}
コード例 #20
0
ファイル: Image.php プロジェクト: hisaboh/w2t
 /**
  * ファイル名から新規インスタンスを返す
  *
  * @param string $filename
  * @return Image
  */
 public static function load($filename)
 {
     $size = getimagesize($filename);
     if ($size === false) {
         throw new Exception("invalid data");
     }
     $self = new self();
     switch ($size[2]) {
         case IMAGETYPE_GIF:
             $self->resource(imagecreatefromgif($filename), IMAGETYPE_GIF);
             break;
         case IMAGETYPE_JPEG:
             $self->resource(imagecreatefromjpeg($filename), IMAGETYPE_JPEG);
             break;
         case IMAGETYPE_PNG:
             $self->resource(imagecreatefrompng($filename), IMAGETYPE_PNG);
             break;
         case IMAGETYPE_WBMP:
             $self->resource(imagecreatefromwbmp($filename), IMAGETYPE_WBMP);
             break;
         default:
             throw new Exception("invalid data");
     }
     return $self;
 }
コード例 #21
0
ファイル: File.php プロジェクト: demouth/dmimage
 /**
  * コンストラクタ。
  * @param int 画像幅(px)
  * @param int 画像高さ(px)
  * @param int 背景画像色 例:0x0099FF
  */
 public function __construct($filePath)
 {
     $fileType = exif_imagetype($filePath);
     if ($fileType === IMAGETYPE_GIF) {
         $imageResource = imagecreatefromgif($filePath);
     } else {
         if ($fileType === IMAGETYPE_JPEG) {
             $imageResource = imagecreatefromjpeg($filePath);
         } else {
             if ($fileType === IMAGETYPE_PNG) {
                 $imageResource = imagecreatefrompng($filePath);
             } else {
                 if ($fileType === IMAGETYPE_WBMP) {
                     $imageResource = imagecreatefromwbmp($filePath);
                 } else {
                     throw new Exception('file type error. ' . $filePath . ' is not supported image file.');
                 }
             }
         }
     }
     $imageSize = getimagesize($filePath);
     $width = $imageSize[0];
     $height = $imageSize[1];
     $this->graphics = new Dm_Image_Graphic_Shape($imageResource, $width, $height);
     $this->textGraphics = new Dm_Image_Graphic_Text($imageResource, $width, $height);
     $this->_imageResource = $imageResource;
     $this->_width = $width;
     $this->_height = $height;
     //背景色設定(透過を有効化)
     imagesavealpha($imageResource, true);
 }
コード例 #22
0
ファイル: Paint.php プロジェクト: moust/paint
 public function input($input)
 {
     // if is not a string, not an existing file or not a file ressource
     if (!is_string($input) || !file_exists($input) || !is_file($input)) {
         throw new \InvalidArgumentException('Input file is not a valid ressource.');
     }
     $this->inputPath = $input;
     list($this->inputWidth, $this->inputHeight, $this->inputType) = getimagesize($input);
     switch ($this->inputType) {
         case IMAGETYPE_GIF:
             if (!function_exists('imagecreatefromgif')) {
                 throw new CapabilityException('GIF is not supported.');
             }
             $this->input = imagecreatefromgif($input);
             break;
         case IMAGETYPE_JPEG:
             if (!function_exists('imagecreatefromjpeg')) {
                 throw new CapabilityException('JPEG is not supported.');
             }
             $this->input = imagecreatefromjpeg($input);
             break;
         case IMAGETYPE_PNG:
             if (!function_exists('imagecreatefrompng')) {
                 throw new CapabilityException('PNG is not supported.');
             }
             $this->input = imagecreatefrompng($input);
             break;
         case IMAGETYPE_WBMP:
             if (!function_exists('imagecreatefromwbmp')) {
                 throw new CapabilityException('WBMP is not supported.');
             }
             $this->input = imagecreatefromwbmp($input);
             break;
             // Not supported yet in PHP 5.5. WebP is supported since in PHP 5.5 (https://bugs.php.net/bug.php?id=65038)
         // Not supported yet in PHP 5.5. WebP is supported since in PHP 5.5 (https://bugs.php.net/bug.php?id=65038)
         case defined('IMAGETYPE_WEBP') && IMAGETYPE_WEBP:
             if (!function_exists('imagecreatefromwebp')) {
                 throw new CapabilityException('WebP is not supported.');
             }
             $this->input = imagecreatefromwebp($input);
             break;
         case IMAGETYPE_XBM:
             if (!function_exists('imagecreatefromxbm')) {
                 throw new CapabilityException('XBM is not supported.');
             }
             $this->input = imagecreatefromxbm($input);
             break;
         case defined('IMAGETYPE_WEBP') && IMAGETYPE_XPM:
             if (!function_exists('imagecreatefromxpm')) {
                 throw new CapabilityException('XPM is not supported.');
             }
             $this->input = imagecreatefromxpm($input);
             break;
         default:
             throw new CapabilityException('Unsupported input file type.');
             break;
     }
     $this->applyExifTransformations($this->input);
 }
コード例 #23
0
ファイル: image.php プロジェクト: highchair/hcd-trunk
function open_image($file)
{
    list($width, $height, $type, $attr) = getimagesize($file);
    //echo "Type: ".$type."<br />";
    // http://www.php.net/manual/en/function.exif-imagetype.php
    /*1	IMAGETYPE_GIF
      2	IMAGETYPE_JPEG
      3	IMAGETYPE_PNG
      4	IMAGETYPE_SWF
      5	IMAGETYPE_PSD
      6	IMAGETYPE_BMP
      7	IMAGETYPE_TIFF_II (intel byte order)
      8	IMAGETYPE_TIFF_MM (motorola byte order)
      9	IMAGETYPE_JPC
      10	IMAGETYPE_JP2
      11	IMAGETYPE_JPX
      12	IMAGETYPE_JB2
      13	IMAGETYPE_SWC
      14	IMAGETYPE_IFF
      15	IMAGETYPE_WBMP
      16	IMAGETYPE_XBM
      17	IMAGETYPE_ICO */
    if ($type == 2) {
        $im = @imagecreatefromjpeg($file);
    } elseif ($type == 1) {
        $im = @imagecreatefromgif($file);
    } elseif ($type == 3) {
        $im = @imagecreatefrompng($file);
    } elseif ($type == 15) {
        $im = @imagecreatefromwbmp($file);
    } elseif ($type == 6) {
        $im = @imagecreatefrombmp($file);
    } elseif ($type == 16) {
        $im = @imagecreatefromxbm($file);
    } else {
        $im = @imagecreatefromstring(file_get_contents($file));
    }
    /*if ( $type == IMAGETYPE_JPEG ) {
         	$im = @imagecreatefromjpeg($file); 
     	} elseif ( $type == IMAGETYPE_GIF ) {
         	$im = @imagecreatefromgif($file);
     	} elseif ( $type == IMAGETYPE_PNG ) {
         	$im = @imagecreatefrompng($file);
     	} elseif ( $type == IMAGETYPE_WBMP ) {
         	$im = @imagecreatefromwbmp($file);
     	} elseif ( $type == IMAGETYPE_BMP ) {
         	$im = @imagecreatefrombmp($file);
     	} elseif ( $type == IMAGETYPE_XBM ) {
         	$im = @imagecreatefromxbm($file);
     	} else {
         	$im = @imagecreatefromstring(file_get_contents($file));
     	}*/
    if ($im !== false) {
        return $im;
    } else {
        die(throwError("Unable to open_image"));
    }
    return false;
}
コード例 #24
0
ファイル: Image.php プロジェクト: moust/paint
 /**
  * Create image ressource from filename.
  *
  * @param string Path to the image.
  * @return void
  **/
 protected function create($filename)
 {
     $this->filename = $filename;
     // if is not a string, not an existing file or not a file ressource
     if (!is_string($this->filename) || !file_exists($this->filename) || !is_file($this->filename)) {
         throw new \InvalidArgumentException('Filename is not a valid ressource.');
     }
     switch (exif_imagetype($this->filename)) {
         case IMAGETYPE_GIF:
             if (!function_exists('imagecreatefromgif')) {
                 throw new CapabilityException('GIF is not supported.');
             }
             $this->image = imagecreatefromgif($this->filename);
             break;
         case IMAGETYPE_JPEG:
             if (!function_exists('imagecreatefromjpeg')) {
                 throw new CapabilityException('JPEG is not supported.');
             }
             $this->image = imagecreatefromjpeg($this->filename);
             break;
         case IMAGETYPE_PNG:
             if (!function_exists('imagecreatefrompng')) {
                 throw new CapabilityException('PNG is not supported.');
             }
             $this->image = imagecreatefrompng($this->filename);
             break;
         case IMAGETYPE_WBMP:
             if (!function_exists('imagecreatefromwbmp')) {
                 throw new CapabilityException('WBMP is not supported.');
             }
             $this->image = imagecreatefromwbmp($this->filename);
             break;
             // Not supported yet in PHP 5.5. WebP is supported since in PHP 5.5 (https://bugs.php.net/bug.php?id=65038)
         // Not supported yet in PHP 5.5. WebP is supported since in PHP 5.5 (https://bugs.php.net/bug.php?id=65038)
         case defined('IMAGETYPE_WEBP') && IMAGETYPE_WEBP:
             if (!function_exists('imagecreatefromwebp')) {
                 throw new CapabilityException('WebP is not supported.');
             }
             $this->image = imagecreatefromwebp($this->filename);
             break;
         case IMAGETYPE_XBM:
             if (!function_exists('imagecreatefromxbm')) {
                 throw new CapabilityException('XBM is not supported.');
             }
             $this->image = imagecreatefromxbm($this->filename);
             break;
         case defined('IMAGETYPE_WEBP') && IMAGETYPE_XPM:
             if (!function_exists('imagecreatefromxpm')) {
                 throw new CapabilityException('XPM is not supported.');
             }
             $this->image = imagecreatefromxpm($this->filename);
             break;
         default:
             throw new CapabilityException('Unsupported input file type.');
             break;
     }
     $this->setWidth(imagesx($this->image));
     $this->setHeight(imagesy($this->image));
 }
コード例 #25
0
function resize($filename, $size, $quality)
{
    $dir = UPLOADDIR;
    // Адрес директории для сохранения картинки
    $ext = strtolower(strrchr(basename($filename), "."));
    // Получаем формат уменьшаемого изображения
    $extentions = array('.jpg', '.gif', '.png', '.bmp');
    // Определяем формат уменьшаемой картинки
    if (in_array($ext, $extentions)) {
        echo '01';
        $percent = $size;
        // Ширина изображения миниатюры
        list($width, $height) = getimagesize(UPLOADDIR . $filename);
        // Возвращает ширину и высоту картинки
        $newheight = $height * $percent;
        $newwidth = $newheight / $width;
        $thumb = imagecreatetruecolor($percent, $newwidth);
        switch ($ext) {
            case '.jpg':
                $source = @imagecreatefromjpeg(UPLOADDIR . $filename);
                break;
            case '.gif':
                $source = @imagecreatefromgif(UPLOADDIR . $filename);
                break;
            case '.png':
                $source = @imagecreatefrompng(UPLOADDIR . $filename);
                break;
            case '.bmp':
                $source = @imagecreatefromwbmp(UPLOADDIR . $filename);
                break;
        }
        // php уменьшение изображения
        imagecopyresized($thumb, $source, 0, 0, 0, 0, $percent, $newwidth, $width, $height);
        // Создаем изображение
        switch ($ext) {
            case '.jpg':
                imagejpeg($thumb, UPLOADDIR . "min_" . $filename, $quality);
                // Для JPEG картинок
                break;
            case '.gif':
                imagegif($thumb, UPLOADDIR . $filename);
                // Для GIF картинки
                break;
            case '.png':
                imagepng($thumb, UPLOADDIR . $filename, $quality);
                // Для PNG картинок
                break;
            case '.bmp':
                imagewbmp($thumb, UPLOADDIR . $filename);
                // Для BMP картинки
                break;
        }
    } else {
        return 'typeError';
    }
    @imagedestroy($thumb);
    @imagedestroy($source);
    return $filename;
}
コード例 #26
0
ファイル: utility.php プロジェクト: jundl77/FamShare
/**
 * Make a thumbnail of a newly uploaded file if it is an image
 *
 * @param $src the source of the file
 * @param $dest where to save the thumbnail
 * @param $fileExt the file extension (to check if the file is an image)
 * @param $desired_width the desired width of the thumbnail, height and width are kept in ratio
 */
function make_thumb($src, $dest, $fileExt, $desired_width)
{
    $exif = exif_read_data($src, 'IFD0');
    // Read the source image
    if ($fileExt == 'gif') {
        $source_image = imagecreatefromgif($src);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        $source_image = imagecreatefromjpeg($src);
    } elseif ($fileExt == 'png') {
        $source_image = imagecreatefrompng($src);
    } elseif ($fileExt == 'wbmp') {
        $source_image = imagecreatefromwbmp($src);
    } else {
        // Return if not an image
        return;
    }
    // Fix Orientation of original image - this has to be done because of stupid apple products who can't save their
    // orientation like everybody else, ugh!
    switch ($exif['Orientation']) {
        case 3:
            $source_image = imagerotate($source_image, 180, 0);
            break;
        case 6:
            $source_image = imagerotate($source_image, -90, 0);
            break;
        case 8:
            $source_image = imagerotate($source_image, 90, 0);
            break;
    }
    // Save turned source image again (overwrites false orientation)
    if ($fileExt == 'gif') {
        imagegif($source_image, $src);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        imagejpeg($source_image, $src);
    } elseif ($fileExt == 'png') {
        imagepng($source_image, $src);
    } elseif ($fileExt == 'bmp') {
        imagewbmp($source_image, $src);
    }
    $width = imagesx($source_image);
    $height = imagesy($source_image);
    // Find the "desired height" of this thumbnail, relative to the desired width
    $desired_height = floor($height * ($desired_width / $width));
    // Create a new, "virtual" image
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);
    // Copy source image at a resized size
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
    // Create the physical thumbnail image to its destination
    if ($fileExt == 'gif') {
        imagegif($virtual_image, $dest);
    } elseif ($fileExt == 'jpg' || $fileExt == 'jpeg') {
        imagejpeg($virtual_image, $dest);
    } elseif ($fileExt == 'png') {
        imagepng($virtual_image, $dest);
    } elseif ($fileExt == 'bmp') {
        imagewbmp($virtual_image, $dest);
    }
}
コード例 #27
0
 protected function _convertFrameToGif($frame_path)
 {
     $gif_path = null;
     //			first try with imagemagick convert as imagemaigk produces better gifs
     if ($this->_config->convert) {
         $process = new ProcessBuilder('convert', $this->_config);
         $exec = $process->add($frame_path)->add($frame_path . '.convert-convert.gif')->getExecBuffer();
         $exec->setBlocking(true)->execute();
         if ($exec->hasError() === true) {
             throw new Exception('When attempting to convert "' . $frame_path . '" to a gif, convert encountered an error. Convert reported: ' . $exec->getLastLine());
         }
         $gif_path = $frame_path . '.convert-convert.gif';
     }
     //			if we still have no gif path then try with php gd.
     if (empty($gif_path) === true) {
         if (function_exists('imagegif') === false) {
             throw new Exception('PHP GD\'s function `imagegif` is not available, as a result the frame could not be added.');
         }
         $im = false;
         $data = getimagesize($frame_path);
         switch ($data['mime']) {
             case 'image/jpeg':
                 $im = @imagecreatefromjpeg($frame_path);
                 break;
             case 'image/png':
                 $im = @imagecreatefrompng($frame_path);
                 break;
             case 'image/xbm':
                 $im = @imagecreatefromwbmp($frame_path);
                 break;
             case 'image/xpm':
                 $im = @imagecreatefromxpm($frame_path);
                 break;
         }
         if ($im === false) {
             throw new Exception('Unsupported image type.');
         }
         //				save as a gif
         $gif_path = $frame_path . '.convert-php.gif';
         if (imagegif($im, $gif_path) === false) {
             throw new Exception('Unable to convert frame to gif using PHP GD.');
         }
         imagedestroy($im);
     }
     if (empty($gif_path) === true) {
         throw new Exception('Unable to convert frame to gif.');
     } else {
         if (is_file($gif_path) === false) {
             throw new Exception('Unable to convert frame to gif, however the gif conversion path was set.');
         } else {
             if (filesize($gif_path) === 0) {
                 throw new Exception('Unable to convert frame to gif, as a gif was produced, however it was a zero byte file.');
             }
         }
     }
     array_push($this->_tidy_up_gifs, $gif_path);
     return $gif_path;
 }
コード例 #28
0
ファイル: utils.php プロジェクト: kmklr72/lmms.io
function scale_image($url, $width, $extension = null)
{
    if ($extension == null) {
        $extension = parse_extension($url);
    }
    $lsp_image = is_lsp_image($url);
    if ($lsp_image !== false) {
        global $DATA_DIR;
        include_once 'lsp/dbo.php';
        $url = "{$DATA_DIR}{$lsp_image}";
    }
    ini_set('user_agent', 'gd/2.x (linux)');
    $image = NULL;
    try {
        switch ($extension) {
            case '.jpg':
            case '.jpeg':
                $image = @imagecreatefromjpeg($url);
                break;
            case '.gif':
                $image = @imagecreatefromgif($url);
                break;
            case '.bmp':
                $image = @imagecreatefromwbmp($url);
                break;
            case '.png':
            default:
                $image = @imagecreatefrompng($url);
                break;
        }
    } catch (Exception $e) {
        return $url;
    }
    if ($image === false) {
        return $url;
    }
    $orig_width = imagesx($image);
    $orig_height = imagesy($image);
    if ($orig_width < $width) {
        return $url;
    }
    // Calc the new height
    $height = $orig_height * $width / $orig_width;
    // Create new image to display
    $new_image = imagecreatetruecolor($width, $height);
    imagealphablending($new_image, false);
    imagesavealpha($new_image, true);
    // Create new image with changed dimensions
    imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);
    // Capture object to memory
    ob_start();
    //header( "Content-type: image/jpeg" );
    imagepng($new_image);
    imagedestroy($new_image);
    $i = ob_get_clean();
    return 'data:image/png;base64,' . base64_encode($i) . '"';
}
コード例 #29
0
 /**
  * Read image
  *
  * @param   string uri
  * @return  resource
  * @throws  img.ImagingException
  */
 public function readImageFromUri($uri)
 {
     if (false === ($r = imagecreatefromwbmp($uri))) {
         $e = new \img\ImagingException('Cannot read image from "' . $uri . '"');
         \xp::gc(__FILE__);
         throw $e;
     }
     return $r;
 }
コード例 #30
-1
ファイル: Tool.php プロジェクト: ideatic/tinyfier
 private function _load_image($path)
 {
     list($w, $h, $type) = getimagesize($path);
     switch ($type) {
         case IMAGETYPE_GIF:
             $this->_format = 'gif';
             return imagecreatefromgif($path);
         case IMAGETYPE_JPEG:
             $this->_format = 'jpg';
             return imagecreatefromjpeg($path);
         case IMAGETYPE_PNG:
             $this->_format = 'png';
             return imagecreatefrompng($path);
         case IMAGETYPE_SWF:
             $this->_format = 'swf';
             return imagecreatefromswf($path);
         case IMAGETYPE_WBMP:
             $this->_format = 'wbmp';
             return imagecreatefromwbmp($path);
         case IMAGETYPE_XBM:
             $this->_format = 'xbm';
             return imagecreatefromxbm($path);
         default:
             return imagecreatefromstring(file_get_contents($path));
     }
     return false;
 }