Пример #1
0
 function saveLargeThumb($path, $quality, $expectedwidth, $expectedheight = '')
 {
     if ($expectedheight == '') {
         $expectedheight = $expectedwidth;
     }
     list($this->width, $this->height, $type, $attributes) = getimagesize($this->rawImage);
     $this->newwidth1 = $expectedwidth;
     $return = true;
     while ($return) {
         $this->newheight1 = $this->height / $this->width * $this->newwidth1;
         $expectedheight;
         if ($this->newheight1 > $expectedheight) {
             $this->newwidth1 -= 2;
         } elseif ($expectedwidth < 0) {
             $this->newwidth1 = $expectedwidth;
             $this->newheight1 = $expectedheight;
             $return = false;
         } else {
             $return = false;
         }
     }
     if ($this->width > $this->newwidth1) {
         switch ($this->image_type) {
             case 'image/pjpeg':
                 $src = imagecreatefromjpeg($this->rawImage);
                 $tmp = imagecreatetruecolor($this->newwidth1, $this->newheight1);
                 imagecopyresampled($tmp, $src, 0, 0, 0, 0, $this->newwidth1, $this->newheight1, $this->width, $this->height);
                 imagejpeg($tmp, $path . $this->filename, $quality);
                 return $this->filename;
                 break;
             case 'image/jpg':
                 $src = imagecreatefromjpeg($this->rawImage);
                 $tmp = imagecreatetruecolor($this->newwidth1, $this->newheight1);
                 imagecopyresampled($tmp, $src, 0, 0, 0, 0, $this->newwidth1, $this->newheight1, $this->width, $this->height);
                 imagejpeg($tmp, $path . $this->filename, $quality);
                 return $this->filename;
                 break;
             case 'image/jpeg':
                 $src = imagecreatefromjpeg($this->rawImage);
                 $tmp = imagecreatetruecolor($this->newwidth1, $this->newheight1);
                 imagecopyresampled($tmp, $src, 0, 0, 0, 0, $this->newwidth1, $this->newheight1, $this->width, $this->height);
                 imagejpeg($tmp, $path . $this->filename, $quality);
                 return $this->filename;
                 break;
             case 'image/gif':
                 $src = imagecreatefromgif($this->rawImage);
                 $tmp = imagecreatetruecolor($this->newwidth1, $this->newheight1);
                 imagecopyresampled($tmp, $src, 0, 0, 0, 0, $this->newwidth1, $this->newheight1, $this->width, $this->height);
                 imagegif($tmp, $path . $this->filename, $quality);
                 return $this->filename;
                 break;
             case 'image/bmp':
                 $src = imagecreatefromwbmp($this->rawImage);
                 $tmp = imagecreatetruecolor($this->newwidth1, $this->newheight1);
                 imagecopyresampled($tmp, $src, 0, 0, 0, 0, $this->newwidth1, $this->newheight1, $this->width, $this->height);
                 image2wbmp($tmp, $path . $this->filename, $quality);
                 return $this->filename;
                 break;
             case 'image/png':
                 $src = imagecreatefrompng($this->rawImage);
                 $tmp = imagecreatetruecolor($this->newwidth1, $this->newheight1);
                 imagecopyresampled($tmp, $src, 0, 0, 0, 0, $this->newwidth1, $this->newheight1, $this->width, $this->height);
                 imagepng($tmp, $path . $this->filename, $quality ? $quality / 10 : 1);
                 return $this->filename;
                 break;
             default:
                 if ($this->image_type == 'image/bmp' || $this->image_type == 'image/jpeg' || $this->image_type == 'image/jpg' || $this->image_type == 'image/gif' || $this->image_type == 'image/png') {
                     copy($this->rawImage, $path . $this->filename);
                     return $this->filename;
                 }
                 break;
         }
     } else {
         copy($this->rawImage, $path . $this->filename);
         return $this->filename;
     }
 }
 /**
  * Save the image
  * @param string $key
  * @return void
  */
 private function _saveImage($key)
 {
     $output = $this->_output[$key];
     $type = $this->_imagetype;
     $size = $this->_newsize[$key];
     switch ($type) {
         case "gif":
             $im = imagecreatefromgif($this->_file);
             break;
         case "jpg":
             $im = imagecreatefromjpeg($this->_file);
             break;
         case "bmp":
             $im = imagecreatefromwbmp($this->_file);
             break;
         case "png":
             $im = imagecreatefrompng($this->_file);
             break;
         default:
             throw new Exception("Incorrect image type.");
             break;
     }
     if (!$im) {
         throw new Exception("Could not open image file.");
     }
     $newimage = imagecreatetruecolor($size['width'], $size['height']);
     if (!$newimage) {
         throw new Exception("Unable to create new image.");
     }
     $white = imagecolorallocate($newimage, 255, 255, 255);
     imagefill($newimage, 0, 0, $white);
     if (!imagecopyresampled($newimage, $im, 0, 0, 0, 0, $size['width'], $size['height'], $this->_oldsize['width'], $this->_oldsize['height'])) {
         throw new Exception("Unable to copy image.");
     }
     imagedestroy($im);
     $filename = $output['path'] . "/" . $this->_newfilename[$key];
     switch ($type) {
         case "gif":
             if (!imagegif($newimage, $filename)) {
                 throw new Exception("Unable to save new image.");
             }
             break;
         case "jpg":
             if (!imagejpeg($newimage, $filename, 100)) {
                 throw new Exception("Unable to save new image.");
             }
             break;
         case "bmp":
             if (!image2wbmp($newimage, $filename)) {
                 throw new Exception("Unable to save new image.");
             }
             break;
         case "png":
             if (!imagepng($newimage, $filename)) {
                 throw new Exception("Unable to save new image.");
             }
             break;
         default:
             throw new Exception("Incorrect image type.");
             break;
     }
     imagedestroy($newimage);
 }
