Esempio n. 1
1
function ResizeWidthHeight($picture, $smallfile, $rewidth, $reheight)
{
    $picsize = getimagesize($picture);
    if ($picsize[2] == 1) {
        //@header("Content-Type: imgage/gif");
        $dstimg = ImageCreatetruecolor($rewidth, $reheight);
        $srcimg = @ImageCreateFromGIF($picture);
        ImageCopyResized($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg));
        Imagegif($dstimg, $smallfile, 100);
    } elseif ($picsize[2] == 2) {
        //@header("Content-Type: images/jpeg");
        $dstimg = ImageCreatetruecolor($rewidth, $reheight);
        $srcimg = ImageCreateFromJPEG($picture);
        imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg));
        Imagejpeg($dstimg, $smallfile, 100);
    } elseif ($picsize[2] == 3) {
        //@header("Content-Type: images/png");
        $srcimg = ImageCreateFromPNG($picture);
        $dstimg = imagecreate($rewidth, $reheight);
        $black = imagecolorallocate($dstimg, 0x0, 0x0, 0x0);
        $white = imagecolorallocate($dstimg, 0xff, 0xff, 0xff);
        $magenta = imagecolorallocate($dstimg, 0xff, 0x0, 0xff);
        imagecolortransparent($dstimg, $black);
        imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $rewidth, $reheight, ImageSX($srcimg), ImageSY($srcimg));
        Imagepng($dstimg, $smallfile, 0);
    }
    @ImageDestroy($dstimg);
    @ImageDestroy($srcimg);
}
Esempio n. 2
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $wh = false)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $www = $imgW * $pixelPerPoint;
     $hhh = $imgH * $pixelPerPoint;
     if (is_array($wh)) {
         $www = $wh[0];
         $hhh = $wh[1];
     }
     $target_image = ImageCreate($www, $hhh);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $www, $hhh, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
Esempio n. 3
0
function resizeImg($origPath, $mW, $mH)
{
    // Read the size
    $rst['size'] = GetImageSize($origPath);
    $w = $rst['size'][0];
    $h = $rst['size'][1];
    // Proportionally resize the image to the max sizes specified above
    $xRatio = $mW / $w;
    $yRatio = $mH / $h;
    if ($w <= $mW && $h <= $mH) {
        $tnW = $w;
        $tnH = $h;
    } elseif ($xRatio * $h < $mH) {
        $tnH = ceil($xRatio * $h);
        $tnW = $mW;
    } else {
        $tnW = ceil($yRatio * $w);
        $tnH = $mH;
    }
    // Create the new image!
    if ($rst['size']['mime'] == 'image/jpg' || $rst['size']['mime'] == 'image/jpeg') {
        $rst['src'] = imagecreatefromjpeg($origPath);
        $rst['dst'] = ImageCreateTrueColor($tnW, $tnH);
        $rst['resize'] = ImageCopyResized($rst['dst'], $rst['src'], 0, 0, 0, 0, $tnW, $tnH, $w, $h);
        $rst['imgMod'] = imagejpeg($rst['dst'], $origPath, 100);
    } else {
        $rst['note'] = 'Error with file type!';
        return false;
    }
    return $rst;
}
Esempio n. 4
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $color = array())
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
     if ($color) {
         $col[1] = ImageColorAllocate($base_image, $color[0], $color[1], $color[2]);
     } else {
         $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     }
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
Esempio n. 5
0
 function resize($newX = false, $newY = false)
 {
     if ($this->img) {
         $X = ImageSX($this->img);
         $Y = ImageSY($this->img);
         $newX = $this->_convert($newX, $X);
         $newY = $this->_convert($newY, $Y);
         if (!$newX && !$newY) {
             $newX = $X;
             $newY = $Y;
         }
         if (!$newX) {
             $newX = round($X / ($Y / $newY));
         }
         if (!$newY) {
             $newY = round($Y / ($X / $newX));
         }
         if (!($newimg = ImageCreateTruecolor($newX, $newY))) {
             $newimg = ImageCreate($newX, $newY);
         }
         if (!ImageCopyResampled($newimg, $this->img, 0, 0, 0, 0, $newX, $newY, $X, $Y)) {
             ImageCopyResized($newimg, $this->img, 0, 0, 0, 0, $newX, $newY, $X, $Y);
         }
         $this->img = $newimg;
         return true;
     } else {
         return false;
     }
 }
Esempio n. 6
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xffffff, $fore_color = 0x0)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
     $r1 = round(($fore_color & 0xff0000) >> 16, 5);
     $b1 = round(($fore_color & 0xff00) >> 8, 5);
     $g1 = round($fore_color & 0xff, 5);
     // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
     $r2 = round(($back_color & 0xff0000) >> 16, 5);
     $b2 = round(($back_color & 0xff00) >> 8, 5);
     $g2 = round($back_color & 0xff, 5);
     $col[0] = ImageColorAllocate($base_image, $r2, $b2, $g2);
     $col[1] = ImageColorAllocate($base_image, $r1, $b1, $g1);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
