Example #1
1
 static function load($filename)
 {
     $info = getimagesize($filename);
     list($width, $height) = $info;
     if (!$width || !$height) {
         return null;
     }
     $image = null;
     switch ($info['mime']) {
         case 'image/gif':
             $image = imagecreatefromgif($filename);
             break;
         case 'image/jpeg':
             $image = imagecreatefromjpeg($filename);
             break;
         case 'image/png':
             $image = imagecreatetruecolor($width, $height);
             $white = imagecolorallocate($image, 255, 255, 255);
             imagefill($image, 0, 0, $white);
             $png = imagecreatefrompng($filename);
             imagealphablending($png, true);
             imagesavealpha($png, true);
             imagecopy($image, $png, 0, 0, 0, 0, $width, $height);
             imagedestroy($png);
             break;
     }
     if ($image) {
         return new image($image, $width, $height);
     } else {
         return null;
     }
 }
function convertImage($originalImage, $outputImage, $quality = 100)
{
    $myfile = fopen($outputImage, "w");
    // jpg, png, gif or bmp?
    $exploded = explode('.', $originalImage);
    $ext = $exploded[count($exploded) - 1];
    if (preg_match('/jpg|jpeg/i', $ext)) {
        $imageTmp = imagecreatefromjpeg($originalImage);
    } else {
        if (preg_match('/png/i', $ext)) {
            $imageTmp = imagecreatefrompng($originalImage);
        } else {
            if (preg_match('/gif/i', $ext)) {
                $imageTmp = imagecreatefromgif($originalImage);
            } else {
                if (preg_match('/bmp/i', $ext)) {
                    $imageTmp = imagecreatefrombmp($originalImage);
                } else {
                    return 0;
                }
            }
        }
    }
    imagejpeg($imageTmp, $outputImage, $quality);
    imagedestroy($imageTmp);
    return $outputImage;
}
 /**
  * Loads image source and its properties to the instanciated object
  *
  * @param string $filename
  * @return ImageResize
  * @throws \Exception
  */
 public function __construct($filename)
 {
     $image_info = @getimagesize($filename);
     if (!$image_info) {
         throw new \Exception('Could not read file');
     }
     list($this->original_w, $this->original_h, $this->source_type) = $image_info;
     switch ($this->source_type) {
         case IMAGETYPE_GIF:
             $this->source_image = imagecreatefromgif($filename);
             break;
         case IMAGETYPE_JPEG:
             $this->source_image = $this->imageCreateJpegfromExif($filename);
             // set new width and height for image, maybe it has changed
             $this->original_w = ImageSX($this->source_image);
             $this->original_h = ImageSY($this->source_image);
             break;
         case IMAGETYPE_PNG:
             $this->source_image = imagecreatefrompng($filename);
             break;
         default:
             throw new \Exception('Unsupported image type');
             break;
     }
     return $this->resize($this->getSourceWidth(), $this->getSourceHeight());
 }
 /**
  * MÉTODO CONSTRUTOR
  *
  * @author Gibran
  */
 function Imagem($arquivo)
 {
     if (is_file($arquivo)) {
         $this->Arquivo = $arquivo;
         // OBTÉM OS DADOS DA IMAGEM
         $this->ColecaoDados = getimagesize($this->Arquivo);
         // CARREGA A IMAGEM DE ACORDO COM O TIPO
         switch ($this->ColecaoDados[2]) {
             case 1:
                 $this->Recurso = imagecreatefromgif($this->Arquivo);
                 $this->Tipo = "image/gif";
                 break;
             case 2:
                 $this->Recurso = imagecreatefromjpeg($this->Arquivo);
                 $this->Tipo = "image/jpeg";
                 imageinterlace($this->Recurso, true);
                 break;
             case 3:
                 $this->Recurso = imagecreatefrompng($this->Arquivo);
                 $this->Tipo = "image/png";
                 imagealphablending($this->Recurso, false);
                 imagesavealpha($this->Recurso, true);
                 break;
             default:
                 $this->ColecaoDados = null;
                 $this->Recurso = null;
                 $this->Tipo = null;
                 return null;
                 break;
         }
     } else {
         return null;
     }
 }