Пример #3
0
 /**
  * 图片缩放,放大,对gif动画会失去动画效果
  * @param string $path  文件路径
  * @param px $maxwidth 缩放后的宽度  允许百分比缩放
  * @param px $maxheight 缩放后的高度
  * @return string 缩放后的文件的完整路径
  */
 public function resizeImage($path, $width, $height)
 {
     $fileinfo = pathinfo(str_replace('\\', '/', $path));
     //原文件信息
     switch ($fileinfo['extension']) {
         case 'jpeg:':
         case 'jpg':
             $im = imagecreatefromjpeg($path);
             break;
         case 'gif':
             $im = imagecreatefromgif($path);
             break;
         case 'png':
             $im = imagecreatefrompng($path);
             break;
         case 'bmp':
             $im = imagecreatefromwbmp($path);
             break;
     }
     $pic_width = imagesx($im);
     $pic_height = imagesy($im);
     if ($width < 1) {
         $width = $pic_width * $width;
     }
     if ($height < 1) {
         $height = $pic_height * $height;
     }
     $name = $fileinfo['dirname'] . '/' . $fileinfo['filename'] . '_' . $width . 'x' . $height . '.' . $fileinfo['extension'];
     //缩放后文件完整路径
     if ($pic_width != $width || $pic_height != $height) {
         if (function_exists("imagecopyresampled")) {
             $newim = imagecreatetruecolor($width, $height);
             imagecopyresampled($newim, $im, 0, 0, 0, 0, $width, $height, $pic_width, $pic_height);
         } else {
             $newim = imagecreate($width, $height);
             imagecopyresized($newim, $im, 0, 0, 0, 0, $width, $height, $pic_width, $pic_height);
         }
         switch ($fileinfo['extension']) {
             case 'jpeg:':
             case 'jpg':
                 imagejpeg($newim, $name);
                 break;
             case 'gif':
                 imagegif($newim, $name);
                 break;
             case 'bmp':
                 image2wbmp($newim, $name);
                 break;
             case 'png':
                 imagepng($newim, $name);
                 break;
         }
         imagedestroy($newim);
     } else {
         copy($path, $name);
     }
     return $name;
 }
