示例#1
0
function imageCreateFromAny($filepath)
{
    list($w, $h, $t, $attr) = getimagesize($filepath);
    // [] if you don't have exif you could use getImageSize()
    $allowedTypes = array(IMG_GIF, IMG_JPG, IMG_PNG, IMG_WBMP);
    if (!in_array($t, $allowedTypes)) {
        return false;
    }
    switch ($t) {
        case IMG_GIF:
            $im = imageCreateFromGif($filepath);
            echo 'type image GIF';
            break;
        case IMG_JPG:
            $im = imageCreateFromJpeg($filepath);
            echo 'type image JPG';
            break;
        case IMG_PNG:
            $im = imageCreateFromPng($filepath);
            echo 'type image PNG';
            break;
        case IMG_WBMP:
            $im = imageCreateFromwBmp($filepath);
            echo 'type image BMP';
            break;
    }
    echo 'source : ' . $filepath . ' | im : ' . $im;
    return $im;
}
示例#2
0
文件: Gd.php 项目: fredcido/simuweb
 /**
  * Load image from $fileName
  *
  * @throws Zend_Image_Driver_Exception
  * @param string $fileName Path to image
  */
 public function load($fileName)
 {
     parent::load($fileName);
     $this->_imageLoaded = false;
     $info = getimagesize($fileName);
     switch ($this->_type) {
         case 'jpg':
             $this->_image = imageCreateFromJpeg($fileName);
             if ($this->_image !== false) {
                 $this->_imageLoaded = true;
             }
             break;
         case 'png':
             $this->_image = imageCreateFromPng($fileName);
             if ($this->_image !== false) {
                 $this->_imageLoaded = true;
             }
             break;
         case 'gif':
             $this->_image = imageCreateFromGif($fileName);
             if ($this->_image !== false) {
                 $this->_imageLoaded = true;
             }
             break;
     }
 }
function imageResize($file, $info, $destination)
{
    $height = $info[1];
    //высота
    $width = $info[0];
    //ширина
    //определяем размеры будущего превью
    $y = 150;
    if ($width > $height) {
        $x = $y * ($width / $height);
    } else {
        $x = $y / ($height / $width);
    }
    $to = imageCreateTrueColor($x, $y);
    switch ($info['mime']) {
        case 'image/jpeg':
            $from = imageCreateFromJpeg($file);
            break;
        case 'image/png':
            $from = imageCreateFromPng($file);
            break;
        case 'image/gif':
            $from = imageCreateFromGif($file);
            break;
        default:
            echo "No prevue";
            break;
    }
    imageCopyResampled($to, $from, 0, 0, 0, 0, imageSX($to), imageSY($to), imageSX($from), imageSY($from));
    imagepng($to, $destination);
    imagedestroy($from);
    imagedestroy($to);
}
示例#4
0
function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75)
{
    if (file_exists($src) && isset($dest)) {
        // path info
        $destInfo = pathInfo($dest);
        // image src size
        $srcSize = getImageSize($src);
        // image dest size $destSize[0] = width, $destSize[1] = height
        $srcRatio = $srcSize[0] / $srcSize[1];
        // width/height ratio
        $destRatio = $maxWidth / $maxHeight;
        if ($destRatio > $srcRatio) {
            $destSize[1] = $maxHeight;
            $destSize[0] = $maxHeight * $srcRatio;
        } else {
            $destSize[0] = $maxWidth;
            $destSize[1] = $maxWidth / $srcRatio;
        }
        // path rectification
        if ($destInfo['extension'] == "gif") {
            $dest = substr_replace($dest, 'jpg', -3);
        }
        // true color image, with anti-aliasing
        $destImage = imageCreateTrueColor($destSize[0], $destSize[1]);
        //       imageAntiAlias($destImage,true);
        // src image
        switch ($srcSize[2]) {
            case 1:
                //GIF
                $srcImage = imageCreateFromGif($src);
                break;
            case 2:
                //JPEG
                $srcImage = imageCreateFromJpeg($src);
                break;
            case 3:
                //PNG
                $srcImage = imageCreateFromPng($src);
                break;
            default:
                return false;
                break;
        }
        // resampling
        imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
        // generating image
        switch ($srcSize[2]) {
            case 1:
            case 2:
                imageJpeg($destImage, $dest, $quality);
                break;
            case 3:
                imagePng($destImage, $dest);
                break;
        }
        return true;
    } else {
        return 'No such File';
    }
}
示例#5
0
 /**
  * Using GD lib for get and transform images.
  * @see http://php.net/manual/en/function.imagecreatefromjpeg.php#110547
  */
 function anyImgFile2Im($fname = NULL)
 {
     if ($fname) {
         $this->setFile($fname);
     }
     $allowedTypes = [1, 2, 3, 6];
     // gif,jpg,png,bmp
     if (!in_array($this->ftype, $allowedTypes)) {
         return false;
     }
     switch ($this->ftype) {
         case 1:
             $im = imageCreateFromGif($this->fname);
             break;
         case 2:
             $im = imageCreateFromJpeg($this->fname);
             break;
         case 3:
             $im = imageCreateFromPng($this->fname);
             //  echo "\n degug {$this->fname}";
             break;
         case 6:
             $im = imageCreateFromBmp($this->fname);
             break;
     }
     return $im;
 }
示例#6
0
文件: image.php 项目: laiello/phpbf
 function load()
 {
     if ($this->loaded) {
         return true;
     }
     //$size = $this->get_size();
     //if (!$size) throw new exception("Failed loading image");
     list($this->w, $this->h, $this->type) = getImageSize($this->src);
     switch ($this->type) {
         case 1:
             $this->img = imageCreateFromGif($this->src);
             break;
         case 2:
             $this->img = imageCreateFromJpeg($this->src);
             break;
         case 3:
             $this->img = imageCreateFromPng($this->src);
             break;
         default:
             throw new exception("Unsuported image type");
             break;
     }
     $this->loaded = true;
     return true;
 }