Esempio n. 7
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = imagecreatetruecolor($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 0, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagecolortransparent($base_image, $col[0]);
     imagealphablending($base_image, true);
     imagesavealpha($base_image, true);
     //        imagefill($base_image, 0, 0, $col[0]);
     imagefill($base_image, 0, 0, 0x7fff0000);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
Esempio n. 8
0
function ImageResize($srcFile, $toW, $toH, $toFile = "")
{
    if ($toFile == "") {
        $toFile = $srcFile;
    }
    $info = "";
    $data = GetImageSize($srcFile, $info);
    switch ($data[2]) {
        case 1:
            if (!function_exists("imagecreatefromgif")) {
                echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromGIF($srcFile);
            break;
        case 2:
            if (!function_exists("imagecreatefromjpeg")) {
                echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromJpeg($srcFile);
            break;
        case 3:
            $im = ImageCreateFromPNG($srcFile);
            break;
    }
    $srcW = ImageSX($im);
    $srcH = ImageSY($im);
    $toWH = $toW / $toH;
    $srcWH = $srcW / $srcH;
    if ($toWH <= $srcWH) {
        $ftoW = $toW;
        $ftoH = $ftoW * ($srcH / $srcW);
    } else {
        $ftoH = $toH;
        $ftoW = $ftoH * ($srcW / $srcH);
    }
    if ($srcW > $toW || $srcH > $toH) {
        if (function_exists("imagecreatetruecolor")) {
            @($ni = ImageCreateTrueColor($ftoW, $ftoH));
            if ($ni) {
                ImageCopyResampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            } else {
                $ni = ImageCreate($ftoW, $ftoH);
                ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            }
        } else {
            $ni = ImageCreate($ftoW, $ftoH);
            ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
        }
        if (function_exists('imagejpeg')) {
            ImageJpeg($ni, $toFile);
        } else {
            ImagePNG($ni, $toFile);
        }
        ImageDestroy($ni);
    }
    ImageDestroy($im);
}
function twMachThumbnail($serverPfad, $datei, $breiteThumb, $prefix)
{
    // Bild-Datei (mit Pfad)
    $bildDatei = $serverPfad . $datei;
    // wenn dieses Bild nich gefunden wurde: Abbruch
    if (!file_exists($bildDatei)) {
        return false;
    }
    // wenn dieses Bild schon ein Thumbnail ist: Abbruch
    if (substr($datei, 0, strlen($prefix)) == $prefix) {
        //echo $datei. "<br />";
        //echo strlen($prefix). "<br />";
        //echo $prefix. "<br />";
        //echo substr($datei, strlen($prefix)). "<br />";
        //echo "-----<br />";
        return false;
    }
    // Bilddaten zu dieser Bild-Datei
    $bilddaten = getimagesize($bildDatei);
    $imgOrigBreite = $bilddaten[0];
    $imgOrigHoehe = $bilddaten[1];
    $imgOrigTyp = $bilddaten[2];
    // (1=GIF, 2=JPG, 3=PNG, 4=SWF)
    if ($imgOrigBreite < $breiteThumb) {
        $breiteThumb = $imgOrigBreite;
    }
    $Skalierungsfaktor = $imgOrigBreite / $breiteThumb;
    $thumbHoehe = intval($imgOrigHoehe / $Skalierungsfaktor);
    // wenn es ein gif-Bild ist
    if ($imgOrigTyp == 1) {
        $Originalgrafik = ImageCreateFromGIF($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ImageGIF($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } elseif ($imgOrigTyp == 2) {
        $Originalgrafik = ImageCreateFromJPEG($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ///ImageJPEG($Thumbnailgrafik, $pfad."thumb_".$bild);
        ImageJPEG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } elseif ($imgOrigTyp == 3) {
        $Originalgrafik = ImageCreateFromPNG($bildDatei);
        $Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
        ImagePNG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
    } else {
        return false;
    }
    // Speicher leeren
    if ($Originalgrafik) {
        imagedestroy($Originalgrafik);
    }
    if ($Thumbnailgrafik) {
        imagedestroy($Thumbnailgrafik);
    }
}
Esempio n. 10
0
 function makeThumb($sourFile, $width = 128, $height = 128)
 {
     $imageInfo = $this->getInfo($sourFile);
     $sourFile = $this->sourcePath . $sourFile;
     $newName = substr($imageInfo["name"], 0, strrpos($imageInfo["name"], ".")) . "_thumb.jpg";
     switch ($imageInfo["type"]) {
         case 1:
             //gif
             $img = imagecreatefromgif($sourFile);
             break;
         case 2:
             //jpg
             $img = imagecreatefromjpeg($sourFile);
             break;
         case 3:
             //png
             $img = imagecreatefrompng($sourFile);
             break;
         default:
             return 0;
             break;
     }
     if (!$img) {
         return 0;
     }
     $width = $width > $imageInfo["width"] ? $imageInfo["width"] : $width;
     $height = $height > $imageInfo["height"] ? $imageInfo["height"] : $height;
     $srcW = $imageInfo["width"];
     $srcH = $imageInfo["height"];
     if ($srcW * $width > $srcH * $height) {
         $height = round($srcH * $width / $srcW);
     } else {
         $width = round($srcW * $height / $srcH);
     }
     //*
     if (function_exists("imagecreatetruecolor")) {
         $new = imagecreatetruecolor($width, $height);
         ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
     } else {
         $new = imagecreate($width, $height);
         ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
     }
     //*/
     if ($this->toFile) {
         if (file_exists($this->thumbPath . $newName)) {
             unlink($this->thumbPath . $newName);
         }
         imagejpeg($new, $this->thumbPath . $newName, 100);
         return $this->thumbPath . $newName;
     } else {
         imagejpeg($new);
     }
     imagedestroy($new);
     imagedestroy($img);
 }
Esempio n. 11
0
 /**
  * Resize Action
  *
  * For GD 2.01+ the new copyresampled function is used
  * It uses a bicubic interpolation algorithm to get far
  * better result.
  *
  * @param $new_x int  new width
  * @param $new_y int  new height
  * @param mixed $options Optional parameters
  *
  * @return true on success or PEAR Error object on error
  * @see PEAR::isError()
  */
 function _resize($new_x, $new_y, $options = null)
 {
     if ($this->resized === true) {
         return PEAR::raiseError('You have already resized the image without saving it.  Your previous resizing will be overwritten', null, PEAR_ERROR_TRIGGER, E_USER_NOTICE);
     }
     $new_img = ImageCreate($new_x, $new_y);
     ImageCopyResized($new_img, $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
     $this->old_image = $this->imageHandle;
     $this->imageHandle = $new_img;
     $this->resized = true;
     $this->new_x = $new_x;
     $this->new_y = $new_y;
     return true;
 }
Esempio n. 12
0
 static function thumb($image, $type = '', $filename = '', $maxWidth = 200, $maxHeight = 50, $interlace = true, $suffix = '_thumb')
 {
     $info = Image::getImageInfo($image);
     if ($info !== false) {
         $srcWidth = $info['width'];
         $srcHeight = $info['height'];
         $pathinfo = pathinfo($image);
         $type = $pathinfo['extension'];
         $type = empty($type) ? $info['type'] : $type;
         $type = strtolower($type);
         $interlace = $interlace ? 1 : 0;
         unset($info);
         $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
         if ($scale >= 1) {
             $width = $srcWidth;
             $height = $srcHeight;
         } else {
             $width = (int) ($srcWidth * $scale);
             $height = (int) ($srcHeight * $scale);
         }
         $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
         $srcImg = $createFun($image);
         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
             $thumbImg = imagecreatetruecolor($width, $height);
         } else {
             $thumbImg = imagecreate($width, $height);
         }
         if (function_exists("ImageCopyResampled")) {
             ImageCopyResampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         } else {
             ImageCopyResized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         }
         if ('gif' == $type || 'png' == $type) {
             $background_color = imagecolorallocate($thumbImg, 0, 255, 0);
             imagecolortransparent($thumbImg, $background_color);
         }
         if ('jpg' == $type || 'jpeg' == $type) {
             imageinterlace($thumbImg, $interlace);
         }
         $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
         $filename = empty($filename) ? substr($image, 0, strrpos($image, '.')) . $suffix . '.' . $type : $filename;
         $imageFun($thumbImg, $filename);
         ImageDestroy($thumbImg);
         ImageDestroy($srcImg);
         return $filename;
     }
     return false;
 }
Esempio n. 13
0
function resizeImage($image, $maxHeight)
{
    $width = ImageSx($image);
    $height = ImageSy($image);
    if ($height > $maxHeight) {
        $ratio = $maxHeight / $height;
        $x = $width * $ratio;
        $y = $maxHeight;
    } else {
        $x = $width;
        $y = $height;
    }
    $dst = ImageCreate($x, $y);
    ImageCopyResized($dst, $image, 0, 0, 0, 0, $x, $y, $width, $height);
    return $dst;
}
Esempio n. 14
0
 /**
  * This function cuts a image created previusly with this class, and receive: width, height and the background color
  * in rgb format. transparent color is the default color.
  * @param int $w
  * @param int $h
  * @param int $red
  * @param int $green
  * @param int $blue
  */
 public function resizeImage($w, $h, $color = null)
 {
     $width = imagesx($this->img);
     $height = imagesy($this->img);
     $proportion = $this->getImageProportion($width, $height, $w, $h);
     $this->newImg = imagecreatetruecolor($w, $h);
     if ($color == null) {
         $transparent = imagecolorallocate($this->newImg, 0, 0, 0);
         imagecolortransparent($this->newImg, $transparent);
     } else {
         $rgb = $this->convertFromHexToRgbColor($color);
         imagecolorallocate($this->newImg, $rgb->red, $rgb->green, $rgb->blue);
     }
     ImageCopyResized($this->newImg, $this->img, $proportion['x'], $proportion['y'], 0, 0, $proportion['newWidth'], $proportion['newHeight'], $width, $height);
     $this->img = $this->newImg;
 }
Esempio n. 15
0
 /**
  * @todo  缩略图
  * @param string $src  大图路径
  * @param string $to   小图路径
  * @param int $to_w    小图宽度
  * @param int $to_h    小图高度
  * @return boolean|string
  */
 public static function smallImg($src, $to, $to_w, $to_h)
 {
     $data = getimagesize($src);
     //0为宽,1为高,2为类型
     $srcW = $data[0];
     $srcH = $data[1];
     switch ($data[2]) {
         case 1:
             //图片类型,1是GIF图
             $im = @ImageCreateFromGIF($src);
             break;
         case 2:
             //图片类型,2是JPG图
             $im = @imagecreatefromjpeg($src);
             break;
         case 3:
             //图片类型,3是PNG图
             $im = @ImageCreateFromPNG($src);
             break;
     }
     if (empty($im)) {
         return false;
     }
     $to_w = $to_w > $srcW ? $srcW : $to_w;
     $to_h = $to_h > $srcH ? $srcH : $to_h;
     if ($srcW * $to_w > $srcH * $to_h) {
         $to_h = round($srcH * $to_w / $srcW);
     } else {
         $to_w = round($srcW * $to_h / $srcH);
     }
     if (function_exists("imagecreatetruecolor")) {
         $newImg = imagecreatetruecolor($to_w, $to_h);
         ImageCopyResampled($newImg, $im, 0, 0, 0, 0, $to_w, $to_h, $srcW, $srcH);
     } else {
         $newImg = imagecreate($to_w, $to_h);
         ImageCopyResized($newImg, $im, 0, 0, 0, 0, $to_w, $to_h, $srcW, $srcH);
     }
     $todir = dirname($to);
     if (!is_dir($todir)) {
         @mkdir($todir, 0777, true);
     }
     imagejpeg($newImg, $to);
     imagedestroy($newImg);
     imagedestroy($im);
     return $to;
 }
function twMachThumbnail($pfad, $bild, $thumbBreite)
{
    $bildMitPfad = $pfad . $bild;
    // wenn Bild nich gefunden wurde: Abbruch
    if (!file_exists($bildMitPfad)) {
        return false;
    }
    $bilddaten = getimagesize($bildMitPfad);
    $origBreite = $bilddaten[0];
    $origHoehe = $bilddaten[1];
    if ($origBreite < $thumbBreite) {
        $thumbBreite = $origBreite;
    }
    $Skalierungsfaktor = $origBreite / $thumbBreite;
    $thumbHoehe = intval($origHoehe / $Skalierungsfaktor);
    // wenn es ein gif-Bild ist
    if ($bilddaten[2] == 1) {
        $Originalgrafik = ImageCreateFromGIF($bildMitPfad);
        $Thumbnailgrafik = ImageCreateTrueColor($thumbBreite, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $thumbBreite, $thumbHoehe, $origBreite, $origHoehe);
        ImageGIF($Thumbnailgrafik, $pfad . "thumb_" . $bild);
    } elseif ($bilddaten[2] == 2) {
        $Originalgrafik = ImageCreateFromJPEG($bildMitPfad);
        $Thumbnailgrafik = ImageCreateTrueColor($thumbBreite, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $thumbBreite, $thumbHoehe, $origBreite, $origHoehe);
        ///ImageJPEG($Thumbnailgrafik, $pfad."thumb_".$bild);
        ImageJPEG($Thumbnailgrafik, $pfad . "thumb_" . $bild);
    } elseif ($bilddaten[2] == 3) {
        $Originalgrafik = ImageCreateFromPNG($bildMitPfad);
        $Thumbnailgrafik = ImageCreateTrueColor($thumbBreite, $thumbHoehe);
        ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $thumbBreite, $thumbHoehe, $origBreite, $origHoehe);
        ImagePNG($Thumbnailgrafik, $pfad . "thumb_" . $bild);
    } else {
        return false;
    }
    // Speicher leeren
    if ($Originalgrafik) {
        imagedestroy($Originalgrafik);
    }
    if ($Thumbnailgrafik) {
        imagedestroy($Thumbnailgrafik);
    }
}
Esempio n. 17
0
 function show($w, $h)
 {
     if ($this->getDBData() !== false) {
         $file = OTV_UPLOADS . "/" . $this->id . ".jpg";
         if (file_exists($file)) {
             list($fullw, $fullh, $type) = getimagesize($file);
             $im = ImageCreateFromJPEG($file);
             $im_rsz = ImageCreateTrueColor($w, $h);
             ImageCopyResized($im_rsz, $im, 0, 0, 0, 0, $w, $h, $fullw, $fullh);
             header("Content-type: image/jpg");
             ImageJPEG($im_rsz);
             ImageDestroy($im_rsz);
             ImageDestroy($im);
             return true;
         }
         return false;
     } else {
         echo "no db data";
     }
     return false;
 }
Esempio n. 18
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = imagecreate($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, QRImage::$black[0], QRImage::$black[1], QRImage::$black[2]);
     $col[1] = ImageColorAllocate($base_image, QRImage::$white[0], QRImage::$white[1], QRImage::$white[2]);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = imagecreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
Esempio n. 19
0
 function RedimensionarImagen($imagen, $tam = 125)
 {
     $imgInfo = getimagesize($imagen);
     if ($imgInfo['mime'] == "image/jpeg" || $imgInfo['mime'] == "image/jpg") {
         $original = ImageCreateFromJPEG($imagen);
     }
     if ($imgInfo['mime'] == "image/png") {
         $original = imagecreatefrompng($imagen);
     }
     $imgWidth = $tam;
     $imgHeight = imagesy($original) / (imagesx($original) / $imgWidth);
     $thumb = imagecreatetruecolor($imgWidth, $imgHeight);
     ImageCopyResized($thumb, $original, 0, 0, 0, 0, $imgWidth, $imgHeight, imagesx($original), imagesy($original));
     imagefilter($thumb, IMG_FILTER_SMOOTH, 90);
     header('Content-Type: ' . $imgInfo['mime']);
     if ($imgInfo['mime'] == "image/jpeg" || $imgInfo['mime'] == "image/jpg") {
         imagejpeg($thumb, NULL, 100);
     }
     if ($imgInfo['mime'] == "image/png") {
         imagepng($thumb);
     }
 }
Esempio n. 20
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $QR_COLOR, $QR_COLORBG)
 {
     $h = count($frame);
     $w = strlen(trim($frame[0]));
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = ImageCreate($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, $QR_COLORBG["R"], $QR_COLORBG["G"], $QR_COLORBG["B"]);
     $col[1] = ImageColorAllocate($base_image, $QR_COLOR["R"], $QR_COLOR["G"], $QR_COLOR["B"]);
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
Esempio n. 21
0
 function imageZoom($srcFile, $dstW = '', $dstH = '', $url = '')
 {
     header("Content-type: image/jpeg");
     $data = GetImageSize($srcFile, $info);
     switch ($data[2]) {
         case 1:
             $im = @ImageCreateFromGIF($srcFile);
             break;
         case 2:
             $im = @ImageCreateFromJPEG($srcFile);
             break;
         case 3:
             $im = @ImageCreateFromPNG($srcFile);
             break;
     }
     $srcW = ImageSX($im);
     $srcH = ImageSY($im);
     $newsize = $this->getZoomSize($srcW, $srcH, $dstW, $dstH);
     $dstW = $newsize[0];
     $dstH = $newsize[1];
     if (function_exists("ImageCreateTruecolor")) {
         $ni = ImageCreateTruecolor($dstW, $dstH);
     } else {
         $ni = ImageCreate($dstW, $dstH);
     }
     ImageCopyResized($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
     if ($url == "") {
         imagejpeg($ni);
     } else {
         if (!imagejpeg($ni, $url)) {
             return new sfException(lang::get("Was error!"));
         }
     }
     ImageDestroy($ni);
     ImageDestroy($im);
 }
Esempio n. 22
0
function thumbnailImage($imageBitsIn, $contentType)
{
    // Create a GD image
    $imageIn = ImageCreateFromString($imageBitsIn);
    // Measure the image
    $inX = ImageSx($imageIn);
    $inY = ImageSy($imageIn);
    // Decide how to scale it
    if ($inX > $inY) {
        $outX = THUMB_SIZE;
        $outY = (int) (THUMB_SIZE * ((double) $inY / $inX));
    } else {
        $outX = (int) (THUMB_SIZE * ((double) $inX / $inY));
        $outY = THUMB_SIZE;
    }
    // Create thumbnail image and fill it with white
    $imageOut = ImageCreateTrueColor($outX, $outY);
    ImageFill($imageOut, 0, 0, ImageColorAllocate($imageOut, 255, 255, 255));
    // Copy / resize the original image into the thumbnail image
    ImageCopyResized($imageOut, $imageIn, 0, 0, 0, 0, $outX, $outY, $inX, $inY);
    // Write the image to a temporary file in the requested format
    $fileOut = tempnam("/tmp", "aws") . ".aws";
    switch ($contentType) {
        case "image/jpg":
            $ret = ImageJPEG($imageOut, $fileOut, 100);
            break;
        case "image/png":
            $ret = ImagePNG($imageOut, $fileOut, 0);
            break;
        case "image/gif":
            $ret = ImageGIF($imageOut, $fileOut);
            break;
        default:
            unlink($fileOut);
            return false;
    }
    // Verify success
    if (!$ret) {
        unlink($fileOut);
        return false;
    }
    // Read the image back in
    $imageBitsOut = file_get_contents($fileOut);
    // Clean up
    unlink($fileOut);
    return $imageBitsOut;
}
Esempio n. 23
0
/**
 * make thumbnail image and save
 */
function thumbnail($file, $save_filename, $max_width = 100, $max_height = 100, $sizeChg = 1)
{
    $img_info = @getimagesize($file);
    //이미지 사이즈를 확인합니다.
    //이미지 타입을 이용해 변수를 재지정해줍니다.
    //------------------------------------------------------
    // Imagetype Constants
    //------------------------------------------------------
    // 1 IMAGETYPE_GIF
    // 2 IMAGETYPE_JPEG
    // 3 IMAGETYPE_PNG
    // 4 IMAGETYPE_SWF
    // 5 IMAGETYPE_PSD
    // 6 IMAGETYPE_BMP
    // 7 IMAGETYPE_TIFF_II (intel byte order)
    // 8 IMAGETYPE_TIFF_MM (motorola byte order)
    // 9 IMAGETYPE_JPC
    // 10 IMAGETYPE_JP2
    // 11 IMAGETYPE_JPX
    // 12 IMAGETYPE_JB2
    // 13 IMAGETYPE_SWC
    // 14 IMAGETYPE_IFF
    // 15 IMAGETYPE_WBMP
    // 16 IMAGETYPE_XBM
    //------------------------------------------------------
    if ($img_info[2] == 1) {
        $src_img = ImageCreateFromGIF($file);
    } elseif ($img_info[2] == 2) {
        $src_img = ImageCreateFromJPEG($file);
    } elseif ($img_info[2] == 3) {
        $src_img = ImageCreateFromPNG($file);
    } elseif ($img_info[2] == 4) {
        $src_img = ImageCreateFromWBMP($file);
    } else {
        return false;
    }
    $img_info = getImageSize($file);
    //원본이미지의 정보를 얻어옵니다
    $img_width = $img_info[0];
    $img_height = $img_info[1];
    $crt_width = $max_width;
    //생성되면 이미지 사이즈
    $crt_height = $max_height;
    //1.가로 세로 원본비율을 맞추고, 남은 영역에 색채워서 정해진 크기로 생성
    if ($sizeChg == 1) {
        if ($img_width / $max_width == $img_height / $max_height) {
            //원본과 썸네일의 가로세로비율이 같은경우
            $dst_x = 0;
            $dst_y = 0;
            $dst_width = $max_width;
            $dst_height = $max_height;
        } elseif ($img_width / $max_width < $img_height / $max_height) {
            //세로에 기준을 둔경우
            $dst_x = ($max_width - $img_width * ($max_height / $img_height)) / 2;
            $dst_y = 0;
            $dst_width = $max_height * ($img_width / $img_height);
            $dst_height = $max_height;
        } else {
            //가로에 기준을 둔경우
            $dst_x = 0;
            $dst_y = ($max_height - $img_height * ($max_width / $img_width)) / 2;
            $dst_width = $max_width;
            $dst_height = $max_width * ($img_height / $img_width);
        }
        //2.가로 세로 원본비율을 맞추고, 남은 영역없이 이미지만 컷 생성
    } else {
        if ($sizeChg == 2) {
            if ($img_width / $max_width == $img_height / $max_height) {
                //원본과 썸네일의 가로세로비율이 같은경우
                $dst_width = $max_width;
                $dst_height = $max_height;
            } elseif ($img_width / $max_width < $img_height / $max_height) {
                //세로에 기준을 둔경우
                $dst_width = $max_height * ($img_width / $img_height);
                $dst_height = $max_height;
            } else {
                //가로에 기준을 둔경우
                $dst_width = $max_width;
                $dst_height = $max_width * ($img_height / $img_width);
            }
            $dst_x = 0;
            $dst_y = 0;
            $crt_width = $dst_width;
            $crt_height = $dst_height;
            //3.가로 세로 원본비율을 맞추지 않고, 정해진 크기대로 생성
        } else {
            $dst_width = $max_width;
            $dst_height = $max_height;
            $dst_x = 0;
            $dst_y = 0;
        }
    }
    $dst_img = imagecreatetruecolor($crt_width, $crt_height);
    //타겟이미지를 생성합니다
    $white = imagecolorallocate($dst_img, 255, 255, 255);
    imagefill($dst_img, 0, 0, $white);
    ImageCopyResized($dst_img, $src_img, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $img_width, $img_height);
    //타겟이미지에 원하는 사이즈의 이미지를 저장합니다
    ImageInterlace($dst_img);
    switch ($img_info[2]) {
        case "1":
            ImageGIF($dst_img, $save_filename);
            break;
        case "2":
            ImageJPEG($dst_img, $save_filename);
            break;
        case "3":
            imagealphablending($dst_img, false);
            imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $img_width, $img_height);
            //(생성이미지,원소스이미지,시작점X,시작점Y,원본소스상 시작점X,원본소스상 시작점Y,생성이미지너비, 생성이미지높이,원이미지너비,원이미지높이)
            imagesavealpha($dst_img, true);
            ImagePNG($dst_img, $save_filename, 0);
            break;
        case "4":
            ImageWBMP($dst_img, $save_filename);
            break;
    }
    ImageDestroy($dst_img);
    ImageDestroy($src_img);
}
 /**
  * resize the image and return the thumbnail image  details array("width"=>, "height"=>, "name")
  *
  * @param string $fileName 
  * @param int $new_x the thumbnail width
  * @param int $new_y the thumbnail height
  * @return unknown
  */
 function _resize($fileName, $new_x, $new_y)
 {
     $functionName = 'ImageCreateFrom' . $this->fileType;
     if (function_exists($functionName)) {
         $this->imgHandler = $functionName($this->filePath);
     } else {
         array_push($this->errors, $functionName . " function is unavailable");
         return false;
     }
     if (function_exists('ImageCreateTrueColor')) {
         $new_img = ImageCreateTrueColor($new_x, $new_y);
     } else {
         $new_img = ImageCreate($new_x, $new_y);
     }
     if (function_exists('ImageCopyResampled')) {
         ImageCopyResampled($new_img, $this->imgHandler, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
     } else {
         ImageCopyResized($new_img, $this->imgHandler, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
     }
     if ($this->_imageSave($new_img, $fileName, 80)) {
         return array("width" => $new_x, "height" => $new_y, "name" => basename($fileName));
     } else {
         array_push($this->errors, "Unable to resize the image");
         return false;
     }
 }
Esempio n. 25
0
function upload_image($newname = NULL, $wwidth, $lwidth, $thumbwidth, $hide_display = NULL)
{
    global $base_path_amp, $gd_version;
    $picdir = AMP_LOCAL_PATH . DIRECTORY_SEPARATOR . "img/original";
    $thumbdir = AMP_LOCAL_PATH . DIRECTORY_SEPARATOR . "img/thumb";
    $usedir = AMP_LOCAL_PATH . DIRECTORY_SEPARATOR . "img/pic";
    $addition = "";
    $newext = "jpg";
    $array = explode(".", $_FILES['file']['name']);
    $filename = $array[0];
    $extension = strtolower($array[1]);
    if ($_FILES['file']['name'] == "") {
    } else {
        if (!($extension == jpe or $extension == jpg or $extension == jpeg)) {
            $response = "<b>The attached file is not a jpeg!</b>";
        } else {
            if ($newname) {
                $filename = $newname;
            }
            $smallimage = "{$thumbdir}" . "/" . "{$filename}" . "{$addition}" . "." . "{$newext}";
            $useimage = "{$usedir}" . "/" . "{$filename}" . "{$addition}" . "." . "{$newext}";
            $original = "{$picdir}" . "/" . "{$filename}" . "." . "{$newext}";
            if (file_exists($original)) {
                $response = "<b>A file with this name already exists  on the server</b>";
            } else {
                if (move_uploaded_file($_FILES['file']['tmp_name'], $original)) {
                    $response = "<b>File is valid, and was successfully uploaded.</b>";
                } else {
                    $response = "<b>File uploaded failed.</b>";
                }
                if (!copy($original, $useimage)) {
                    echo "<b>failed to copy {$useimage}...\n</b>";
                }
                if (!copy($original, $smallimage)) {
                    echo "<b>failed to copy {$smallimage}...\n</b>";
                }
                chmod($smallimage, 0755);
                chmod($useimage, 0755);
                chmod($original, 0755);
                if (file_exists($smallimage)) {
                    $image = imagecreatefromjpeg("{$smallimage}");
                    $ywert = imagesy($image);
                    $xwert = imagesx($image);
                    if ($xwert > $ywert) {
                        $verh = $xwert / $ywert;
                        $newwidth = $thumbwidth;
                        $newheight = $newwidth / $verh;
                    } else {
                        $verh = $ywert / $xwert;
                        $newwidth = $thumbwidth;
                        $newheight = $newwidth * $verh;
                    }
                    if ($gd_version >= 2.0) {
                        $destimage = ImageCreateTrueColor($newwidth, $newheight);
                        ImageCopyResampled($destimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $xwert, $ywert);
                    } else {
                        $destimage = ImageCreate($newwidth, $newheight);
                        ImageCopyResized($destimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $xwert, $ywert);
                    }
                    imagejpeg($destimage, $smallimage);
                }
                if (file_exists($useimage)) {
                    $image = imagecreatefromjpeg("{$useimage}");
                    $ywert = imagesy($image);
                    $xwert = imagesx($image);
                    if ($xwert > $ywert) {
                        $verh = $xwert / $ywert;
                        $newwidth = $wwidth;
                        $newheight = $newwidth / $verh;
                    } else {
                        $verh = $ywert / $xwert;
                        $newwidth = $lwidth;
                        $newheight = $newwidth * $verh;
                    }
                    if ($gd_version >= 2.0) {
                        $destimage = ImageCreateTrueColor($newwidth, $newheight);
                        ImageCopyResampled($destimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $xwert, $ywert);
                    } else {
                        $destimage = ImageCreate($newwidth, $newheight);
                        ImageCopyResized($destimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $xwert, $ywert);
                    }
                    imagejpeg($destimage, $useimage);
                }
            }
        }
    }
    if (isset($original)) {
        $response .= '<hr><table>';
        $response .= '<tr><td>Thumbnail:<td><td>' . $smallimage . '</td><td><img src="../img/thumb/' . $filename . $addition . "." . $newext . "\"></td></tr>";
        $response .= '<tr><td>Optimized:<td><td>' . $useimage . '</td><td><img src="../img/pic/' . $filename . $addition . "." . $newext . "\"></td></tr>";
        $response .= '<tr><td>Original:<td><td>' . $original . '</td><td><img src="../img/original/' . $filename . $addition . "." . $newext . "\"></td></tr>";
        $response .= '</table><hr><br>';
    }
    if (!$hide_display) {
        echo $response;
    }
    $image = $filename . $addition . "." . $newext;
    return $image;
}
Esempio n. 26
0
function fUploadimg_process($file, $Store_dir, $simp = "N")
{
    global $config, $_POST;
    $mime_types = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/pjpeg', 'jpe' => 'image/jpeg', 'bmp' => 'image/bmp', 'png' => 'image/png', 'ppng' => 'image/x-png', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'pict' => 'image/x-pict', 'pic' => 'image/x-pict', 'pct' => 'image/x-pict', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'psd' => 'image/x-photoshop', 'swf' => 'application/x-shockwave-flash', 'js' => 'application/x-javascript', 'pdf' => 'application/pdf', 'ps' => 'application/postscript', 'eps' => 'application/postscript', 'ai' => 'application/postscript', 'wmf' => 'application/x-msmetafile', 'mid' => 'audio/midi', 'wav' => 'audio/wav', 'mp3' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'avi' => 'video/x-msvideo', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'lha' => 'application/x-lha', 'lzh' => 'application/x-lha', 'z' => 'application/x-compress', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', 'gzip' => 'application/x-gzip', 'tgz' => 'application/x-gzip', 'tar' => 'application/x-tar', 'bz2' => 'application/bzip2', 'zip' => 'application/zip', 'arj' => 'application/x-arj', 'rar' => 'application/octet-stream', 'rars' => 'application/x-rar-compressed', 'word' => 'application/msword');
    if (in_array($file['type'], $mime_types) && $file['error'] == '0') {
        $Image = explode(".", $file['name']);
        $Num = count($Image) - 1;
        $Suffix = strtolower($Image[$Num]);
        $Fname = date("YmdHis") . $_POST['fileKey'];
        if ($file['size'] > $config['size']) {
            header("Location: update.php?action=error&error=" . urlencode("文件太大不能上传"));
            exit;
        }
        //fMessage('file max');
        if ($file['size'] == 0) {
            header("Location: update.php?action=error&error=" . urlencode("文件不能为空信息"));
            exit;
        }
        if (is_dir(R_P . $Store_dir) !== TRUE) {
            mkdir(R_P . $Store_dir, 0777);
        }
        $Picpath = R_P . $Store_dir . $Fname . "." . $Suffix;
        if (!copy($file['tmp_name'], $Picpath)) {
            if (!move_uploaded_file($file['tmp_name'], $Picpath)) {
                fMessage('file lost', "index.php?action=member&option=info");
            }
        }
        chmod($Picpath, 0777);
        if ($simp != "N") {
            $PicSource = R_P . $Store_dir . $simp . $Fname . "." . $Suffix;
            if (is_dir(R_P . $Store_dir . $simp) !== TRUE) {
                mkdir(R_P . $Store_dir . $simp, 0777);
            }
            if ($file['type'] == 'image/gif') {
                $im = imagecreatefromgif($Picpath);
            } elseif ($file['type'] == 'image/jpeg' || ($file['type'] = 'image/pjpeg')) {
                $im = imagecreatefromjpeg($Picpath);
            } else {
                $im = imagecreatefrompng($Picpath);
            }
            $srcW = ImageSX($im);
            $srcH = ImageSY($im);
            if ($srcW < 120 && $srcH < 120) {
                copy($Picpath, $PicSource);
            } else {
                if ($srcW > $srcH) {
                    $withe = 120;
                    $height = intval($withe * $srcH / $srcW);
                } elseif ($srcH > $srcW) {
                    $height = 120;
                    $withe = intval($height * $srcW / $srcH);
                } else {
                    $height = $srcH;
                    $withe = $srcW;
                }
                //$ni=ImageCreate($withe,$heigh);//建立一张空图
                $ni = imagecreatetruecolor($withe, $height);
                //建立一张空图
                imagealphablending($ni, false);
                ImageCopyResized($ni, $im, 0, 0, 0, 0, $withe, $height, $srcW, $srcH);
                //按0,0,0,0的坐标开始
                if ($file['type'] == 'image/gif') {
                    imagegif($ni, $PicSource);
                } elseif ($file['type'] == 'image/jpeg') {
                    imagejpeg($ni, $PicSource);
                } else {
                    Imagepng($ni, $PicSource);
                }
            }
            chmod($PicSource, 0777);
        }
        return $Fname . "." . $Suffix;
    }
    header("Location: update.php?action=error&error=" . urlencode("上传文件格式不符合"));
    die("上传文件格式不符合");
}
Esempio n. 27
0
 /**
 +----------------------------------------------------------
 * 生成缩略图
 +----------------------------------------------------------
 * @static
 * @access public
 +----------------------------------------------------------
 * @param string $image  原图
 * @param string $type 图像格式
 * @param string $filename 缩略图文件名
 * @param string $maxWidth  宽度
 * @param string $maxHeight  高度
 * @param string $position 缩略图保存目录
 * @param boolean $interlace 启用隔行扫描
 +----------------------------------------------------------
 * @return void
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 static function thumb($image, $type = '', $filename = '', $maxWidth = 200, $maxHeight = 50, $interlace = true, $suffix = '_thumb')
 {
     // 获取原图信息
     $info = Image::getImageInfo($image);
     if ($info == false) {
         file_put_contents('1.txt', 'wrong');
     }
     if ($info !== false) {
         $srcWidth = $info['width'];
         $srcHeight = $info['height'];
         $pathinfo = pathinfo($image);
         $type = $pathinfo['extension'];
         $type = empty($type) ? $info['type'] : $type;
         $type = strtolower($type);
         $interlace = $interlace ? 1 : 0;
         unset($info);
         $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
         // 计算缩放比例
         // 缩略图尺寸
         $width = (int) ($srcWidth * $scale);
         $height = (int) ($srcHeight * $scale);
         // 载入原图
         $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
         $srcImg = $createFun($image);
         //创建缩略图
         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
             $thumbImg = imagecreatetruecolor($width, $height);
         } else {
             $thumbImg = imagecreate($width, $height);
         }
         // 复制图片
         if (function_exists("ImageCopyResampled")) {
             ImageCopyResampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         } else {
             ImageCopyResized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         }
         if ('gif' == $type || 'png' == $type) {
             //imagealphablending($thumbImg, false);//取消默认的混色模式
             //imagesavealpha($thumbImg,true);//设定保存完整的 alpha 通道信息
             $background_color = imagecolorallocate($thumbImg, 0, 255, 0);
             //  指派一个绿色
             imagecolortransparent($thumbImg, $background_color);
             //  设置为透明色,若注释掉该行则输出绿色的图
         }
         // 对jpeg图形设置隔行扫描
         if ('jpg' == $type || 'jpeg' == $type) {
             imageinterlace($thumbImg, $interlace);
         }
         // 生成图片
         $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
         $filename = empty($filename) ? substr($image, 0, strrpos($image, '.')) . $suffix . '.' . $type : $filename;
         $imageFun($thumbImg, $filename);
         ImageDestroy($thumbImg);
         ImageDestroy($srcImg);
         return $filename;
     }
     return false;
 }
Esempio n. 28
0
 function makeThumbWatermark($width = 128, $height = 128)
 {
     $this->fileCheck();
     $image_info = $this->getInfo($this->src_image_name);
     if (!$image_info) {
         return false;
     }
     $src_image_type = $image_info["type"];
     $img = $this->createImage($src_image_type, $this->src_image_name);
     if (!$img) {
         return false;
     }
     $width = $width == 0 ? $image_info["width"] : $width;
     $height = $height == 0 ? $image_info["height"] : $height;
     $width = $width > $image_info["width"] ? $image_info["width"] : $width;
     $height = $height > $image_info["height"] ? $image_info["height"] : $height;
     $srcW = $image_info["width"];
     $srcH = $image_info["height"];
     if ($srcH * $width > $srcW * $height) {
         $width = round($srcW * $height / $srcH);
     } else {
         $height = round($srcH * $width / $srcW);
     }
     //*
     $src_image = @imagecreatetruecolor($width, $height);
     $white = @imagecolorallocate($src_image, 0xff, 0xff, 0xff);
     @imagecolortransparent($src_image, $white);
     @imagefilltoborder($src_image, 0, 0, $white, $white);
     if ($src_image) {
         ImageCopyResampled($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     } else {
         $src_image = imagecreate($width, $height);
         ImageCopyResized($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     }
     $src_image_w = ImageSX($src_image);
     $src_image_h = ImageSY($src_image);
     if ($this->wm_image_name) {
         $wm_image_info = $this->getInfo($this->wm_image_name);
         if (!$wm_image_info) {
             return false;
         }
         $wm_image_type = $wm_image_info["type"];
         $wm_image = $this->createImage($wm_image_type, $this->wm_image_name);
         $wm_image_w = ImageSX($wm_image);
         $wm_image_h = ImageSY($wm_image);
         $temp_wm_image = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos, $wm_image);
         if ($this->emboss && function_exists("imagefilter")) {
             imagefilter($wm_image, IMG_FILTER_EMBOSS);
             $bgcolor = imagecolorclosest($wm_image, 0x7f, 0x7f, 0x7f);
             imagecolortransparent($wm_image, $bgcolor);
         }
         if (function_exists("ImageAlphaBlending") && IMAGETYPE_PNG == $wm_image_info['type']) {
             ImageAlphaBlending($src_image, true);
         }
         $wm_image_x = $temp_wm_image["dest_x"];
         $wm_image_y = $temp_wm_image["dest_y"];
         if (IMAGETYPE_PNG == $wm_image_info['type']) {
             imageCopy($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h);
         } else {
             imageCopyMerge($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h, $this->wm_image_transition);
         }
     }
     if ($this->wm_text) {
         $this->wm_text = $this->wm_text;
         $temp_wm_text = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos);
         $wm_text_x = $temp_wm_text["dest_x"];
         $wm_text_y = $temp_wm_text["dest_y"];
         if (preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->wm_text_color, $color)) {
             $red = hexdec($color[1]);
             $green = hexdec($color[2]);
             $blue = hexdec($color[3]);
             $wm_text_color = imagecolorallocate($src_image, $red, $green, $blue);
         } else {
             $wm_text_color = imagecolorallocate($src_image, 255, 255, 255);
         }
         imagettftext($src_image, $this->wm_text_size, $this->wm_angle, $wm_text_x, $wm_text_y, $wm_text_color, $this->wm_text_font, $this->wm_text);
     }
     if ($this->save_file) {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     $src_img = ImageGIF($src_image, $this->save_file);
                 } else {
                     $src_img = ImagePNG($src_image, $this->save_file);
                 }
                 break;
             case 2:
                 $src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
                 break;
             case 3:
                 $src_img = ImagePNG($src_image, $this->save_file);
                 break;
             default:
                 $src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
                 break;
         }
     } else {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     header("Content-type: image/gif");
                     $src_img = ImageGIF($src_image);
                 } else {
                     header("Content-type: image/png");
                     $src_img = ImagePNG($src_image);
                 }
                 break;
             case 2:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($src_image, "", $this->jpeg_quality);
                 break;
             case 3:
                 header("Content-type: image/png");
                 $src_img = ImagePNG($src_image);
                 break;
             case 6:
                 header("Content-type: image/bmp");
                 $src_img = imagebmp($src_image);
                 break;
             default:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($src_image, "", $this->jpeg_quality);
                 break;
         }
     }
     imagedestroy($src_image);
     imagedestroy($img);
     return true;
 }
Esempio n. 29
0
 /**
  * Crop the image
  *
  * @param int $crop_x left column of the image
  * @param int $crop_y top row of the image
  * @param int $crop_width new cropped image width
  * @param int $crop_height new cropped image height
  */
 function crop($new_x, $new_y, $new_width, $new_height)
 {
     if (function_exists('ImageCreateTrueColor')) {
         $new_img = $this->newImgPreserveAlpha(ImageCreateTrueColor($new_width, $new_height));
     } else {
         $new_img = ImageCreate($new_width, $new_height);
     }
     if (function_exists('ImageCopyResampled')) {
         ImageCopyResampled($new_img, $this->imageHandle, 0, 0, $new_x, $new_y, $new_width, $new_height, $new_width, $new_height);
     } else {
         ImageCopyResized($new_img, $this->imageHandle, 0, 0, $new_x, $new_y, $new_width, $new_height, $new_width, $new_height);
     }
     $this->old_image = $this->imageHandle;
     $this->imageHandle = $new_img;
     $this->resized = true;
     $this->new_x = $new_x;
     $this->new_y = $new_y;
     return true;
 }
Esempio n. 30
-1
 function mkimage($data)
 {
     $data_array = explode("\n", $data);
     $c = count($data_array) - 1;
     $image_size = $c;
     $output_size = ($c + $this->quiet_zone * 2) * $this->module_size;
     $img = ImageCreate($image_size, $image_size);
     $white = ImageColorAllocate($img, 255, 255, 255);
     $black = ImageColorAllocate($img, 0, 0, 0);
     $im = ImageCreate($output_size, $output_size);
     $white2 = ImageColorAllocate($im, 255, 255, 255);
     ImageFill($im, 0, 0, $white2);
     $y = 0;
     foreach ($data_array as $row) {
         $x = 0;
         while ($x < $image_size) {
             if (substr($row, $x, 1) == "1") {
                 ImageSetPixel($img, $x, $y, $black);
             }
             $x++;
         }
         $y++;
     }
     $quiet_zone_offset = $this->quiet_zone * $this->module_size;
     $image_width = $image_size * $this->module_size;
     ImageCopyResized($im, $img, $quiet_zone_offset, $quiet_zone_offset, 0, 0, $image_width, $image_width, $image_size, $image_size);
     return $im;
 }