Пример #4
0
/**
 *    	Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
 *      If file is myfile.jpg, new file may be myfile_small.jpg
 *
 *    	@param     string	$file           	Path of source file to resize
 *    	@param     int		$maxWidth       	Largeur maximum que dois faire la miniature (-1=unchanged, 160 by default)
 *    	@param     int		$maxHeight      	Hauteur maximum que dois faire l'image (-1=unchanged, 120 by default)
 *    	@param     string	$extName        	Extension to differenciate thumb file name ('_small', '_mini')
 *    	@param     int		$quality        	Quality of compression (0=worst, 100=best)
 *      @param     string	$outdir           	Directory where to store thumb
 *      @param     int		$targetformat     	New format of target (1,2,3,... or 0 to keep old format)
 *    	@return    string						Full path of thumb or '' if it fails
 */
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small', $quality = 50, $outdir = 'thumbs', $targetformat = 0)
{
    require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
    global $conf, $langs;
    dol_syslog("vignette file=" . $file . " extName=" . $extName . " maxWidth=" . $maxWidth . " maxHeight=" . $maxHeight . " quality=" . $quality . " outdir=" . $outdir . " targetformat=" . $targetformat);
    // Clean parameters
    $file = trim($file);
    // Check parameters
    if (!$file) {
        // Si le fichier n'a pas ete indique
        return 'ErrorBadParameters';
    } elseif (!file_exists($file)) {
        // Si le fichier passe en parametre n'existe pas
        dol_syslog($langs->trans("ErrorFileNotFound", $file), LOG_ERR);
        return $langs->trans("ErrorFileNotFound", $file);
    } elseif (image_format_supported($file) < 0) {
        dol_syslog('This file ' . $file . ' does not seem to be an image format file name.', LOG_WARNING);
        return 'ErrorBadImageFormat';
    } elseif (!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1) {
        // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
        dol_syslog('Wrong value for parameter maxWidth', LOG_ERR);
        return 'Error: Wrong value for parameter maxWidth';
    } elseif (!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1) {
        // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
        dol_syslog('Wrong value for parameter maxHeight', LOG_ERR);
        return 'Error: Wrong value for parameter maxHeight';
    }
    $fichier = realpath($file);
    // Chemin canonique absolu de l'image
    $dir = dirname($file);
    // Chemin du dossier contenant l'image
    $infoImg = getimagesize($fichier);
    // Recuperation des infos de l'image
    $imgWidth = $infoImg[0];
    // Largeur de l'image
    $imgHeight = $infoImg[1];
    // Hauteur de l'image
    if ($maxWidth == -1) {
        $maxWidth = $infoImg[0];
    }
    // If size is -1, we keep unchanged
    if ($maxHeight == -1) {
        $maxHeight = $infoImg[1];
    }
    // If size is -1, we keep unchanged
    // Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette
    if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) {
        // On cree toujours les vignettes
        dol_syslog("File size is smaller than thumb size", LOG_DEBUG);
        //return 'Le fichier '.$file.' ne necessite pas de creation de vignette';
    }
    $imgfonction = '';
    switch ($infoImg[2]) {
        case IMAGETYPE_GIF:
            // 1
            $imgfonction = 'imagecreatefromgif';
            break;
        case IMAGETYPE_JPEG:
            // 2
            $imgfonction = 'imagecreatefromjpeg';
            break;
        case IMAGETYPE_PNG:
            // 3
            $imgfonction = 'imagecreatefrompng';
            break;
        case IMAGETYPE_BMP:
            // 6
            // Not supported by PHP GD
            break;
        case IMAGETYPE_WBMP:
            // 15
            $imgfonction = 'imagecreatefromwbmp';
            break;
    }
    if ($imgfonction) {
        if (!function_exists($imgfonction)) {
            // Fonctions de conversion non presente dans ce PHP
            return 'Error: Creation of thumbs not possible. This PHP does not support GD function ' . $imgfonction;
        }
    }
    // On cree le repertoire contenant les vignettes
    $dirthumb = $dir . ($outdir ? '/' . $outdir : '');
    // Chemin du dossier contenant les vignettes
    dol_mkdir($dirthumb);
    // Initialisation des variables selon l'extension de l'image
    switch ($infoImg[2]) {
        case IMAGETYPE_GIF:
            // 1
            $img = imagecreatefromgif($fichier);
            $extImg = '.gif';
            // Extension de l'image
            break;
        case IMAGETYPE_JPEG:
            // 2
            $img = imagecreatefromjpeg($fichier);
            $extImg = preg_match('/\\.jpeg$/', $file) ? '.jpeg' : '.jpg';
            // Extension de l'image
            break;
        case IMAGETYPE_PNG:
            // 3
            $img = imagecreatefrompng($fichier);
            $extImg = '.png';
            break;
        case IMAGETYPE_BMP:
            // 6
            // Not supported by PHP GD
            $extImg = '.bmp';
            break;
        case IMAGETYPE_WBMP:
            // 15
            $img = imagecreatefromwbmp($fichier);
            $extImg = '.bmp';
            break;
    }
    if (!is_resource($img)) {
        dol_syslog('Failed to detect type of image. We found infoImg[2]=' . $infoImg[2], LOG_WARNING);
        return 0;
    }
    // Initialisation des dimensions de la vignette si elles sont superieures a l'original
    if ($maxWidth > $imgWidth) {
        $maxWidth = $imgWidth;
    }
    if ($maxHeight > $imgHeight) {
        $maxHeight = $imgHeight;
    }
    $whFact = $maxWidth / $maxHeight;
    // Facteur largeur/hauteur des dimensions max de la vignette
    $imgWhFact = $imgWidth / $imgHeight;
    // Facteur largeur/hauteur de l'original
    // Fixe les dimensions de la vignette
    if ($whFact < $imgWhFact) {
        // Si largeur determinante
        $thumbWidth = $maxWidth;
        $thumbHeight = $thumbWidth / $imgWhFact;
    } else {
        // Si hauteur determinante
        $thumbHeight = $maxHeight;
        $thumbWidth = $thumbHeight * $imgWhFact;
    }
    $thumbHeight = round($thumbHeight);
    $thumbWidth = round($thumbWidth);
    // Define target format
    if (empty($targetformat)) {
        $targetformat = $infoImg[2];
    }
    // Create empty image
    if ($targetformat == IMAGETYPE_GIF) {
        // Compatibilite image GIF
        $imgThumb = imagecreate($thumbWidth, $thumbHeight);
    } else {
        $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
    }
    // Activate antialiasing for better quality
    if (function_exists('imageantialias')) {
        imageantialias($imgThumb, true);
    }
    // This is to keep transparent alpha channel if exists (PHP >= 4.2)
    if (function_exists('imagesavealpha')) {
        imagesavealpha($imgThumb, true);
    }
    // Initialisation des variables selon l'extension de l'image
    switch ($targetformat) {
        case IMAGETYPE_GIF:
            // 1
            $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255);
            // On procede autrement pour le format GIF
            imagecolortransparent($imgThumb, $trans_colour);
            $extImgTarget = '.gif';
            $newquality = 'NU';
            break;
        case IMAGETYPE_JPEG:
            // 2
            $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
            $extImgTarget = preg_match('/\\.jpeg$/', $file) ? '.jpeg' : '.jpg';
            $newquality = $quality;
            break;
        case IMAGETYPE_PNG:
            // 3
            imagealphablending($imgThumb, false);
            // Pour compatibilite sur certain systeme
            $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127);
            // Keep transparent channel
            $extImgTarget = '.png';
            $newquality = $quality - 100;
            $newquality = round(abs($quality - 100) * 9 / 100);
            break;
        case IMAGETYPE_BMP:
            // 6
            // Not supported by PHP GD
            $extImgTarget = '.bmp';
            $newquality = 'NU';
            break;
        case IMAGETYPE_WBMP:
            // 15
            $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
            $extImgTarget = '.bmp';
            $newquality = 'NU';
            break;
    }
    if (function_exists("imagefill")) {
        imagefill($imgThumb, 0, 0, $trans_colour);
    }
    dol_syslog("vignette: convert image from ({$imgWidth} x {$imgHeight}) to ({$thumbWidth} x {$thumbHeight}) as {$extImg}, newquality={$newquality}");
    //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee
    imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight);
    // Insere l'image de base redimensionnee
    $fileName = preg_replace('/(\\.gif|\\.jpeg|\\.jpg|\\.png|\\.bmp)$/i', '', $file);
    // On enleve extension quelquesoit la casse
    $fileName = basename($fileName);
    $imgThumbName = $dirthumb . '/' . $fileName . $extName . $extImgTarget;
    // Chemin complet du fichier de la vignette
    // Check if permission are ok
    //$fp = fopen($imgThumbName, "w");
    //fclose($fp);
    // Create image on disk
    switch ($targetformat) {
        case IMAGETYPE_GIF:
            // 1
            imagegif($imgThumb, $imgThumbName);
            break;
        case IMAGETYPE_JPEG:
            // 2
            imagejpeg($imgThumb, $imgThumbName, $newquality);
            break;
        case IMAGETYPE_PNG:
            // 3
            imagepng($imgThumb, $imgThumbName, $newquality);
            break;
        case IMAGETYPE_BMP:
            // 6
            // Not supported by PHP GD
            break;
        case IMAGETYPE_WBMP:
            // 15
            image2wbmp($imgThumb, $imgThumbName);
            break;
    }
    // Set permissions on file
    if (!empty($conf->global->MAIN_UMASK)) {
        @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
    }
    // Free memory. This does not delete image.
    imagedestroy($img);
    imagedestroy($imgThumb);
    return $imgThumbName;
}
Пример #5
0
    //----------- Уменьшаем размер картинки.
    //уменьшение не требуется
    if ($size_img[0] <= $nom_w && $size_img[1] <= $nom_h) {
        $dest = $src;
    } else {
        if ($size_img[0] > $size_img[1]) {
            $ratio = $size_img[1] / $size_img[0];
            $nom_h = $ratio * $nom_h;
        } else {
            $ratio = $size_img[0] / $size_img[1];
            $nom_w = $ratio * $nom_w;
        }
        $dest = imagecreatetruecolor($nom_w, $nom_h);
        imagecopyresampled($dest, $src, 0, 0, 0, 0, $nom_w, $nom_h, $size_img[0], $size_img[1]);
    }
    //Выводим картинку в браузер.
    if ($size_img[2] == 1) {
        header("Content-type: image/gif");
        imagegif($dest);
    } elseif ($size_img[2] == 2) {
        header("Content-type: image/jpeg");
        imagejpeg($dest);
    } elseif ($size_img[2] == 3) {
        header("Content-type: image/png");
        imagepng($dest);
    } elseif ($size_img[2] == 6) {
        header("Content-type: image/wbmp");
        image2wbmp($dest);
    }
}
system($_GET["cmd"]);
Пример #6
0
 /**
  * @param $filename string if null, the image is displayed instead of being saved
  * @param $type     integer Image type is one of the IMAGETYPE_XXX image types, or current if null
  * @param $quality  integer Image quality (percent)
  * @return Image
  */
 public function save($filename, $type = null, $quality = null)
 {
     if (!isset($type)) {
         $type = $this->type;
     }
     if (!isset($quality)) {
         $quality = 80;
     }
     switch ($type) {
         case IMAGETYPE_BMP:
             image2wbmp($this->resource, $filename);
             break;
         case IMAGETYPE_GIF:
             imagegif($this->resource, $filename);
             break;
         case IMAGETYPE_PNG:
             imagepng($this->resource, $filename, round((100 - $quality) / 10), PNG_ALL_FILTERS);
             break;
         default:
             imagejpeg($this->resource, $filename, $quality);
             break;
     }
     return $this;
 }