示例#7
0
 protected function get_any_type($srcpath)
 {
     try {
         $this->check_file($srcpath);
         $srcSize = getImageSize($srcpath);
         switch ($srcSize[2]) {
             case 1:
                 $img = imageCreateFromGif($srcpath);
                 break;
             case 2:
                 $img = imageCreateFromJpeg($srcpath);
                 break;
             case 3:
                 $img = imageCreateFromPng($srcpath);
                 break;
             default:
                 throw new Imgdexception('not possible to get any type - srcpath:' . $srcpath);
                 break;
         }
         $image['width'] = $srcSize[0];
         $image['height'] = $srcSize[1];
         $image['img'] = $img;
         return $image;
     } catch (Imgdexception $e) {
         $e->print_debug(__FILE__, __LINE__);
         return false;
     }
 }
示例#8
0
 /**
  * Read a png image from file
  * @param File file of the image
  * @return resource internal PHP image resource of the file
  */
 public function read(File $file)
 {
     $this->checkIfReadIsPossible($file, 'png');
     $image = imageCreateFromPng($file->getAbsolutePath());
     if ($image === false) {
         throw new ImageException($file->getPath() . ' is not a valid PNG image');
     }
     return $image;
 }
示例#9
0
 private function mergerImg($imgs)
 {
     list($max_width, $max_height) = getimagesize($imgs['dst']);
     $dest = imagecreatefromjpeg($imgs['dst']);
     $src = imageCreateFromPng($imgs['src']);
     imageAlphaBlending($dest, true);
     imageSaveAlpha($dest, true);
     self::imagecopymerge_alpha($dest, $src, 0, 0, 0, 0, $max_width, $max_height, 100);
     $filename = $this->getFileName('jpg');
     // header("Content-type: image/jpeg");
     imagejpeg($dest, $filename, 80);
     imagedestroy($src);
     imagedestroy($dest);
     return $filename;
 }
示例#10
0
function img_create($type, $name)
{
    if ($type == "gif") {
        $im = imageCreateFromGif($name);
    } elseif ($type == "jpeg" || $type == "jpg") {
        $im = imagecreatefromjpeg($name);
    } elseif ($type == "png") {
        $im = imageCreateFromPng($name);
    } elseif ($type == "bmp") {
        $im = imageCreateFromBmp($name);
    } else {
        return false;
    }
    return $im;
}
示例#11
0
 /**
  * @see	\wcf\system\image\adapter\IImageAdapter::loadFile()
  */
 public function loadFile($file)
 {
     list($this->width, $this->height, $this->type) = getImageSize($file);
     switch ($this->type) {
         case IMAGETYPE_GIF:
             $this->image = imageCreateFromGif($file);
             break;
         case IMAGETYPE_JPEG:
             $this->image = imageCreateFromJpeg($file);
             break;
         case IMAGETYPE_PNG:
             $this->image = imageCreateFromPng($file);
             break;
         default:
             throw new SystemException("Could not read image '" . $file . "', format is not recognized.");
             break;
     }
 }
示例#12
0
 function loadImage($path)
 {
     if ($this->image) {
         imagedestroy($this->image);
     }
     $img_sz = getimagesize($path);
     switch ($img_sz[2]) {
         case 1:
             $this->image_type = "GIF";
             if (!($this->image = imageCreateFromGif($path))) {
                 return FALSE;
             } else {
                 return TRUE;
             }
             break;
         case 2:
             $this->image_type = "JPG";
             if (!($this->image = imageCreateFromJpeg($path))) {
                 return FALSE;
             } else {
                 return TRUE;
             }
             break;
         case 3:
             $this->image_type = "PNG";
             if (!($this->image = imageCreateFromPng($path))) {
                 return FALSE;
             } else {
                 return TRUE;
             }
             break;
         case 4:
             $this->image_type = "SWF";
             if (!($this->image = imageCreateFromSwf($path))) {
                 return FALSE;
             } else {
                 return TRUE;
             }
             break;
         default:
             return FALSE;
     }
 }
示例#13
0
 function __construct($filename)
 {
     $this->_filename = $filename;
     list($this->_width, $this->_height) = getimagesize($this->_filename);
     $pathinfo = pathinfo($filename);
     switch (strtolower($pathinfo['extension'])) {
         case 'jpg':
         case 'jpeg':
             $this->_source = imageCreateFromJpeg($filename);
             break;
         case 'gif':
             $this->_source = imageCreateFromGif($filename);
             $this->_createImageCallback = 'imagecreate';
             break;
         case 'png':
             $this->_source = imageCreateFromPng($filename);
             break;
         default:
             throw new Naf_Image_Exception('Unsupported file extension');
             break;
     }
 }