function mkthumb($img_src, $img_width = "100", $img_height = "100", $folder_scr = "include/files", $des_src = "include/files")
{
    // Größe und Typ ermitteln
    list($src_width, $src_height, $src_typ) = getimagesize($folder_scr . "/" . $img_src);
    if (!$src_typ) {
        return false;
    }
    // calculate new size
    if ($src_width >= $src_height) {
        $new_image_height = $src_height / $src_width * $img_width;
        $new_image_width = $img_width;
        if ($new_image_height > $img_height) {
            $new_image_width = $new_image_width / $new_image_height * $img_height;
            $new_image_height = $img_height;
        }
    } else {
        $new_image_width = $src_width / $src_height * $img_height;
        $new_image_height = $img_height;
        if ($new_image_width > $img_width) {
            $new_image_height = $new_image_height / $new_image_width * $img_width;
            $new_image_width = $img_width;
        }
    }
    // for the case that the thumbnail would be bigger then the original picture
    if ($new_image_height > $src_height) {
        $new_image_width = $new_image_width * $src_height / $new_image_height;
        $new_image_height = $src_height;
    }
    if ($new_image_width > $src_width) {
        $new_image_height = $new_image_height * $new_image_width / $src_width;
        $new_image_width = $src_width;
    }
    if ($src_typ == 1) {
        $image = imagecreatefromgif($folder_scr . "/" . $img_src);
        $new_image = imagecreate($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagegif($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 2) {
        $image = imagecreatefromjpeg($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagejpeg($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 3) {
        $image = imagecreatefrompng($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagepng($new_image, $des_src . "/" . $img_src . "_thumb");
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } else {
        return false;
    }
}
Example #6
0
 /**
  * @param string $fileName
  * @param array $options
  * @param array $plugins
  */
 public function __construct($fileName, $options = array(), array $plugins = array())
 {
     parent::__construct($fileName, $options, $plugins);
     $this->determineFormat();
     $this->verifyFormatCompatiblity();
     switch ($this->format) {
         case 'GIF':
             $this->oldImage = @imagecreatefromgif($this->fileName);
             break;
         case 'JPG':
             $this->oldImage = @imagecreatefromjpeg($this->fileName);
             break;
         case 'PNG':
             $this->oldImage = @imagecreatefrompng($this->fileName);
             break;
         case 'STRING':
             $this->oldImage = @imagecreatefromstring($this->fileName);
             break;
     }
     if (!is_resource($this->oldImage)) {
         throw new \Exception('Invalid image file');
     } else {
         $this->currentDimensions = array('width' => imagesx($this->oldImage), 'height' => imagesy($this->oldImage));
     }
 }
Example #7
0
 private function createnewpicture()
 {
     $local = $this->path_two . $this->file['name'];
     move_uploaded_file($this->file['tmp_name'], $local);
     $filename = $this->file['tmp_name'] . "/" . $this->file['name'];
     $this->location = $this->path . "/" . $this->file['name'];
     switch ($this->file['type']) {
         case 'image/jpeg':
             $src = imagecreatefromjpeg($local);
             break;
         case 'image/png':
             $src = imagecreatefrompng($local);
             break;
         case 'image/gif':
             $src = imagecreatefromgif($local);
             break;
         default:
             break;
     }
     $sx = imagesx($src);
     $sy = imagesy($src);
     $new_image = imagecreatetruecolor($this->newwidth, $this->newheight);
     if (imagecopyresized($new_image, $src, 0, 0, 0, 0, $this->newwidth, $this->newheight, $sx, $sy)) {
         if (ImageJpeg($new_image, $this->location) || Imagegif($new_image, $this->location) || Imagepng($new_image, $this->location)) {
             //imagejpeg($this->location);
             return true;
         }
     } else {
         return false;
     }
 }
 static function resizewidth($width, $imageold, $imagenew)
 {
     $image_info = getimagesize($imageold);
     $image_type = $image_info[2];
     if ($image_type == IMAGETYPE_JPEG) {
         $image = imagecreatefromjpeg($imageold);
     } elseif ($this->image_type == IMAGETYPE_GIF) {
         $image = imagecreatefromgif($imageold);
     } elseif ($this->image_type == IMAGETYPE_PNG) {
         $image = imagecreatefrompng($imageold);
     }
     $ratio = imagesy($image) / imagesx($image);
     $height = $width * $ratio;
     //$width = imagesx($image) * $width/100;
     // $height = imagesx($image) * $width/100;
     $new_image = imagecreatetruecolor($width, $height);
     imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image_info[0], $image_info[1]);
     $image = $new_image;
     $compression = 75;
     $permissions = null;
     if ($image_type == IMAGETYPE_JPEG) {
         imagejpeg($image, $imagenew, $compression);
     } elseif ($image_type == IMAGETYPE_GIF) {
         imagegif($image, $imagenew);
     } elseif ($image_type == IMAGETYPE_PNG) {
         imagepng($image, $imagenew);
     }
     if ($permissions != null) {
         chmod($imagenew, $permissions);
     }
 }
Example #9
0
function create_thumbnail($filename)
{
    $percent = 0.1;
    list($width, $height) = getimagesize("/var/www/amberandbrice.com/workspace/images/" . $filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $ext = pathinfo($filename)['extension'];
    echo "<h1>{$ext}</h1>";
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
        case 'JPG':
            $source = imagecreatefromjpeg("images/" . $filename);
            imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            imagejpeg($thumb, "./thumbs/" . $filename);
            break;
        case 'gif':
            $source = imagecreatefromgif("images/" . $filename);
            imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            imagejpeg($thumb, "./thumbs/" . $filename);
            break;
        case 'png':
            $source = imagecreatefrompng("images/" . $filename);
            imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            imagejpeg($thumb, "./thumbs/" . $filename);
            break;
        default:
            die("image extension cannot be determined");
    }
}
Example #10
0
 public function getLogo()
 {
     $f_info = pathinfo($this->url_logo);
     $get_w = $this->input->get('w');
     $get_h = $this->input->get('h');
     // Get new sizes
     list($width, $height) = getimagesize($this->url_logo);
     $newwidth = $get_w === FALSE ? $this->size_x : $get_w;
     $newheight = $get_h === FALSE ? $this->size_y : $get_h;
     $thumb = imagecreatetruecolor($newwidth, $newheight);
     //compress picture size
     if (strtolower($f_info['extension']) == 'jpg') {
         $image = imagecreatefromjpeg($this->url_logo);
         $call = 'imagejpeg';
         $content = 'image/jpeg';
     }
     if (strtolower($f_info['extension']) == 'png') {
         $image = imagecreatefrompng($this->url_logo);
         $call = 'imagepng';
         $content = 'image/jpeg';
     }
     if (strtolower($f_info['extension']) == 'gif') {
         $image = imagecreatefromgif($this->url_logo);
         $call = 'imagegif';
         $content = 'image/gif';
     }
     @header('Content-Type : ' . $content);
     imagecopyresized($thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     call_user_func($call, $thumb);
     imagedestroy($thumb);
 }
 public function open($file)
 {
     $this->close();
     // *** Get extension
     $extension = strtolower(strrchr($file, '.'));
     switch ($extension) {
         case '.jpg':
         case '.jpeg':
             $this->image = @imagecreatefromjpeg($file);
             break;
         case '.gif':
             $this->image = @imagecreatefromgif($file);
             break;
         case '.png':
             $this->image = @imagecreatefrompng($file);
             break;
         default:
             $this->image = FALSE;
             break;
     }
     if ($this->image !== FALSE) {
         // *** Get width and height
         $this->width = imagesx($this->image);
         $this->height = imagesy($this->image);
     }
     return $this->image;
 }
Example #12
0
 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;
 }
Example #13
0
 function resizeThumbnailImage($thumb, $image, $width, $height, $start_width, $start_height, $scale)
 {
     $newImageWidth = ceil($width * $scale);
     $newImageHeight = ceil($height * $scale);
     $newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
     $ext = strtolower(substr(basename($image), strrpos(basename($image), '.') + 1));
     $source = '';
     if ($ext == 'png') {
         $source = imagecreatefrompng($image);
     } elseif ($ext == 'jpg' || $ext == 'jpeg') {
         $source = imagecreatefromjpeg($image);
     } elseif ($ext == 'gif') {
         $source = imagecreatefromgif($image);
     }
     imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
     $ext = strtolower(substr(basename($thumb), strrpos(basename($thumb), '.') + 1));
     if ($ext == 'png') {
         $result = imagepng($newImage, $thumb, 0);
     } elseif ($ext == 'jpg' || $ext == 'jpeg') {
         $result = imagejpeg($newImage, $thumb, 90);
     } elseif ($ext == 'gif') {
         $result = imagegif($newImage, $thumb);
     }
     if (!$result) {
         return false;
     }
     chmod($thumb, 0664);
     return $thumb;
 }
Example #14
0
 public function load($path, $extension = null, $content = null)
 {
     global $F;
     $this->destroy();
     $this->path = $path;
     if (is_null($extension)) {
         $extension = File::extension($path);
     }
     switch ($extension) {
         default:
         case "jpg":
             $this->resourceID = @imagecreatefromjpeg($path);
             break;
         case "gif":
             $this->resourceID = @imagecreatefromgif($path);
             break;
         case "png":
             $this->resourceID = @imagecreatefrompng($path);
             imagesavealpha($this->resourceID, true);
             break;
         case Image::DATA:
             $this->resourceID = @imagecreatefromstring($content);
             break;
     }
     if ($this->resourceID) {
         $this->width = imagesx($this->resourceID);
         $this->height = imagesy($this->resourceID);
         return true;
     } else {
         return false;
     }
 }
Example #15
0
 public static function create_from($filename)
 {
     $size = @getimagesize($filename);
     if (FALSE == $size) {
         return NULL;
     }
     list($w, $h, $type) = $size;
     $obj = new self();
     switch ($type) {
         // 1 = GIF,2 = JPG,3 = PNG ...
         case 1:
             // gif
             $obj->im = imagecreatefromgif($filename);
             break;
         case 2:
             // jpg
             $obj->im = imagecreatefromjpeg($filename);
             break;
         case 3:
             // png
             $obj->im = imagecreatefrompng($filename);
             break;
         default:
             $obj->im = FALSE;
             break;
     }
     if (FALSE == $obj->im) {
         return NULL;
     }
     return $obj;
 }
Example #16
0
function upload($tmp, $name, $nome, $larguraP, $pasta)
{
    $ext = strtolower(end(explode('.', $name)));
    if ($ext == 'jpg') {
        $img = imagecreatefromjpeg($tmp);
    } elseif ($ext == 'gif') {
        $img = imagecreatefromgif($tmp);
    } else {
        $img = imagecreatefrompng($tmp);
    }
    $x = imagesx($img);
    $y = imagesy($img);
    $largura = $x > $larguraP ? $larguraP : $x;
    $altura = $largura * $y / $x;
    if ($altura > $larguraP) {
        $altura = $larguraP;
        $largura = $altura * $x / $y;
    }
    $nova = imagecreatetruecolor($largura, $altura);
    imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
    imagejpeg($nova, "{$pasta}/{$nome}");
    imagedestroy($img);
    imagedestroy($nova);
    return $nome;
}
Example #17
0
 /**
  * Load an image
  *
  * @param $filename
  * @return Image
  * @throws Exception
  */
 public static function load($filename)
 {
     $instance = new self();
     // Require GD library
     if (!extension_loaded('gd')) {
         throw new Exception('Required extension GD is not loaded.');
     }
     $instance->filename = $filename;
     $info = getimagesize($instance->filename);
     switch ($info['mime']) {
         case 'image/gif':
             $instance->image = imagecreatefromgif($instance->filename);
             break;
         case 'image/jpeg':
             $instance->image = imagecreatefromjpeg($instance->filename);
             break;
         case 'image/png':
             $instance->image = imagecreatefrompng($instance->filename);
             imagesavealpha($instance->image, true);
             imagealphablending($instance->image, true);
             break;
         default:
             throw new Exception('Invalid image: ' . $instance->filename);
             break;
     }
     $instance->original_info = array('width' => $info[0], 'height' => $info[1], 'orientation' => $instance->get_orientation(), 'exif' => function_exists('exif_read_data') ? $instance->exif = @exif_read_data($instance->filename) : null, 'format' => preg_replace('/^image\\//', '', $info['mime']), 'mime' => $info['mime']);
     $instance->width = $info[0];
     $instance->height = $info[1];
     imagesavealpha($instance->image, true);
     imagealphablending($instance->image, true);
     return $instance;
 }
Example #18
0
 /**
  * Set the image variable by using image create
  *
  * @param string $filename - The image filename
  */
 private function setImage($filename)
 {
     $size = getimagesize($filename);
     $this->ext = $size['mime'];
     switch ($this->ext) {
         // Image is a JPG
         case 'image/jpg':
         case 'image/jpeg':
             // create a jpeg extension
             $this->image = imagecreatefromjpeg($filename);
             break;
             // Image is a GIF
         // Image is a GIF
         case 'image/gif':
             $this->image = @imagecreatefromgif($filename);
             break;
             // Image is a PNG
         // Image is a PNG
         case 'image/png':
             $this->image = @imagecreatefrompng($filename);
             break;
             // Mime type not found
         // Mime type not found
         default:
             throw new Exception("File is not an image, please use another file type.", 1);
     }
     $this->origWidth = imagesx($this->image);
     $this->origHeight = imagesy($this->image);
 }
 public static function image($item, $path, $filename)
 {
     $image_tempname1 = $_FILES[$item]['name'];
     $ImageName = $path . $image_tempname1;
     $newfilename = $path . $filename;
     if (move_uploaded_file($_FILES[$item]['tmp_name'], $ImageName)) {
         list($width, $height, $type, $attr) = getimagesize($ImageName);
         if ($type == 2) {
             rename($ImageName, $newfilename);
         } else {
             if ($type == 1) {
                 $image_old = imagecreatefromgif($ImageName);
             } elseif ($type == 3) {
                 $image_old = imagecreatefrompng($ImageName);
             }
             $image_jpg = imagecreatetruecolor($width, $height);
             imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);
             imagejpeg($image_jpg, $newfilename);
             imagedestroy($image_old);
             imagedestroy($image_jpg);
         }
         return 1;
     } else {
         return 0;
     }
 }
Example #20
0
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;
}
 public function fill_watermark()
 {
     $image = $this->editor->get_image();
     $size = $this->editor->get_size();
     list($mask_width, $mask_height, $mask_type, $mask_attr) = getimagesize($this->args['mask']);
     switch ($mask_type) {
         case 1:
             $mask = imagecreatefromgif($this->args['mask']);
             break;
         case 2:
             $mask = imagecreatefromjpeg($this->args['mask']);
             break;
         case 3:
             $mask = imagecreatefrompng($this->args['mask']);
             break;
     }
     imagealphablending($image, true);
     if (strpos($this->args['position'], 'left') !== false) {
         $left = $this->args['padding'];
     } else {
         $left = $size['width'] - $mask_width - $this->args['padding'];
     }
     if (strpos($this->args['position'], 'top') !== false) {
         $top = $this->args['padding'];
     } else {
         $top = $size['height'] - $mask_height - $this->args['padding'];
     }
     imagecopy($image, $mask, $left, $top, 0, 0, $mask_width, $mask_height);
     $this->editor->update_image($image);
     imagedestroy($mask);
 }
Example #22
0
 public function __construct($filepath)
 {
     if (!function_exists('gd_info')) {
         throw new Hayate_Exception(_('GD extension is missing.'));
     }
     if (!is_file($filepath)) {
         throw new Hayate_Exception(sprintf(_('Cannot find %s'), $filepath));
     }
     $this->filepath = $filepath;
     $info = getimagesize($this->filepath);
     if (false === $info) {
         throw new Hayate_Exception(sprintf(_('Cannot read %s'), $filepath));
     }
     list($this->width, $this->height) = $info;
     $mimes = array('image/jpeg' => 'jpg', 'image/pjpeg' => 'jpg', 'image/gif' => 'gif', 'image/png' => 'png');
     $this->ext = isset($mimes[$info['mime']]) ? $mimes[$info['mime']] : null;
     if (null === $this->ext) {
         throw new Hayate_Exception(sprintf(_('Supported mime types are: %s'), implode(',', array_keys($mimes))));
     }
     switch ($this->ext) {
         case 'jpg':
             $this->img = imagecreatefromjpeg($filepath);
             break;
         case 'gif':
             $this->img = imagecreatefromgif($filepath);
             break;
         case 'png':
             $this->img = imagecreatefrompng($filepath);
             break;
     }
 }
Example #23
0
/**
 *  Retourne la couleur du pixel en bas a gauche de l'image
 **/
function colorImageBottom($imageName)
{
    // recuperer le type et la taille de l'image
    // Pb sur certains JPG qui retourne ''
    list($imgW, $imgH, $imgTyp) = getimagesize($imageName);
    switch ($imgTyp) {
        case 1:
            $im = imagecreatefromgif($imageName);
            break;
        case 2:
        case ' ':
            $im = imagecreatefromjpeg($imageName);
            break;
        case 3:
            $im = imagecreatefrompng($imageName);
            break;
        default:
            $app = JFactory::getApplication();
            $app->enqueueMessage(JTEXT::_('IMGNAME_ERROR') . '[name=' . $imageName . '] [ type=' . $imgTyp . '] [ format= ' . $imgW . 'x' . $imgH, 'error');
            var_dump(gd_info());
            return "";
    }
    $rgb = imagecolorat($im, 2, $imgH - 2);
    $hex = sprintf("%06X", $rgb);
    return $hex;
}
Example #24
0
 private function openImage($file)
 {
     // *** Get extension
     $extension = strtolower(strrchr($file, '.'));
     //$extension = DataHandler::returnExtensionOfFile($file);
     switch ($extension) {
         case '.jpg':
         case '.jpeg':
             $img = @imagecreatefromjpeg($file);
             break;
         case '.gif':
             $img = @imagecreatefromgif($file);
             break;
         case '.png':
             $img = @ImageCreateFromPNG($file);
             //                        //abaixo do php.net
             //                        imagealphablending($img, false);
             //						imagesavealpha($img, true);
             break;
         default:
             $img = false;
             break;
     }
     return $img;
 }
Example #25
0
 /** 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;
 }
Example #26
0
             mkdir($dir . $p, 0755);
         }
     }
     return $p;
 }
 private static function _init($file)
 {
     $info = getimagesize($file);
     $method = $im = $ext = null;
     switch ($info['mime']) {
         case 'image/jpeg':
         case 'image/jpg':
             $ext = '.jpg';
             $im = imagecreatefromjpeg($file);
             $method = 'imagejpeg';
             break;
         case 'image/gif':
             $ext = '.gif';
             $im = imagecreatefromgif($file);
             $method = 'imagegif';
             break;
         case 'image/png':
             $ext = '.png';
             $im = imagecreatefrompng($file);
             $method = 'imagepng';
             break;
         case 'image/bmp':
             $ext = '.bmp';
             $im = imagecreatefrombmp($file);
             $method = 'imagepng';
             break;
 private function openImage($file)
 {
     // *** Get extension
     $extension = strtolower(strrchr($file, '.'));
     $file_size = @filesize($file) / 1024 / 1024;
     // magic number convert bytes to mb
     $image_size_limit = 0.5;
     // sorry for the magic numbering... can't get a good read on how to programatically fix this.
     // if we're about to try to load a massive image...
     // don't
     if ($file_size >= $image_size_limit || $file_size == 0) {
         return false;
     }
     switch ($extension) {
         case '.jpg':
         case '.jpeg':
             $img = imagecreatefromjpeg($file);
             break;
         case '.gif':
             $img = @imagecreatefromgif($file);
             break;
         case '.png':
             $img = @imagecreatefrompng($file);
             break;
         default:
             $img = false;
             break;
     }
     return $img;
 }
Example #28
0
function resize($photo_src, $width, $name)
{
    $parametr = getimagesize($photo_src);
    list($width_orig, $height_orig) = getimagesize($photo_src);
    $ratio_orig = $width_orig / $height_orig;
    $new_width = $width;
    $new_height = $width / $ratio_orig;
    $newpic = imagecreatetruecolor($new_width, $new_height);
    $col2 = imagecolorallocate($newpic, 255, 255, 255);
    imagefilledrectangle($newpic, 0, 0, $new_width, $new_width, $col2);
    switch ($parametr[2]) {
        case 1:
            $image = imagecreatefromgif($photo_src);
            break;
        case 2:
            $image = imagecreatefromjpeg($photo_src);
            break;
        case 3:
            $image = imagecreatefrompng($photo_src);
            break;
    }
    imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
    imagejpeg($newpic, $name, 100);
    return true;
}
Example #29
0
function get_image($file)
{
    /*
    	Create a resource from image file and return it with getimagesize() array
    	$file - image file or resource
    	return array('res'=>$image_resource, 'imgsize'=>getimagesize($file))
    */
    if (is_file($file) === true && file_exists($file) === true && is_readable($file) === true) {
        $img_size = getimagesize($file);
        if ($img_size !== false) {
            $im_mime = $img_size['mime'];
            // Get the image from file
            if ($im_mime === 'image/jpeg') {
                $res = imagecreatefromjpeg($file);
            } else {
                if ($im_mime === 'image/gif') {
                    $res = imagecreatefromgif($file);
                } else {
                    if ($im_mime === 'image/png') {
                        $res = imagecreatefrompng($file);
                    } else {
                        // Exit if not supported format
                        return false;
                    }
                }
            }
            return array('res' => $res, 'imgsize' => $img_size);
        }
    }
    return false;
}
Example #30
0
 public function __construct($filename = null, array $options = array(), $binary = false, $type = null)
 {
     $this->filename = $filename;
     $this->remote = false;
     $this->binary = (bool) $binary;
     $this->assertFileAvaiable();
     $this->detectFormat($type);
     if ($this->binary) {
         $this->oldImage = @imagecreatefromstring($this->filename);
     } else {
         switch ($this->format) {
             case self::TYPE_PNG:
                 $this->oldImage = @imagecreatefrompng($this->filename);
                 break;
             case self::TYPE_JPEG:
                 $this->oldImage = @imagecreatefromjpeg($this->filename);
                 break;
             case self::TYPE_GIF:
                 $this->oldImage = @imagecreatefromgif($this->filename);
                 break;
         }
     }
     if (!$this->oldImage) {
         $error = error_get_last();
         throw new \InvalidArgumentException('create image with given resource failed' . ($error ? ' with error ' . $error['message'] : ''));
     }
     $this->currentDimensions = array('width' => imagesx($this->oldImage), 'height' => imagesy($this->oldImage));
     $this->setOptions($options);
 }