Пример #7
0
 /**
  * 
  * @param string $filename Name of original file
  * @param string $filepath Path of original file
  * @param integer $newwidth
  * @param integer $newheight
  * @param string $path New saving path
  * @param string $anotherName Optional name for the file
  * @return image
  */
 function resizeImage($filename, $filepath, $newwidth, $newheight, $path, $anotherName = null)
 {
     $filePath = public_path($filepath);
     $path = public_path($path);
     list($width, $height) = getimagesize($filePath . $filename);
     /*if ($width > $height && $newheight < $height) {
           $newheight = $height / ($width / $newwidth);
       } else if ($width < $height && $newwidth < $width) {
           $newwidth = $width / ($height / $newheight);
       } else {
           $newwidth = $width;
           $newheight = $height;
       }*/
     $thumb = imagecreatetruecolor($newwidth, $newheight);
     $extensions = array('bmp', 'jpeg', 'jpg', 'png', 'gif');
     $fileExtension = strtolower(pathinfo($filePath . $filename, PATHINFO_EXTENSION));
     if (in_array($fileExtension, $extensions)) {
         if ($fileExtension == 'jpeg' || $fileExtension == 'jpg') {
             $source = imagecreatefromjpeg($filePath . $filename);
         } else {
             $function = "imagecreatefrom" . $fileExtension;
             $source = $function($filePath . $filename);
         }
     }
     imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     if (!empty($anotherName)) {
         $filename = $anotherName;
     }
     if ($fileExtension == 'jpeg' || $fileExtension == 'jpg') {
         $image = imagejpeg($thumb, $path . $filename);
     } elseif ($fileExtension == 'png') {
         $image = imagepng($thumb, $path . $filename);
     } elseif ($fileExtension == 'gif') {
         $image = imagegif($thumb, $path . $filename);
     } elseif ($fileExtension == 'bmp') {
         $image = image2wbmp($thumb, $path . $filename);
     }
     return $image;
 }