示例#14
0
/**
* Generate images of alternate sizes.
*/
function resizeImage($cnvrt_arry)
{
    global $platform, $imgs, $cnvrt_path, $reqd_image, $convert_writable, $convert_magick, $convert_GD, $convert_cmd, $cnvrt_alt, $cnvrt_mesgs, $compat_quote;
    if (empty($imgs) || $convert_writable == FALSE) {
        return;
    }
    if ($convert_GD == TRUE && !($gd_version = gdVersion())) {
        return;
    }
    if ($cnvrt_alt['no_prof'] == TRUE) {
        $strip_prof = ' +profile "*"';
    } else {
        $strip_prof = '';
    }
    if ($cnvrt_alt['mesg_on'] == TRUE) {
        $str = '';
    }
    foreach ($imgs as $img_file) {
        if ($cnvrt_alt['indiv'] == TRUE && $img_file != $reqd_image['file']) {
            continue;
        }
        $orig_img = $reqd_image['pwd'] . '/' . $img_file;
        $cnvrtd_img = $cnvrt_path . '/' . $cnvrt_arry['prefix'] . $img_file;
        if (!is_file($cnvrtd_img)) {
            $img_size = GetImageSize($orig_img);
            $height = $img_size[1];
            $width = $img_size[0];
            $area = $height * $width;
            $maxarea = $cnvrt_arry['maxwid'] * $cnvrt_arry['maxwid'] * 0.9;
            $maxheight = $cnvrt_arry['maxwid'] * 0.75 + 1;
            if ($area > $maxarea || $width > $cnvrt_arry['maxwid'] || $height > $maxheight) {
                if ($width / $cnvrt_arry['maxwid'] >= $height / $maxheight) {
                    $dim = 'W';
                }
                if ($height / $maxheight >= $width / $cnvrt_arry['maxwid']) {
                    $dim = 'H';
                }
                if ($dim == 'W') {
                    $cnvt_percent = round(0.9375 * $cnvrt_arry['maxwid'] / $width * 100, 2);
                }
                if ($dim == 'H') {
                    $cnvt_percent = round(0.75 * $cnvrt_arry['maxwid'] / $height * 100, 2);
                }
                // convert it
                if ($convert_magick == TRUE) {
                    // Image Magick image conversion
                    if ($platform == 'Win32' && $compat_quote == TRUE) {
                        $winquote = '"';
                    } else {
                        $winquote = '';
                    }
                    exec($winquote . $convert_cmd . ' -geometry ' . $cnvt_percent . '%' . ' -quality ' . $cnvrt_arry['qual'] . ' -sharpen ' . $cnvrt_arry['sharpen'] . $strip_prof . ' "' . $orig_img . '"' . ' "' . $cnvrtd_img . '"' . $winquote);
                    $using = $cnvrt_mesgs['using IM'];
                } elseif ($convert_GD == TRUE) {
                    // GD image conversion
                    if (eregi('\\.jpg$|\\.jpeg$', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) {
                        $src_img = imageCreateFromJpeg($orig_img);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) {
                        $src_img = imageCreateFromPng($orig_img);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) {
                        $src_img = imageCreateFromGif($orig_img);
                    } else {
                        continue;
                    }
                    $src_width = imageSx($src_img);
                    $src_height = imageSy($src_img);
                    $dest_width = $src_width * ($cnvt_percent / 100);
                    $dest_height = $src_height * ($cnvt_percent / 100);
                    if ($gd_version >= 2) {
                        $dst_img = imageCreateTruecolor($dest_width, $dest_height);
                        imageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
                    } else {
                        $dst_img = imageCreate($dest_width, $dest_height);
                        imageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
                    }
                    imageDestroy($src_img);
                    if (eregi('\\.jpg$|\\.jpeg$/i', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) {
                        imageJpeg($dst_img, $cnvrtd_img, $cnvrt_arry['qual']);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) {
                        imagePng($dst_img, $cnvrtd_img);
                    } elseif (eregi('\\.gif$/i', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) {
                        imageGif($dst_img, $cnvrtd_img);
                    }
                    imageDestroy($dst_img);
                    $using = $cnvrt_mesgs['using GD'] . $gd_version;
                }
                if ($cnvrt_alt['mesg_on'] == TRUE && is_file($cnvrtd_img)) {
                    $str .= "  <small>\n" . '   ' . $cnvrt_mesgs['generated'] . $cnvrt_arry['txt'] . $cnvrt_mesgs['converted'] . $cnvrt_mesgs['image_for'] . $img_file . $using . ".\n" . "  </small>\n  <br />\n";
                }
            }
        }
    }
    if (isset($str)) {
        return $str;
    }
}
<?php

$mail["perk"] = "*****@*****.**";
Header("Content-type: image/png");
//$string=implode($argv," ");
$string = $_REQUEST['email'];
//$string="perk";
$im = imageCreateFromPng("./email.png");
$orange = ImageColorAllocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($mail[$string])) / 2;
ImageString($im, 3, $px, 9, $mail[$string], $orange);
ImagePng($im);
ImageDestroy($im);
示例#16
0
function all_project_tree($id_user, $completion, $project_kind)
{
    include "../include/config.php";
    $config["id_user"] = $id_user;
    $dotfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.all.dot";
    $pngfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.projectall.png";
    $mapfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.projectall.map";
    $dotfile = fopen($dotfilename, "w");
    fwrite($dotfile, "digraph Integria {\n");
    fwrite($dotfile, "\t  ranksep=1.8;\n");
    fwrite($dotfile, "\t  ratio=auto;\n");
    fwrite($dotfile, "\t  size=\"9,9\";\n");
    fwrite($dotfile, 'URL="' . $config["base_url"] . '/index.php?sec=projects&sec2=operation/projects/project_tree";' . "\n");
    fwrite($dotfile, "\t  node[fontsize=" . $config['fontsize'] . "];\n");
    fwrite($dotfile, "\t  me [label=\"{$id_user}\", style=\"filled\", color=\"yellow\"]; \n");
    $total_project = 0;
    $total_task = 0;
    if ($project_kind == "all") {
        $sql1 = "SELECT * FROM tproject WHERE disabled = 0";
    } else {
        $sql1 = "SELECT * FROM tproject WHERE disabled = 0 AND end != '0000-00-00 00:00:00'";
    }
    if ($result1 = mysql_query($sql1)) {
        while ($row1 = mysql_fetch_array($result1)) {
            if (user_belong_project($id_user, $row1["id"], 1) == 1) {
                $project[$total_project] = $row1["id"];
                $project_name[$total_project] = $row1["name"];
                if ($completion < 0) {
                    $sql2 = "SELECT * FROM ttask WHERE id_project = " . $row1["id"];
                } elseif ($completion < 101) {
                    $sql2 = "SELECT * FROM ttask WHERE completion < {$completion} AND id_project = " . $row1["id"];
                } else {
                    $sql2 = "SELECT * FROM ttask WHERE completion = 100 AND id_project = " . $row1["id"];
                }
                if ($result2 = mysql_query($sql2)) {
                    while ($row2 = mysql_fetch_array($result2)) {
                        if (user_belong_task($id_user, $row2["id"], 1) == 1) {
                            $task[$total_task] = $row2["id"];
                            $task_name[$total_task] = $row2["name"];
                            $task_parent[$total_task] = $row2["id_parent_task"];
                            $task_project[$total_task] = $project[$total_project];
                            $task_workunit[$total_task] = get_task_workunit_hours($row2["id"]);
                            $task_completion[$total_task] = $row2["completion"];
                            $total_task++;
                        }
                    }
                }
                $total_project++;
            }
        }
    }
    // Add project items
    for ($ax = 0; $ax < $total_project; $ax++) {
        fwrite($dotfile, 'PROY' . $project[$ax] . ' [label="' . wordwrap($project_name[$ax], 12, '\\n') . '", style="filled", color="grey", URL="' . $config["base_url"] . '/index.php?sec=projects&sec2=operation/projects/task&id_project=' . $project[$ax] . '"];');
        fwrite($dotfile, "\n");
    }
    // Add task items
    for ($ax = 0; $ax < $total_task; $ax++) {
        $temp = 'TASK' . $task[$ax] . ' [label="' . wordwrap($task_name[$ax], 12, '\\n') . '"';
        if ($task_completion[$ax] < 10) {
            $temp .= 'color="red"';
        } elseif ($task_completion[$ax] < 100) {
            $temp .= 'color="yellow"';
        } elseif ($task_completion[$ax] == 100) {
            $temp .= 'color="green"';
        }
        $temp .= "URL=\"" . $config["base_url"] . "/index.php?sec=projects&sec2=operation/projects/task_detail&id_project=" . $task_project[$ax] . "&id_task=" . $task[$ax] . "&operation=view\"";
        $temp .= "];";
        fwrite($dotfile, $temp);
        fwrite($dotfile, "\n");
    }
    // Make project attach to user "me"
    for ($ax = 0; $ax < $total_project; $ax++) {
        fwrite($dotfile, 'me -> PROY' . $project[$ax] . ';');
        fwrite($dotfile, "\n");
    }
    // Make project first parent task relation visible
    for ($ax = 0; $ax < $total_task; $ax++) {
        if ($task_parent[$ax] == 0) {
            fwrite($dotfile, 'PROY' . $task_project[$ax] . ' -> TASK' . $task[$ax] . ';');
            fwrite($dotfile, "\n");
        }
    }
    // Make task-subtask parent task relation visible
    for ($ax = 0; $ax < $total_task; $ax++) {
        if ($task_parent[$ax] != 0) {
            fwrite($dotfile, 'TASK' . $task_parent[$ax] . ' -> TASK' . $task[$ax] . ';');
            fwrite($dotfile, "\n");
        }
    }
    fwrite($dotfile, "}");
    fwrite($dotfile, "\n");
    // exec ("twopi -Tpng $dotfilename -o $pngfilename");
    exec("twopi -Tcmapx -o{$mapfilename} -Tpng -o{$pngfilename} {$dotfilename}");
    Header('Content-type: image/png');
    $imgPng = imageCreateFromPng($pngfilename);
    imageAlphaBlending($imgPng, true);
    imageSaveAlpha($imgPng, true);
    imagePng($imgPng);
    require $mapfilename;
    //unlink ($pngfilename);
    unlink($dotfilename);
}
示例#17
0
$fallBack_image = 'tmp.png';
//an image you are sure it works, if there is a problem, this skin will be used
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}
$times = array(array('Start', microtime_float()));
$login = $_GET['login'];
if (trim($login) == '') {
    $imgPng = imageCreateFromPng($fallBack_image);
} else {
    $imgPng = imageCreateFromPng('http://s3.amazonaws.com/MinecraftSkins/' . $login . '.png');
}
if (!$imgPng) {
    $imgPng = imageCreateFromPng($fallBack_image);
}
imageAlphaBlending($imgPng, true);
imageSaveAlpha($imgPng, true);
/* $width = imagesx($imgPng);
	$height = imagesy($imgPng);
	
	if(!($width == $height*2) || $height%32 != 0)//bad ratio !
		$imgPng = imageCreateFromPng($fallBack_image); */
//A quick fix, not perfect, to add compatibility with the new 1.8 Minecraft skin format
$width = 64;
$height = 32;
$hdRatio = $height / 32;
//$hdRatio = 2 if skin is 128*64
$times[] = array('Telechargement-Image', microtime_float());
$a = $_GET['a'];
 /**
  * Creates a new GDlib image resource based on the input image filename.
  * If it fails creating an image from the input file a blank gray image with the dimensions of the input image will be created instead.
  *
  * @param string $sourceImg Image filename
  * @return resource Image Resource pointer
  */
 public function imageCreateFromFile($sourceImg)
 {
     $imgInf = pathinfo($sourceImg);
     $ext = strtolower($imgInf['extension']);
     switch ($ext) {
         case 'gif':
             if (function_exists('imagecreatefromgif')) {
                 return imageCreateFromGif($sourceImg);
             }
             break;
         case 'png':
             if (function_exists('imagecreatefrompng')) {
                 $imageHandle = imageCreateFromPng($sourceImg);
                 if ($this->saveAlphaLayer) {
                     imagesavealpha($imageHandle, true);
                 }
                 return $imageHandle;
             }
             break;
         case 'jpg':
         case 'jpeg':
             if (function_exists('imagecreatefromjpeg')) {
                 return imageCreateFromJpeg($sourceImg);
             }
             break;
     }
     // If non of the above:
     $i = @getimagesize($sourceImg);
     $im = imagecreatetruecolor($i[0], $i[1]);
     $Bcolor = ImageColorAllocate($im, 128, 128, 128);
     ImageFilledRectangle($im, 0, 0, $i[0], $i[1], $Bcolor);
     return $im;
 }
示例#19
0
     die("Wrong extension.");
 }
 $wh = imageSx($orig);
 if (imageSy($orig) < $wh) {
     $wh = imageSy($orig);
 }
 if ($img['i_set'] > 0 && isset($_GET['set'])) {
     imagecopyresampled($im, $orig, 0 + $W / 8, 0 + $W / 8, imageSx($orig) / 2 - $wh / 2, imageSy($orig) / 2 - $wh / 2, $W - $W / 4, $W - $W / 4, $wh, $wh);
 } else {
     imagecopyresampled($im, $orig, 0, 0, imageSx($orig) / 2 - $wh / 2, imageSy($orig) / 2 - $wh / 2, $W, $W, $wh, $wh);
 }
 if ((int) $img['i_rotation'] != 0) {
     $im = imagerotate($im, $img['i_rotation'] * -90, 0);
 }
 if ($img['i_set'] > 0 && isset($_GET['set'])) {
     $stack = imageCreateFromPng(projectPath . '/resources/stack.png');
     imagecopyresampled($im, $stack, 0, 0, 0, 0, $W, $W, imageSx($stack), imageSy($stack));
 }
 if (me() != $img['i_u_fk']) {
     $own->addWatermark($im);
 }
 if ($img['i_set'] > 0 && isset($_GET['set'])) {
     header("content-type: image/png");
     imagePng($im);
 } else {
     header("content-type: image/jpeg");
     imageJpeg($im, NULL, 90);
 }
 exit;
 break;
 if (me() <= 0 || getS('user', 'u_email') != ownStaGramAdmin) {
示例#20
0
 function getImageType($file)
 {
     //使用getimagesize()函数,返回图像相关数据
     file_exists($file) ? $TempImage = getimagesize($file) : die("文件不存在!");
     switch ($TempImage[2]) {
         case 1:
             $image = imageCreateFromGif($file);
             $this->_type = "gif";
             break;
         case 2:
             $image = imageCreateFromJpeg($file);
             $this->_type = "jpg";
             break;
         case 3:
             $image = imageCreateFromPng($file);
             $this->_type = "png";
             break;
         default:
             die("不支持该文件格式,请使用GIF、JPG、PNG格式。");
     }
     unset($TempImage);
     $this->_im = $image;
 }
示例#21
0
function do_copy_image($resize_filein, $origin_filein, $fileout, $x, $y, $w, $h)
{
    if (strpos(strtolower($origin_filein), '.jpg') != false || strpos(strtolower($origin_filein), '.jpeg') != false) {
        $dest = @imagecreatefromjpeg($origin_filein);
    } elseif (strpos(strtolower($origin_filein), '.png') != false) {
        $dest = @imagecreatefrompng($origin_filein);
    } else {
        $dest = @imagecreatefromwbmp($origin_filein);
    }
    $src = imageCreateFromPng($resize_filein);
    list($rs_width, $rs_height) = getimagesize($resize_filein);
    imagecopymerge($dest, $src, $x, $y, 0, 0, $w, $h, 75);
    // imagecopymerge($dest, $src, $x, $y, 0, -$rs_height/4, $w, $h, 75);
    imagepng($dest, $fileout);
    imagedestroy($dest);
    imagedestroy($src);
}
示例#22
0
function redimage($src, $dest, $dw = false, $dh = false, $stamp = false)
{
    // detect file type (could be a lot better)
    if (is_array($src)) {
        $type_src = strtoupper(substr($src['name'], -3));
        $src = $src['tmp_name'];
    } else {
        $type_src = strtoupper(substr($src, -3));
    }
    $type_dest = strtoupper(substr($dest, -3));
    // read source image
    switch ($type_src) {
        case 'JPG':
            $src_img = ImageCreateFromJpeg($src);
            break;
        case 'PEG':
            $src_img = ImageCreateFromJpeg($src);
            break;
        case 'GIF':
            $src_img = ImageCreateFromGif($src);
            break;
        case 'PNG':
            $src_img = imageCreateFromPng($src);
            break;
        case 'BMP':
            $src_img = imageCreatefromWBmp($src);
            break;
    }
    // get it's info
    $size = GetImageSize($src);
    $sw = $size[0];
    $sh = $size[1];
    /*
                // get it's info
                $size = GetImageSize ($src);
                $fw = $size[0];
                $fh = $size[1];
    
                // ROGNE the picture from the top left pixel's color
                $rogne_color = imagecolorat ($src_img, 0, 0);
                $rogne_point = array ($fh, 0, 0, $fw);
    
                for ($x = 0; $x < $fw; $x ++){
                        for ($y = 0; $y < $fh; $y ++){
                                if (imagecolorat ($src_img, $x, $y) != $rogne_color){
                                        $rogne_point[0] = ($rogne_point[0] > $y)?$y:$rogne_point[0];
                                        $rogne_point[1] = ($rogne_point[1] < $x)?$x:$rogne_point[1];
                                        $rogne_point[2] = ($rogne_point[2] < $y)?$y:$rogne_point[2];
                                        $rogne_point[3] = ($rogne_point[3] > $x)?$x:$rogne_point[3];
                                }
                        }
                }
    
                $sw = $rogne_point[1] - $rogne_point[3];
                $sh = $rogne_point[2] - $rogne_point[0];
    
                $rogne_img = ImageCreateTrueColor ($sw, $sh);
    
                ImageCopyResampled ($rogne_img, $src_img, 0, 0, $rogne_point[3], $rogne_point[0], $fw, $fh, $fw, $fh);
    
                $src_img = $rogne_img;
    */
    // do not redim the pic
    if ($dw == false && $dh == false) {
        $dest_img = ImageCreateTrueColor($sw, $sh);
        ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $sw, $sh, $sw, $sh);
    } else {
        // redim the pix with dest W as max Side
        if ($dw != 0 && $dh == false) {
            if ($sw == $sh) {
                $dh = $dw;
            } else {
                if ($sw > $sh) {
                    $dh = round($dw / $sw * $sh);
                } else {
                    $dh = $dw;
                    $dw = round($dh / $sh * $sw);
                }
            }
            $dest_img = ImageCreateTrueColor($dw, $dh);
            ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
        } else {
            // redim the pic according to dest W or dest H
            if ($dw == 0 || $dh == 0) {
                if ($dw == 0) {
                    $dw = round($dh / $sh * $sw);
                } else {
                    if ($dh == 0) {
                        $dh = round($dw / $sw * $sh);
                    }
                }
                $dest_img = ImageCreateTrueColor($dw, $dh);
                ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
            } else {
                if ($sw / $sh < $dw / $dh) {
                    $tw = $sw;
                    $th = round($sw / $dw * $dh);
                    $x = 0;
                    $y = round(($sh - $th) / 2);
                    $temp_img = ImageCreateTrueColor($tw, $th);
                    $dest_img = ImageCreateTrueColor($dw, $dh);
                    ImageCopyResampled($temp_img, $src_img, 0, 0, $x, $y, $sw, $sh, $sw, $sh);
                    ImageCopyResampled($dest_img, $temp_img, 0, 0, 0, 0, $dw, $dh, $tw, $th);
                    ImageDestroy($temp_img);
                } else {
                    $tw = $sw;
                    $th = round($sw * ($dh / $dw));
                    $x = 0;
                    $y = round(($th - $sh) / 2);
                    $temp_img = ImageCreateTrueColor($tw, $th);
                    $dest_img = ImageCreateTrueColor($dw, $dh);
                    imagefill($temp_img, 0, 0, imagecolorallocate($dest_img, 0, 0, 0));
                    ImageCopyResampled($temp_img, $src_img, $x, $y, 0, 0, $sw, $sh, $sw, $sh);
                    ImageCopyResampled($dest_img, $temp_img, 0, 0, 0, 0, $dw, $dh, $tw, $th);
                    ImageDestroy($temp_img);
                }
            }
        }
    }
    if ($stamp != false) {
        // detect file type (could be a lot better)
        $type_stamp = strtoupper(substr($stamp, -3));
        // read  stamp
        switch ($type_stamp) {
            case 'JPG':
                $stamp_img = ImageCreateFromJpeg($stamp);
                break;
            case 'PEG':
                $stamp_img = ImageCreateFromJpeg($stamp);
                break;
            case 'GIF':
                $stamp_img = ImageCreateFromGif($stamp);
                break;
            case 'PNG':
                $stamp_img = imageCreateFromPng($stamp);
                break;
            case 'BMP':
                $stamp_img = imageCreatefromWBmp($stamp);
                break;
        }
        // get it's info
        $size = GetImageSize($stamp);
        $stw = $size[0];
        $sth = $size[1];
        $sx = $dw - $stw;
        $sy = $dh - $sth;
        imagecolortransparent($stamp_img, imageColorAllocate($stamp_img, 0, 0, 0));
        imagecopy($dest_img, $stamp_img, $sx, $sy, 0, 0, $stw, $sth);
    }
    // free destination
    if (file_exists($dest_img)) {
        unlink($dest_img);
    }
    // save dest image
    switch ($type_dest) {
        case 'JPG':
            imageJpeg($dest_img, $dest, 90);
            break;
        case 'PEG':
            imageJpeg($dest_img, $dest, 90);
            break;
        case 'GIF':
            imageGif($dest_img, $dest, 90);
            break;
        case 'PNG':
            imagePng($dest_img, $dest, 90);
            break;
        case 'BMP':
            imageWBmp($dest_img, $dest, 90);
            break;
    }
    // free memory
    imageDestroy($src_img);
    ImageDestroy($dest_img);
}
示例#23
0
if (!file_exists($image_path)) {
    //header("location: $path");
    exit;
}
switch ($ext) {
    case "gif":
        $img = imageCreateFromGif($image_path);
        break;
    case "jpg":
        $img = imageCreateFromJpeg($image_path);
        break;
    case "jpeg":
        $img = imageCreateFromJpeg($image_path);
        break;
    case "png":
        $img = imageCreateFromPng($image_path);
        break;
    default:
        $img = null;
        break;
}
if ($img == null) {
    header("location: {$path}");
    exit;
} else {
    $orig_width = imageSX($img);
    $orig_height = imageSY($img);
    $image_width = $orig_width;
    $image_height = $orig_height;
    if ($width != null && $height != null) {
        $image_width = min($width, $image_width * ($height / $orig_height));
示例#24
0
 /**
  * This function resizes given image, if it has bigger dimensions, than we need and saves it (also makes chmod 0777 on the file) ...
  * It uses GD or ImageMagick, setting is available to change in CL's config file.
  *
  * @param string $inputFileName the input file to work with
  * @param string $outputFileName the file to write into the final (resized) image
  * @param integer $maxNewWidth maximal width of image
  * @param integer $maxNewHeight maximal height of image
  * @return bool TRUE, if everything was successful (resize and chmod), else FALSE
  */
 function resize($inputFileName, $outputFileName, $maxNewWidth, $maxNewHeight)
 {
     $imageInfo = getimagesize($inputFileName);
     $fileType = $imageInfo['mime'];
     $extension = strtolower(str_replace('.', '', substr($outputFileName, -4)));
     $originalWidth = $imageInfo[0];
     $originalHeight = $imageInfo[1];
     if ($originalWidth > $maxNewWidth or $originalHeight > $maxNewHeight) {
         $newWidth = $maxNewWidth;
         $newHeight = $originalHeight / ($originalWidth / $maxNewWidth);
         if ($newHeight > $maxNewHeight) {
             $newHeight = $maxNewHeight;
             $newWidth = $originalWidth / ($originalHeight / $maxNewHeight);
         }
         $newWidth = ceil($newWidth);
         $newHeight = ceil($newHeight);
     } else {
         $newWidth = $originalWidth;
         $newHeight = $originalHeight;
     }
     $ok = FALSE;
     if (CL::getConf('CL_Images/engine') == 'imagick-cli') {
         exec("convert -thumbnail " . $newWidth . "x" . $newHeight . " " . $inputFileName . " " . $outputFileName);
         $ok = TRUE;
     } elseif (CL::getConf('CL_Images/engine') == 'imagick-php') {
         $image = new Imagick($inputFileName);
         $image->thumbnailImage($newWidth, $newHeight);
         $ok = (bool) $image->writeImage($outputFileName);
         $image->clear();
         $image->destroy();
     } else {
         $out = imageCreateTrueColor($newWidth, $newHeight);
         switch (strtolower($fileType)) {
             case 'image/jpeg':
                 $source = imageCreateFromJpeg($inputFileName);
                 break;
             case 'image/png':
                 $source = imageCreateFromPng($inputFileName);
                 break;
             case 'image/gif':
                 $source = imageCreateFromGif($inputFileName);
                 break;
             default:
                 break;
         }
         imageCopyResized($out, $source, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
         switch (strtolower($extension)) {
             case 'jpg':
             case 'jpeg':
                 if (imageJpeg($out, $outputFileName)) {
                     $ok = TRUE;
                 }
                 break;
             case 'png':
                 if (imagePng($out, $outputFileName)) {
                     $ok = TRUE;
                 }
                 break;
             case 'gif':
                 if (imageGif($out, $outputFileName)) {
                     $ok = TRUE;
                 }
                 break;
             default:
                 break;
         }
         imageDestroy($out);
         imageDestroy($source);
     }
     if ($ok and chmod($outputFileName, 0777)) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
示例#25
0
/** Cắt ảnh theo cỡ tùy chọn */
function create_image($args)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_filter('before_create_image', $args);
    hook_action('create_image');
    if (!is_array($args)) {
        parse_str($args, $args);
    }
    $file_id = $args['file'];
    if (isset_image($file_id)) {
        $row = get_file_data($file_id);
        $file_info = json_decode($row->file_info);
        $file_dst_name_body = $file_info->file_dst_name_body;
        $file_dst_name_ext = $file_info->file_dst_name_ext;
        $source_file = get_file_location($file_id);
        $crop_name = $file_dst_name_body . '-' . $args['w'] . 'x' . $args['h'] . '.' . $file_dst_name_ext;
        if (file_exists(get_file_location($file_id, FALSE) . $crop_name)) {
            return get_file_url($file_id, FALSE) . $crop_name;
        } else {
            /** resize file */
            /* fix func exif_imagetype not avaiable */
            $type = getimagesize($source_file);
            $type = $type['mime'];
            switch ($type) {
                case 'image/png':
                    $type = IMAGETYPE_PNG;
                    break;
                case 'image/jpeg':
                    $type = IMAGETYPE_JPEG;
                    break;
                case 'image/gif':
                    $type = IMAGETYPE_GIF;
                    break;
                case 'image/bmp':
                    $type = IMAGETYPE_BMP;
                    break;
                case 'image/x-ms-bmp':
                    $type = IMAGETYPE_BMP;
                    break;
            }
            /* fix func exif_imagetype not avaiable */
            switch ($type) {
                case 1:
                    $source = imageCreateFromGif($source_file);
                    break;
                case 2:
                    $source = imageCreateFromJpeg($source_file);
                    break;
                case 3:
                    $source = imageCreateFromPng($source_file);
                    break;
                case 6:
                    $source = imageCreateFromBmp($source_file);
                    break;
            }
            /** resize file gốc về cùng 1 cỡ */
            $size = getimagesize($source_file);
            $source_width = $size[0];
            $source_height = $size[1];
            $fix_width = $args['w'];
            $fix_height = $args['h'];
            $thumb = imagecreatetruecolor($fix_width, $fix_height);
            /* Fix black background */
            $white = imagecolorallocate($thumb, 255, 255, 255);
            imagefill($thumb, 0, 0, $white);
            /* Fix black background */
            /* fix quality with imagecopyresampled , repalce imagecopyresized */
            imagecopyresampled($thumb, $source, 0, 0, 0, 0, $fix_width, $fix_height, $source_width, $source_height);
            $saveto = get_file_location($file_id, FALSE) . $crop_name;
            imagejpeg($thumb, $saveto, 100);
            return get_file_url($file_id, FALSE) . $crop_name;
        }
    } else {
        return FALSE;
    }
}
示例#26
0
 /**
  * @author Matt Squirrell
  * @source http://php.net/manual/fr/function.imagecreatefromjpeg.php
  * @licence none
  * 
  * @param <i>String</i> url de l'image
  * @return <i>Image</i> copie de l'image
  */
 protected function imageCreateFromAny($filepath)
 {
     $type = exif_imagetype($filepath);
     // [] if you don't have exif you could use getImageSize()
     $allowedTypes = array(1, 2, 3, 6);
     if (!in_array($type, $allowedTypes)) {
         return "error";
     }
     switch ($type) {
         case 1:
             $im = imageCreateFromGif($filepath);
             break;
         case 2:
             $im = imageCreateFromJpeg($filepath);
             break;
         case 3:
             $im = imageCreateFromPng($filepath);
             break;
         case 6:
             $im = imageCreateFromBmp($filepath);
             break;
     }
     return $im;
 }
示例#27
0
 /**
  * Rotate an image (left or right)
  *
  * @param string $sImage Full path to the image
  * @param string $sCmd Command to perform. Must be "left" or "right" (without quotes)
  * @return mixed FALSE on failure, NULL on success
  */
 public function rotate($sImage, $sCmd, $sActualFile = null)
 {
     if (!$this->_load($sImage)) {
         return false;
     }
     switch ($this->_aInfo[2]) {
         case 1:
             $hFrm = @imageCreateFromGif($this->sPath);
             break;
         case 3:
             $hFrm = @imageCreateFromPng($this->sPath);
             break;
         default:
             $hFrm = @imageCreateFromJpeg($this->sPath);
             break;
     }
     if (substr($this->sPath, 0, 7) != 'http://') {
         @unlink($this->sPath);
     }
     if (function_exists('imagerotate')) {
         if ($sCmd == 'left') {
             $im2 = imagerotate($hFrm, 90, 0);
         } else {
             $im2 = imagerotate($hFrm, 270, 0);
         }
     } else {
         $wid = imagesx($hFrm);
         $hei = imagesy($hFrm);
         $im2 = imagecreatetruecolor($hei, $wid);
         switch ($this->sType) {
             case 'jpeg':
             case 'jpg':
             case 'jpe':
                 imagealphablending($im2, true);
                 break;
             case 'png':
                 //imagealphablending($im2, false);
                 //imagesavealpha($im2, true);
                 break;
         }
         for ($i = 0; $i < $wid; $i++) {
             for ($j = 0; $j < $hei; $j++) {
                 $ref = imagecolorat($hFrm, $i, $j);
                 if ($sCmd == 'right') {
                     imagesetpixel($im2, $hei - 1 - $j, $i, $ref);
                 } else {
                     imagesetpixel($im2, $j, $wid - $i, $ref);
                 }
             }
         }
     }
     switch ($this->sType) {
         case 'gif':
             @imagegif($im2, $this->sPath);
             break;
         case 'png':
             imagealphablending($im2, false);
             imagesavealpha($im2, true);
             @imagepng($im2, $this->sPath);
             break;
         default:
             @imagejpeg($im2, $this->sPath);
             break;
     }
     imagedestroy($hFrm);
     imagedestroy($im2);
     if (Phpfox::getParam('core.allow_cdn')) {
         Phpfox::getLib('cdn')->put($this->sPath, $sActualFile);
     }
 }
示例#28
0
 /**
  * Original source: https://stackoverflow.com/questions/12661/efficient-jpeg-image-resizing-in-php
  * Resize images for thumbnails/mobile
  * @param str $sourcefile
  * @param str $endfile
  * @param int $thumbwidth
  * @param int $thumbheight
  * @param int $quality
  */
 public function makeThumbnail($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality)
 {
     // Takes the sourcefile (path/to/image.jpg) and makes a thumbnail from it
     // and places it at endfile (path/to/thumb.jpg).
     // Load image and get image size.
     $type = exif_imagetype($sourcefile);
     // [] if you don't have exif you could use getImageSize()
     switch ($type) {
         case 1:
             $img = imageCreateFromGif($sourcefile);
             break;
         case 2:
             $img = imageCreateFromJpeg($sourcefile);
             break;
         case 3:
             $img = imageCreateFromPng($sourcefile);
             break;
         case 6:
             $img = imageCreateFromBmp($sourcefile);
             break;
     }
     $width = imagesx($img);
     $height = imagesy($img);
     // Don't make images larger than the original
     if ($thumbwidth > $width) {
         $thumbwidth = $width;
     }
     if ($thumbheight > $height) {
         $thumbheight = $height;
     }
     // Resized dimensions
     $newwidth = $thumbwidth;
     $divisor = $width / $thumbwidth;
     $newheight = floor($height / $divisor);
     // Create a new temporary image.
     $tmpimg = imagecreatetruecolor($newwidth, $newheight);
     // Copy and resize old image into new image.
     imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     // Save thumbnail into a file.
     $returnVal = imagejpeg($tmpimg, $endfile, $quality);
     // Release the memory
     imagedestroy($tmpimg);
     imagedestroy($img);
     return $returnVal;
 }
示例#29
0
 function create_image_from_any($filepath)
 {
     $type = exif_imagetype($filepath);
     // [] if you don't have exif you could use getImageSize()
     //echo $type; exit;
     $allowedTypes = array(1, 2, 3);
     if (!in_array($type, $allowedTypes)) {
         return false;
     }
     switch ($type) {
         case 1:
             $image = imageCreateFromGif($filepath);
             break;
         case 2:
             $image = imageCreateFromJpeg($filepath);
             break;
         case 3:
             $image = imageCreateFromPng($filepath);
             break;
             // case 6 :
             // $image = imageCreateFromBmp($filepath);
             // break;
     }
     return $image;
 }
示例#30
0
 public static function convert($srcFile = null, $destFile = null, $width = 0, $height = 0, $mode = self::MODE_CUT)
 {
     if (false === file_exists($srcFile)) {
         return false;
     }
     preg_match('/\\.([^\\.]+)$/', $destFile, $matches);
     switch (strtolower($matches[1])) {
         case 'jpg':
         case 'jpeg':
             $saveType = self::TYPE_JPG;
             break;
         case 'gif':
             $saveType = self::TYPE_GIF;
             break;
         case 'png':
             $saveType = self::TYPE_PNG;
             break;
         default:
             $saveType = self::TYPE_JPG;
     }
     $type = self::getImageType($srcFile);
     $srcImage = null;
     switch ($type) {
         case self::TYPE_GIF:
             $srcImage = imageCreateFromGif($srcFile);
             break;
         case self::TYPE_JPG:
             $srcImage = imageCreateFromJpeg($srcFile);
             break;
         case self::TYPE_PNG:
             $srcImage = imageCreateFromPng($srcFile);
             break;
         default:
             return false;
     }
     $srcWidth = imageSX($srcImage);
     $srcHeight = imageSY($srcImage);
     if ($width == 0 && $height == 0) {
         $width = $srcWidth;
         $height = $srcHeight;
         $mode = self::MODE_SCALE;
     } else {
         if ($width > 0 & $height == 0) {
             $useWidth = true;
             $mode = self::MODE_SCALE;
             if ($srcWidth <= $width) {
                 return self::saveFile($srcImage, $destFile, $saveType);
             }
         } else {
             if ($width == 0 && $height > 0) {
                 $mode = self::MODE_SCALE;
             }
         }
     }
     if ($mode == self::MODE_SCALE) {
         if ($width > 0 & $height > 0) {
             $useWidth = $srcWidth * $height > $srcHeight * $width ? true : false;
         }
         if (isset($useWidth) && $useWidth == true) {
             $height = $srcHeight * $width / $srcWidth;
         } else {
             $width = $srcWidth * $height / $srcHeight;
         }
     }
     $destImage = imageCreateTrueColor($width, $height);
     if ($mode == self::MODE_CUT) {
         $useWidth = $srcWidth * $height > $srcHeight * $width ? false : true;
         if ($useWidth == true) {
             $tempWidth = $width;
             $tempHeight = $srcHeight * $tempWidth / $srcWidth;
         } else {
             $tempHeight = $height;
             $tempWidth = $srcWidth * $tempHeight / $srcHeight;
         }
         $tempImage = imageCreateTrueColor($tempWidth, $tempHeight);
         $srcImage = imageCopyResampled($tempImage, $srcImage, 0, 0, 0, 0, $tempWidth, $tempHeight, $srcWidth, $srcHeight);
         imageDestroy($srcImage);
         $srcImage = $tempImage;
         $srcWidth = $width;
         $srcHeight = $srcWidth * $width / $srcHeight;
     }
     if ($mode == self::MODE_SCALE) {
         imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
     } else {
         imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $width, $height, $width, $height);
     }
     @imageDestroy($srcImage);
     return self::saveFile($destImage, $destFile, $saveType);
 }