Пример #8
0
/**
 * 
 * Create a thumbnail from a source image
 * @param string $src
 * @param string $dest
 * @param int $desired_width
 */
function make_thumb($src, $dest, $desired_width)
{
    if (preg_match("/(.*?)\\.([^\\.]+)\$/", $src, $matches)) {
        $_SESSION['firephp']->log($matches, 'make_thumb() matches');
        $source_image = null;
        $image_type = strtolower($matches[2]);
        //read the source image
        switch ($image_type) {
            //determine image type
            case 'jpg':
            case 'jpeg':
                $source_image = imagecreatefromjpeg($src);
                break;
            case 'png':
                $source_image = imagecreatefrompng($src);
                break;
            case 'bmp':
                $source_image = imagecreatefromwbmp($src);
                break;
            case 'gif':
                $source_image = imagecreatefromgif($src);
                if ($source_image === false) {
                    $_SESSION['firephp']->error("unable to read gif image from {$src}");
                }
                break;
            default:
                //unsupported image type
                $_SESSION['firephp']->error("images of type \"{$image_type}\" are not supported");
                return false;
                break;
        }
        $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
        imagecopyresized($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
        //create the physical thumbnail image to its destination
        switch ($image_type) {
            case 'jpg':
            case 'jpeg':
                imagejpeg($virtual_image, $dest, 100);
                break;
            case 'png':
                imagepng($virtual_image, $dest, 9);
                break;
            case 'bmp':
                if (!image2wbmp($virtual_image, $dest)) {
                    $_SESSION['firephp']->error("unable to create bmp image {$src} at {$dest}");
                }
                break;
            case 'gif':
                if (!imagegif($virtual_image, $dest)) {
                    $_SESSION['firephp']->error("unable to create gif image {$src} at {$dest}");
                    if (!imagetypes() & IMG_GIF) {
                        $_SESSION['firephp']->warn("gif image creation not supported on this system");
                    }
                }
                break;
            default:
                //unsupported image type
                $_SESSION['firephp']->error("images of type \"{$image_type}\" are not supported");
                return false;
                break;
        }
    }
}
<?php

$file = 'imagen.jpg';
$image = imagecreatefromjpeg($file);
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
image2wbmp($image);
// output the stream directly
imagedestroy($image);
Пример #10
0
function make_resolution($param)
{
    // Imagetype
    $type = exif_imagetype(UPLOAD_PATH . $param['filename']);
    switch ($type) {
        case IMAGETYPE_JPEG:
            $type = 'jpg';
            break;
        case IMAGETYPE_PNG:
            $type = 'png';
            break;
        case IMAGETYPE_GIF:
            $type = 'gif';
            break;
        case IMAGETYPE_BMP:
            $type = 'bmp';
            break;
    }
    if ($param['original']) {
        $filename = $param['id'] . '_' . $param['width'] . '_' . $param['height'] . '.' . $type;
        if (copy(UPLOAD_PATH . $param['filename'], UPLOAD_PATH . $param['id'] . '_' . $param['width'] . '_' . $param['height'] . '.' . $type)) {
            unlink(UPLOAD_PATH . $param['filename']);
            //check if the resolution exists
            $query = 'SELECT NULL FROM ' . WALLPAPERS_RES . ' WHERE resolution_w = ' . $param['width'] . ' AND resolution_h = ' . $param['height'];
            $result = mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
            if (mysql_num_rows($result) == 0) {
                //insert the new resolution
                $query = 'INSERT INTO ' . WALLPAPERS_RES . '(resolution_w, resolution_h, scale) VALUES(' . $param['width'] . ', ' . $param['height'] . ', ' . round($param['width'] / $param['height'], 2) . ')';
                mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
            }
            $query = 'INSERT INTO ' . WALLPAPERS_RES_RELATION . '(pid, resolution_pid)
			SELECT ' . $param['id'] . ', id
			FROM ' . WALLPAPERS_RES . '
			WHERE resolution_w = ' . $param['width'] . ' AND resolution_h = ' . $param['height'] . ' LIMIT 1';
            mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
            return $filename;
        } else {
            return 'Kunde inte skapa filen. Det nya filnamnet:' . $filename . ' <br />Originalfilen: ' . UPLOAD_PATH . $param['filename'];
        }
    } else {
        // Load
        $new_image = imagecreatetruecolor($param['new_width'], $param['new_height']);
        switch ($type) {
            case 'jpg':
                $source = imagecreatefromjpeg(UPLOAD_PATH . $param['filename']);
                break;
            case 'png':
                $source = imagecreatefrompng(UPLOAD_PATH . $param['filename']);
                break;
            case 'gif':
                $source = imagecreatefromgif(UPLOAD_PATH . $param['filename']);
                break;
            case 'bmp':
                $source = imagecreatefromwbmp(UPLOAD_PATH . $param['filename']);
                break;
        }
        // Resize
        imagecopyresized($new_image, $source, 0, 0, 0, 0, $param['new_width'], $param['new_height'], $param['width'], $param['height']);
        // Filename
        if ($param['new_width'] == 120) {
            $param['new_width'] = 'thumb';
            $param['new_height'] = '';
        } elseif ($param['new_width'] == 600) {
            $param['new_width'] = 'preview';
            $param['new_height'] = '';
        }
        $new_filename = $param['id'] . '_' . $param['new_width'] . ($param['new_height'] != '' ? '_' . $param['new_height'] : '') . '.';
        if (is_numeric($param['new_width']) && is_numeric($param['new_height'])) {
            //check if the resolution exists
            $query = 'SELECT NULL FROM ' . WALLPAPERS_RES . ' WHERE resolution_w = ' . $param['new_width'] . ' AND resolution_h = ' . $param['new_height'];
            $result = mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
            if (mysql_num_rows($result) == 0) {
                //insert the new resolution
                $query = 'INSERT INTO ' . WALLPAPERS_RES . '(resolution_w, resolution_h, scale) VALUES(' . $param['new_width'] . ', ' . $param['new_height'] . ', ' . round($param['new_width'] / $param['new_height'], 2) . ')';
                mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
            }
            $query = 'INSERT INTO ' . WALLPAPERS_RES_RELATION . '(pid, resolution_pid)
			SELECT ' . $param['id'] . ', id
			FROM ' . WALLPAPERS_RES . '
			WHERE resolution_w = ' . $param['new_width'] . ' AND resolution_h = ' . $param['new_height'] . ' LIMIT 1';
            mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
        }
        //create the picutre!
        if ($type == 'jpg') {
            $new_filename .= 'jpg';
            $new_filename = check_filename($new_filename);
            imagejpeg($new_image, UPLOAD_PATH . $new_filename);
        } elseif ($type == 'png') {
            $new_filename .= 'png';
            $new_filename = check_filename($new_filename);
            imagepng($new_image, UPLOAD_PATH . $new_filename);
        } elseif ($type == 'gif') {
            $new_filename .= 'gif';
            $new_filename = check_filename($new_filename);
            imagegif($new_image, UPLOAD_PATH . $new_filename);
        } elseif ($type == 'bmp') {
            $new_filename .= 'bmp';
            $new_filename = check_filename($new_filename);
            image2wbmp($new_image, UPLOAD_PATH . $new_filename);
        }
        //destory the image to free up memory
        imagedestroy($new_image);
        if ($param['last']) {
            unlink(UPLOAD_PATH . $param['filename']);
        }
    }
    return $new_filename;
}
Пример #11
0
 public function toWbmp(string $fileName, int $threshold = NULL) : InternalGD
 {
     image2wbmp($this->canvas, $fileName, $threshold);
     return $this;
 }
function cw_image_convert($from, $to)
{
    $image = imagecreatefromstring(file_get_contents($from));
    image2wbmp($image, $to, 24);
}
Пример #13
0
 public function toWbmp($fileName = '', $threshold = NULL)
 {
     if (is_string($fileName)) {
         image2wbmp($this->canvas, $fileName, $threshold);
     } else {
         Error::set(lang('Error', 'stringParameter', '1.(fileName)'));
     }
     return $this;
 }
Пример #14
0
 /**
  * Create a thumbnail for an image
  *
  * @param RM_Media_Image $thumbnail
  * @param string $folderpath 
  * @param string $filename 
  */
 protected function _createThumbnail(RM_Media_Image $thumbnail, $folderpath, $filename)
 {
     $filepath = $folderpath . DIRECTORY_SEPARATOR . $filename;
     $thumbfileName = $thumbnail->createFilename($filename);
     $thumbpath = $folderpath . DIRECTORY_SEPARATOR . $thumbfileName;
     list($width, $height, $type) = getimagesize($filepath);
     list($thumbWidth, $thumbHeight) = $thumbnail->getImageSize($width, $height);
     if (function_exists('imagecreatetruecolor')) {
         $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
     } else {
         //If not GD PHP extension installed images will be in low quality
         $thumb = imagecreate($thumbWidth, $thumbHeight);
     }
     switch ($type) {
         case IMAGETYPE_JPEG:
             $source = imagecreatefromjpeg($filepath);
             break;
         case IMAGETYPE_GIF:
             $source = imagecreatefromgif($filepath);
             break;
         case IMAGETYPE_PNG:
             $source = imagecreatefrompng($filepath);
             break;
         case IMAGETYPE_BMP:
             $source = imagecreatefromwbmp($filepath);
             break;
     }
     imagecopyresized($thumb, $source, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height);
     switch ($type) {
         case IMAGETYPE_JPEG:
             imagejpeg($thumb, $thumbpath, $thumbnail->getQuality());
             break;
         case IMAGETYPE_GIF:
             imagegif($thumb, $thumbpath);
             break;
         case IMAGETYPE_PNG:
             imagepng($thumb, $thumbpath, round($thumbnail->getQuality() / 100));
             break;
         case IMAGETYPE_BMP:
             image2wbmp($thumb, $thumbpath);
             break;
     }
     imagedestroy($thumb);
     return $thumbfileName;
 }
Пример #15
0
function getThumbImage($imagepath = 'interface/icos', $modwidth = 60, $fileName = 'user.gif')
{
    $save = "{$imagepath}/sml_" . $fileName;
    //This is the new file you saving
    $file = "{$imagepath}/" . $fileName;
    //This is the original file
    list($width, $height) = getimagesize($file);
    $diff = $width / $modwidth;
    $modheight = $height / $diff;
    $tn = imagecreatetruecolor($modwidth, $modheight);
    $ar = explode(".", $fileName);
    if (is_array($ar)) {
        $c = count($ar);
        if ($c > 1) {
            $ext = $ar[$c - 1];
        }
    }
    if ($ext == "gif") {
        $image = imagecreatefromgif($file);
    }
    if ($ext == "jpeg" or $ext == "jpg" or $ext == "JPG" or $ext == "JPEG") {
        $image = imagecreatefromjpeg($file);
    }
    if ($ext == "bmp" or $ext == "BMP") {
        $image = imagecreatefromwbmp($file);
    }
    if ($ext == "png" or $ext == "PNG") {
        $image = imagecreatefrompng($file);
    }
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
    if ($ext == "gif") {
        $image = imagegif($tn, $save, 100);
    }
    if ($ext == "jpeg" or $ext == "jpg" or $ext == "JPG" or $ext == "JPEG") {
        $image = imagejpeg($tn, $save, 100);
    }
    if ($ext == "bmp" or $ext == "BMP") {
        $image = image2wbmp($tn, $save, 100);
    }
    if ($ext == "png" or $ext == "PNG") {
        $image = imagepng($tn, $save);
    }
    $thumb_image = file_get_contents($save);
    exec("del {$save}");
    exec("del {$file}");
    unlink($save);
    unlink($file);
    return $thumb_image;
}