private function cropBilde($sti, $filnavn, $nyttFilnavn, $cropBredde, $cropHoyde)
 {
     $gammeltBilde = $sti . $filnavn;
     $bi = @ImageCreateFromJPEG($gammeltBilde) or $bi = @ImageCreateFromPNG($gammeltBilde) or $bi = @ImageCreateFromGIF($gammeltBilde) or $bi = false;
     if ($bi) {
         $naStorrelse = @getimagesize($gammeltBilde);
         $bredde = $naStorrelse[0];
         $hoyde = $naStorrelse[1];
         $nyBreddeNy = $bredde / $cropBredde;
         $nyHoydeNy = $hoyde / $cropHoyde;
         $halvertHoyde = $cropHoyde / 2;
         $halvertBredde = $cropBredde / 2;
         $thumb = @ImageCreateTrueColor($cropBredde, $cropHoyde);
         if ($bredde > $hoyde) {
             $tilpassetBredde = $bredde / $nyHoydeNy;
             $halvBredde = $tilpassetBredde / 2;
             $intBredde = $halvBredde - $halvertBredde;
             @ImageCopyResampled($thumb, $bi, -$intBredde, 0, 0, 0, $tilpassetBredde, $cropHoyde, $bredde, $hoyde);
         } elseif ($bredde < $hoyde || $bredde == $hoyde) {
             $tilPassetHoyde = $hoyde / $nyBreddeNy;
             $halvHoyde = $tilPassetHoyde / 2;
             $intHoyde = $halvHoyde - $halvertHoyde;
             @ImageCopyResampled($thumb, $bi, 0, -$intHoyde, 0, 0, $cropBredde, $tilPassetHoyde, $bredde, $hoyde);
         } else {
             @ImageCopyResampled($thumb, $bi, 0, 0, 0, 0, $cropBredde, $cropHoyde, $bredde, $hoyde);
         }
         @imagejpeg($thumb, $sti . $nyttFilnavn, 50);
         return $nyttFilnavn;
     } else {
         return -1;
     }
 }
Beispiel #2
0
 function open_image($file = null)
 {
     $image_type = $this->image_type($file);
     if (!$image_type) {
         trigger_error("Invalid image file: {$file}.", E_USER_ERROR);
     }
     $this->type = $image_type[0];
     $this->width = $image_type[1];
     $this->height = $image_type[2];
     if (!in_array($this->type, $this->supported_img_types)) {
         trigger_error("File type '{$this->type}' not supported.", E_USER_ERROR);
     }
     // Destroy if already open
     if ($this->image) {
         ImageDestroy($this->image);
     }
     switch ($this->type) {
         case 'JPG':
             $this->image = ImageCreateFromJPEG($file);
             break;
         case 'GIF':
             $this->image = ImageCreateFromGIF($file);
             break;
         case 'PNG':
             $this->image = ImageCreateFromPNG($file);
             break;
     }
 }
Beispiel #3
0
 function SetVar($srcFile, $echoType)
 {
     if (!file_exists($srcFile)) {
         echo '源图片文件不存在!';
         exit;
     }
     $this->srcFile = $srcFile;
     $this->echoType = $echoType;
     $info = "";
     $data = GetImageSize($this->srcFile, $info);
     switch ($data[2]) {
         case 1:
             if (!function_exists("imagecreatefromgif")) {
                 echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
                 exit;
             }
             $this->im = ImageCreateFromGIF($this->srcFile);
             break;
         case 2:
             if (!function_exists("imagecreatefromjpeg")) {
                 echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
                 exit;
             }
             $this->im = ImageCreateFromJpeg($this->srcFile);
             break;
         case 3:
             $this->im = ImageCreateFromPNG($this->srcFile);
             break;
     }
     $this->srcW = ImageSX($this->im);
     $this->srcH = ImageSY($this->im);
 }
 /**
  * Agrega una marca de agua a la foto
  * @param string $absolutePath
  */
 private function _addWaterMark($absolutePath)
 {
     $DOC_ROOT = $this->_CI->input->server('DOCUMENT_ROOT') . "/";
     if (FALSE === is_file($absolutePath)) {
         return FALSE;
     }
     switch (TRUE) {
         case stristr($absolutePath, 'jpg'):
             $photoImage = ImageCreateFromJpeg("{$absolutePath}");
             break;
         case stristr($absolutePath, 'gif'):
             $photoImage = ImageCreateFromGIF("{$absolutePath}");
             break;
         case stristr($absolutePath, 'png'):
             $photoImage = ImageCreateFromPNG("{$absolutePath}");
             break;
     }
     ImageAlphaBlending($photoImage, true);
     // Añadimos aquí el fichero de marca de agua.
     $logoImage = ImageCreateFromPNG($DOC_ROOT . "assets/imagenes/marca_agua_telam.png");
     $logoW = ImageSX($logoImage);
     $logoH = ImageSY($logoImage);
     $tamanox = imagesx($photoImage);
     $ubicacionX = ($tamanox - $logoW) / 2;
     $tamanoy = imagesy($photoImage);
     $ubicacionY = ($tamanoy - $logoH) / 2;
     ImageCopy($photoImage, $logoImage, $ubicacionX, $ubicacionY, 0, 0, $logoW, $logoH);
     imagejpeg($photoImage, $absolutePath);
     ImageDestroy($photoImage);
     ImageDestroy($logoImage);
 }
Beispiel #5
0
 function get_hex($location, $extensions = array('PNG', 'png', 'Png', 'JPG', 'jpg', 'Jpg', 'JPEG', 'jpeg', 'Jpeg', 'GIF', 'gif', 'Gif'), $postvar = "myimage", $getvar = "imgclix")
 {
     if (isset($_GET[$getvar])) {
         foreach ($extensions as $var) {
             if (file_exists($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var)) {
                 if (stristr($var, 'png')) {
                     $im = ImageCreateFromPng($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
                 } elseif (stristr($var, 'gif')) {
                     $im = ImageCreateFromGIF($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
                 } elseif (stristr($var, 'jpg') || stristr($var, 'jpeg')) {
                     $im = ImageCreateFromJpeg($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
                 } else {
                     return FALSE;
                 }
                 $rgb = ImageColorAt($im, $_POST[$postvar . '_x'], $_POST[$postvar . '_y']);
                 $rgb = imagecolorsforindex($im, $rgb);
                 $hex = sprintf('#%02X%02X%02X', $rgb['red'], $rgb['green'], $rgb['blue']);
                 break;
             }
         }
     } else {
         return FALSE;
     }
     if (!isset($hex) || $hex == '') {
         return FALSE;
     }
     return $hex;
 }
 /** 
  * @private
  */
 function thumbnail($imgfile)
 {
     //detect image format
     $this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         $this->img["format"] = "JPEG";
         $this->img["src"] = @ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         $this->img["format"] = "PNG";
         $this->img["src"] = @ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         $this->img["format"] = "GIF";
         if (function_exists("imagecreatefromgif")) {
             $this->img["src"] = @ImageCreateFromGIF($imgfile);
         } else {
             return false;
         }
     } else {
         // not a recognized format
         throw new Exception("Trying to generate a thumbnail of an unsupported format!");
         //die();
     }
     // check for errors
     if (!$this->img["src"]) {
         return false;
     }
     // if no errors, continue
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 85;
     return true;
 }
Beispiel #7
0
 public function resize($width, $height)
 {
     $type = exif_imagetype($this->image);
     if ($type == 2) {
         $images_orig = ImageCreateFromJPEG($this->image);
     } elseif ($type == 3) {
         $images_orig = ImageCreateFromPNG($this->image);
     } elseif ($type == 1) {
         $images_orig = ImageCreateFromGIF($this->image);
     } else {
         return false;
     }
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     if ($type == 2) {
         ImageJPEG($images_fin, $this->image);
     } elseif ($type == 3) {
         ImagePNG($images_fin, $this->image);
     } elseif ($type == 1) {
         ImageGIF($images_fin, $this->image);
     }
     ImageDestroy($images_orig);
     ImageDestroy($images_fin);
     return true;
 }
 function SetVar($srcFile, $echoType)
 {
     $this->srcFile = $srcFile;
     $this->echoType = $echoType;
     $info = '';
     $data = GetImageSize($this->srcFile, $info);
     switch ($data[2]) {
         case 1:
             if (!function_exists('imagecreatefromgif')) {
                 exit;
             }
             $this->im = ImageCreateFromGIF($this->srcFile);
             break;
         case 2:
             if (!function_exists('imagecreatefromjpeg')) {
                 exit;
             }
             $this->im = ImageCreateFromJpeg($this->srcFile);
             break;
         case 3:
             $this->im = ImageCreateFromPNG($this->srcFile);
             break;
     }
     $this->srcW = ImageSX($this->im);
     $this->srcH = ImageSY($this->im);
 }
Beispiel #9
0
 /**
  * 把图片生成缩略图1
  * @param string $srcFile	源文件			
  * @param string $dstFile	目标文件
  * @param int $dstW		目标图片宽度		
  * @param int $dstH		目标文件高度
  * @param string $dstFormat	目标文件生成的格式, 有png和jpg两种格式
  * @return 错误返回错误对象
  */
 public static function makeThumb1($srcFile, $dstFile, $dstW, $dstH, $dstFormat = "png")
 {
     //打开图片
     $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;
     }
     if (!$im) {
         throw new TM_Exception(__CLASS__ . ": Create image failed");
     }
     //设定图片大小
     $srcW = ImageSX($im);
     $srcH = ImageSY($im);
     $ni = ImageCreate($dstW, $dstH);
     ImageCopyResized($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
     //生成指定格式的图片
     if ($dstFormat == "png") {
         imagepng($ni, $dstFile);
     } elseif ($dstFormat == "jpg") {
         ImageJpeg($ni, $dstFile);
     } else {
         imagepng($ni, $dstFile);
     }
 }
function thumbnail($PicPathIn, $PicPathOut, $PicFilenameIn, $PicFilenameOut, $neueHoehe, $Quality)
{
    // Bilddaten ermitteln
    $size = getimagesize("{$PicPathIn}" . "{$PicFilenameIn}");
    $breite = $size[0];
    $hoehe = $size[1];
    $neueBreite = intval($breite * $neueHoehe / $hoehe);
    if ($size[2] == 1) {
        // GIF
        $altesBild = ImageCreateFromGIF("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        imageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
    if ($size[2] == 2) {
        // JPG
        $altesBild = ImageCreateFromJPEG("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
    if ($size[2] == 3) {
        // PNG
        $altesBild = ImageCreateFromPNG("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
}
Beispiel #11
0
 private function thumbnail($imgfile)
 {
     //detect image format
     $this->acHWArr = getimagesize($imgfile);
     $this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File <a href='" . $_SERVER[HTTP_REFERER] . "'>Back</a>";
         exit;
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
Beispiel #12
0
 function thumbnail($imgfile, $format = "image/jpeg")
 {
     //detect image format
     $pos = strpos($format, "/");
     $this->img["format"] = strtoupper(substr($format, $pos + 1));
     //$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
     //$this->img["format"]=strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File ";
         $this->is_img = false;
         return;
         //exit();
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
 function thumbnail($imgfile)
 {
     //detect image format
     //$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
     $this->img["format"] = preg_replace('/.*\\.(.*)$/', "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         $this->img["format"] = "JPEG";
         $this->img["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         $this->img["format"] = "PNG";
         $this->img["src"] = ImageCreateFromPNG($imgfile);
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         $this->img["format"] = "GIF";
         $this->img["src"] = ImageCreateFromGIF($imgfile);
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         $this->img["format"] = "WBMP";
         $this->img["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         echo "Not Supported File";
         exit;
     }
     @($this->img["lebar"] = imagesx($this->img["src"]));
     @($this->img["tinggi"] = imagesy($this->img["src"]));
     //default quality jpeg
     $this->img["quality"] = 75;
 }
Beispiel #14
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);
}
Beispiel #15
0
 function makeIcon($type = 1)
 {
     //$img_des = ImageCreateTrueColor ( $this->size, $this->size );
     $img_des = ImageCreateTrueColor($this->size, $this->size);
     $background = imagecolorallocate($img_des, 255, 255, 255);
     imagefill($img_des, 0, 0, $background);
     switch ($this->t) {
         case 'gif':
             $img_src = ImageCreateFromGIF($this->path);
             break;
         case 'jpg':
             $img_src = ImageCreateFromJPEG($this->path);
             break;
         case 'png':
             $img_src = ImageCreateFromPNG($this->path);
             break;
     }
     if ($type == 1) {
         imagecopyresampled($img_des, $img_src, 0, 0, ($this->nw - $this->size) / 2, 0, $this->nw, $this->nh, $this->w, $this->h);
     } else {
         imagecopyresampled($img_des, $img_src, 0, 0, 0, ($this->nh - $this->size) / 2, $this->nw, $this->nh, $this->w, $this->h);
     }
     /*
     imageline( $img_des , 0 , 0 , 0 , ($this->size-1) , imagecolorallocate( $img_des , 220 , 220 , 220 )  );
     imageline( $img_des , 0 , ($this->size-1) , ($this->size-1) , ($this->size-1) , imagecolorallocate( $img_des , 220 , 220 , 220 )  );
     imageline( $img_des , ($this->size-1) , ($this->size-1) , ($this->size-1) , 0 , imagecolorallocate( $img_des , 220 , 220 , 220 )  );
     imageline( $img_des , ($this->size-1) , 0 , 0 , 0 , imagecolorallocate( $img_des , 220 , 220 , 220 )  );
     */
     //echo $this->dest ;
     switch ($this->t) {
         case 'gif':
             if (empty($this->dest)) {
                 header("Content-type: image/gif");
                 return ImageGIF($img_des);
             } else {
                 return ImageGIF($img_des, $this->dest);
             }
             break;
         case 'jpg':
             if (empty($this->dest)) {
                 header("Content-type: image/jpeg");
                 return ImageJPEG($img_des);
             } else {
                 return ImageJPEG($img_des, $this->dest);
             }
             break;
         case 'png':
             if (empty($this->dest)) {
                 header("Content-type: image/png");
                 return ImagePNG($img_des);
             } else {
                 return ImagePNG($img_des, $this->dest);
             }
             break;
     }
 }
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);
    }
}
Beispiel #17
0
 /**
  * This function will be available automatically after the module is imported with the module control.
  * Using the custom prefix this function will be callable from PHP and JSON-RPC through:
  *
  * UWZ_RequestInfo($id);
  *
  */
 public function RequestInfo()
 {
     $imagePath = IPS_GetKernelDir() . $this->imagePath;
     $area = $this->ReadPropertyString("area");
     $homeX = $this->ReadPropertyInteger("homeX");
     $homeY = $this->ReadPropertyInteger("homeY");
     $homeRadius = $this->ReadPropertyInteger("homeRadius");
     //Calculate time
     $minute = floor(date("i") / 15) * 15;
     $dateline = mktime(date("H"), $minute, 0, date("m"), date("d"), date("y"));
     //Download picture
     $opts = array('http' => array('method' => "GET", 'max_redirects' => 1));
     $context = stream_context_create($opts);
     $remoteImage = "http://www.wetteronline.de/daten/radar/{$area}/" . gmdate("Y", $dateline) . "/" . gmdate("m", $dateline) . "/" . gmdate("d", $dateline) . "/" . gmdate("Hi", $dateline) . ".gif";
     $data = @file_get_contents($remoteImage, false, $context);
     if ($data === false) {
         //No new picture. Download old one.
         $dateline -= 15 * 60;
         $remoteImage = "http://www.wetteronline.de/daten/radar/{$area}/" . gmdate("Y", $dateline) . "/" . gmdate("m", $dateline) . "/" . gmdate("d", $dateline) . "/" . gmdate("Hi", $dateline) . ".gif";
         $data = @file_get_contents($remoteImage, false, $context);
         if ($data === false) {
             return;
         }
     }
     if (strpos($http_response_header[0], "200") === false) {
         return;
     }
     file_put_contents($imagePath, $data);
     //Radarbild auswerten
     $im = ImageCreateFromGIF($imagePath);
     //Stärken
     $regen[6] = imagecolorresolve($im, 250, 2, 250);
     $regen[5] = imagecolorresolve($im, 156, 50, 156);
     $regen[4] = imagecolorresolve($im, 28, 126, 220);
     $regen[3] = imagecolorresolve($im, 44, 170, 252);
     $regen[2] = imagecolorresolve($im, 84, 210, 252);
     $regen[1] = imagecolorresolve($im, 172, 254, 252);
     //Pixel durchgehen
     $regenmenge = 0;
     for ($x = $homeX - $homeRadius; $x <= $homeX + $homeRadius; $x++) {
         for ($y = $homeY - $homeRadius; $y <= $homeY + $homeRadius; $y++) {
             $found = array_search(imagecolorat($im, $x, $y), $regen);
             if (!($found === FALSE)) {
                 $regenmenge += $found;
             }
         }
     }
     // Bereich zeichnen
     $schwarz = ImageColorAllocate($im, 0, 0, 0);
     $rot = ImageColorAllocate($im, 255, 0, 0);
     imagerectangle($im, $homeX - $homeRadius, $homeY - $homeRadius, $homeX + $homeRadius, $homeY + $homeRadius, $rot);
     imagesetpixel($im, $homeX, $homeY, $rot);
     imagegif($im, $localImage);
     imagedestroy($im);
     SetValue($this->GetIDForIdent("RainValue"), $regenmenge);
 }
 function Resize($maxwidth = 10000, $maxheight, $imagename, $filetype, $how = 'keep_aspect')
 {
     $target_temp_file = tempnam("jinn/temp", "gdlib_");
     unlink($target_temp_file);
     $target_temp_file .= '.' . $filetype;
     if (!$maxheight) {
         $maxheight = 10000;
     }
     if (!$maxwidth) {
         $maxwidth = 10000;
     }
     $qual = 100;
     $filename = $imagename;
     $ext = $filetype;
     list($curwidth, $curheight) = getimagesize($filename);
     $factor = min($maxwidth / $curwidth, $maxheight / $curheight);
     $sx = 0;
     $sy = 0;
     $sw = $curwidth;
     $sh = $curheight;
     $dx = 0;
     $dy = 0;
     $dw = $curwidth * $factor;
     $dh = $curheight * $factor;
     if ($ext == "JPEG") {
         $src = ImageCreateFromJPEG($filename);
     }
     if ($ext == "GIF") {
         $src = ImageCreateFromGIF($filename);
     }
     if ($ext == "PNG") {
         $src = ImageCreateFromPNG($filename);
     }
     if (function_exists('ImageCreateTrueColor')) {
         $dst = ImageCreateTrueColor($dw, $dh);
     } else {
         $dst = ImageCreate($dw, $dh);
     }
     if (function_exists('ImageCopyResampled')) {
         imageCopyResampled($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
     } else {
         imageCopyResized($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
     }
     if ($ext == "JPEG") {
         ImageJPEG($dst, $target_temp_file, $qual);
     }
     if ($ext == "PNG") {
         ImagePNG($dst, $target_temp_file, $qual);
     }
     if ($ext == "GIF") {
         ImagePNG($dst, $target_temp_file, $qual);
     }
     ImageDestroy($dst);
     return $target_temp_file;
 }
Beispiel #19
0
 function __construct($path)
 {
     $this->image = null;
     $oldErrorReporting = error_reporting();
     error_reporting(0);
     if ($this->imageLibSupported()) {
         switch (br()->fs()->fileExt($path)) {
             case 'png':
                 if ($this->image = @ImageCreateFromPNG($path)) {
                     $this->format = 'png';
                 }
                 break;
             case 'jpg':
             case 'jpeg':
                 if ($this->image = @ImageCreateFromJPEG($path)) {
                     $this->format = 'jpg';
                 }
                 break;
             case 'gif':
                 if ($this->image = @ImageCreateFromGIF($path)) {
                     $this->format = 'gif';
                 }
                 break;
         }
         if ($this->image) {
         } else {
             $this->image = @ImageCreateFromPNG($path);
             if ($this->image) {
                 $this->format = 'png';
             } else {
                 $this->image = @ImageCreateFromJPEG($path);
                 if ($this->image) {
                     $this->format = 'jpg';
                 } else {
                     $this->image = @ImageCreateFromGIF($path);
                     if ($this->image) {
                         $this->format = 'gif';
                     }
                 }
             }
         }
     } else {
         throw new Exception('It seems GD is not installed.');
     }
     if ($this->image) {
         $this->width = imagesx($this->image);
         $this->height = imagesy($this->image);
     } else {
         throw new Exception($path . ' is not valid image file.');
     }
     $this->filePath = $path;
     error_reporting($oldErrorReporting);
 }
Beispiel #20
0
function SetImgSize($img, $W = 0, $H = 0, $Key = 1)
{
    //echo("$img , $W ,$H , $Key");
    $rasshr = substr(strrchr($img, '.'), 1);
    //организация работы с форматами GIF JPEG PNG
    switch ($rasshr) {
        default:
        case "gif":
            $srcImage = @ImageCreateFromGIF($img);
            break;
        case "jpg":
            $srcImage = @ImageCreateFromJPEG($img);
            break;
        case "png":
            $srcImage = @ImageCreateFromPNG($img);
            break;
    }
    //определяем изначальную длинну и высоту
    $srcWidth = @ImageSX($srcImage);
    $srcHeight = @ImageSY($srcImage);
    //ресайз по заданной ширине
    if ($W != 0 && $H == 0 && $W < $srcWidth) {
        $res = ResNoDel($srcWidth, $srcHeight, $W, 0);
    }
    //ресайз по заданной высоте
    if ($W == 0 && $H != 0 && $H < $srcHeight) {
        $res = ResNoDel($srcWidth, $srcHeight, 0, $H);
    }
    //ресайз с обрезкой
    if ($W != 0 && $H != 0 && ($H < $srcHeight || $W < $srcWidth)) {
        $res = ResDel($srcWidth, $srcHeight, min($W, $srcWidth), min($H, $srcHeight), $Key);
    }
    //создаем картинку
    if ($res) {
        $endImage = @ImageCreateTrueColor($res[2], $res[3]);
        ImageCopyResampled($endImage, $srcImage, 0, 0, $res[0], $res[1], $res[2], $res[3], $res[4], $res[5]);
        unlink($img);
        switch ($rasshr) {
            case "gif":
                ImageGif($endImage, $img);
                break;
            default:
            case "jpg":
                imagejpeg($endImage, $img);
                break;
            case "png":
                imagepng($endImage, $img);
                break;
        }
        ImageDestroy($endImage);
    }
}
Beispiel #21
0
 protected function _createResource($ext, $path)
 {
     if ($ext == 'gif') {
         $res = @ImageCreateFromGIF($path);
     } elseif ($ext == 'jpg' || $ext == 'jpeg') {
         $res = @ImageCreateFromJPEG($path);
     } elseif ($ext == 'png') {
         $res = @ImageCreateFromPNG($path);
     } else {
         $res = false;
     }
     return $res;
 }
Beispiel #22
0
function dzthumb($srcfile,$dstfile,$dstw,$dsth=0,$mode=0,$data=''){
	//mode=0为固定宽高,画质裁切不变形
	//mode=1为固定宽高,画质会拉伸变形
	//mode=2为可变宽高,宽高不超过指定大小
	//mode=3为固定宽度,高度随比例变化
	$data=$data==''?@GetImageSize($srcfile):$data;
	if(!$data) return false;
	if($data[2]==2) $im=@ImageCreateFromJPEG($srcfile);
	elseif ($data[2]==1) $im=@ImageCreateFromGIF($srcfile);
	elseif($data[2]==3) $im=@ImageCreateFromPNG($srcfile);
	list($img_w, $img_h) = $data;
	if($dsth==0) $mode=3;
	if($mode==0){
		$imgratio = $img_w / $img_h;
		$thumbratio = $dstw / $dsth;
		if($imgratio >= 1 && $imgratio >= $thumbratio || $imgratio < 1 && $imgratio > $thumbratio) {
			$cuty = $img_h;
			$cutx = $cuty * $thumbratio;
		} elseif($imgratio >= 1 && $imgratio <= $thumbratio || $imgratio < 1 && $imgratio < $thumbratio) {
			$cutx = $img_w;
			$cuty = $cutx / $thumbratio;
		}
		$cx = $cutx;
		$cy = $cuty;
	}elseif($mode==1){
		$cx = $img_w;
		$cy = $img_h;
	}elseif ($mode==2){
		$cx = $img_w;
		$cy = $img_h;
		$bit=$img_w/$img_h;
		if($dstw/$dsth>$bit){
			$dstw=($img_w/$img_h)*$dsth;
		}else{
			$dsth=($img_h/$img_w)*$dstw;
		}
	}
	elseif($mode==3){
		$cx = $img_w;
		$cy = $img_h;
		$dsth=$dstw * $img_h / $img_w;
	}
	$ni=imagecreatetruecolor($dstw,$dsth);
	ImageCopyResampled($ni,$im,0,0,0,0,$dstw,$dsth, $cx, $cy);
	clearstatcache();
	if($data[2]==2) ImageJPEG($ni,$dstfile,60);
	elseif($data[2]==1) ImageGif($ni,$dstfile);
	elseif($data[2]==3) ImagePNG($ni,$dstfile);
	return true;
}
	function img($sourceFile){
		if(file_exists($sourceFile)){
			$this->ext($sourceFile);
			if($this->ext=="jpg" || $this->ext=="jpeg"){
				$this->image = ImageCreateFromJPEG($sourceFile);
			}elseif($this->ext=="gif"){
				$this->image = ImageCreateFromGIF($sourceFile);
			}elseif($this->ext=="png"){
				$this->image = ImageCreateFromPNG($sourceFile);
			}else $this->errorHandler("Dont't support this file types.");
		} else {
			$this->errorHandler("Can't find the file.");
		}
		return;
	}
 function thumbnail($imgfile)
 {
     // ----- imagepfad speichern
     $this->imgfile = $imgfile;
     // ----- gif support ?
     $this->gifsupport = false;
     if (function_exists('imageGIF')) {
         $this->gifsupport = true;
     }
     // ----- detect image format
     $this->img['format'] = ereg_replace('.*\\.(.*)$', '\\1', $imgfile);
     $this->img['format'] = strtoupper($this->img['format']);
     if (!eregi('cache/', $imgfile)) {
         if ($this->img['format'] == 'JPG' || $this->img['format'] == 'JPEG') {
             // --- JPEG
             $this->img['format'] = 'JPEG';
             $this->img['src'] = @ImageCreateFromJPEG($imgfile);
         } elseif ($this->img['format'] == 'PNG') {
             // --- PNG
             $this->img['src'] = @ImageCreateFromPNG($imgfile);
         } elseif ($this->img['format'] == 'GIF') {
             // --- GIF
             if ($this->gifsupport) {
                 $this->img['src'] = @ImageCreateFromGIF($imgfile);
             }
         } elseif ($this->img['format'] == 'WBMP') {
             // --- WBMP
             $this->img['src'] = @ImageCreateFromWBMP($imgfile);
         }
         // ggf error image senden
         if (!$this->img['src']) {
             global $REX;
             $file = $REX['INCLUDE_PATH'] . '/addons/image_resize/media/warning.jpg';
             header('Content-Type: image/JPG');
             // error image nicht cachen
             header('Cache-Control: false');
             readfile($file);
             exit;
         }
         $this->img['width'] = imagesx($this->img['src']);
         $this->img['height'] = imagesy($this->img['src']);
         $this->img['width_offset_thumb'] = 0;
         $this->img['height_offset_thumb'] = 0;
         // --- default quality jpeg
         $this->img['quality'] = 75;
         $this->filters = array();
     }
 }
Beispiel #25
0
 /**
  * Create a simple sume captcha
  */
 public function sumeCaptcha()
 {
     $val1 = rand(1, 9);
     $val2 = rand(1, 9);
     $result = $val1 + $vale;
     $txtCode = $val1 . ' + ' . $val2;
     $img = ImageCreateFromGIF('img/captcha/bg.gif');
     $bg = ImageColorAllocate($img, 240, 240, 240);
     $color = ImageColorAllocate($img, 0, 0, 0);
     $font = 'img/others/arial.ttf';
     // Create the Captcha image
     ImageTTFText($img, 20, 0, 13, 30, $color, $font, $txtCode);
     ImageJPEG($img, 'img/captcha/box.jpg', 75);
     ImageDestroy($img);
     return $result;
 }
Beispiel #26
0
 /**
  * view image with desired width and height
  */
 function view()
 {
     if ($this->file == '') {
         return;
     }
     list($srcWidth, $srcHeight, $this->type) = @getimagesize($this->file);
     if ($srcWidth > $this->width || $srcHeight > $this->height) {
         $srcImg = '';
         switch ($this->type) {
             case 1:
                 if (function_exists('ImageCreateFromGIF')) {
                     $srcImg = @ImageCreateFromGIF($this->file);
                 }
                 break;
             case 2:
                 if (function_exists('ImageCreateFromJPEG')) {
                     $srcImg = @ImageCreateFromJPEG($this->file);
                 }
                 break;
             case 3:
                 if (function_exists('ImageCreateFromPNG')) {
                     $srcImg = @ImageCreateFromPNG($this->file);
                 }
                 break;
         }
         if ($srcImg) {
             if ($this->type != 1 && function_exists('ImageCreateTrueColor')) {
                 $dstImg = @ImageCreateTrueColor($this->width, $this->height);
             } else {
                 $dstImg = @ImageCreate($this->width, $this->height);
             }
             if (function_exists('ImageCopyResampled')) {
                 @ImageCopyResampled($dstImg, $srcImg, 0, 0, 0, 0, $this->width, $this->height, $srcWidth, $srcHeight);
             } else {
                 @ImageCopyResized($dstImg, $srcImg, 0, 0, 0, 0, $this->width, $this->height, $srcWidth, $srcHeight);
             }
             $this->send($dstImg);
             ImageDestroy($srcImg);
             ImageDestroy($dstImg);
         } else {
             $this->send();
         }
     } else {
         $this->send();
     }
 }
Beispiel #27
0
 /**
  * constructor for resizing image
  * @internal
  *  @$this->img["lebar"]     source image X
  *  @$this->img['tinggi']    source image Y
  *
  * @param string $imgfile
  * @return void
  */
 function thumbnail($imgfile)
 {
     if (!file_exists($imgfile)) {
         return false;
     }
     ini_set('display_errors', '0');
     $this->sSourcePath2file = $imgfile;
     $this->img["src"] = $imgfile;
     $aImageSize = getimagesize($imgfile);
     $this->img['format'] = $aImageSize[2];
     if (extension_loaded('gd') || extension_loaded('gd2')) {
         set_time_limit('6000');
         ini_set('memory_limit', '100M');
         ini_set('post_max_size', '7M');
         switch ($this->img['format']) {
             case IMAGETYPE_GIF:
                 $this->img['src'] = ImageCreateFromGIF($imgfile);
                 break;
             case IMAGETYPE_JPEG:
                 $this->img['src'] = ImageCreateFromJPEG($imgfile);
                 break;
             case IMAGETYPE_PNG:
                 $this->img['src'] = ImageCreateFromPNG($imgfile);
                 break;
             case IMAGETYPE_WBMP:
                 $this->img['src'] = ImageCreateFromWBMP($imgfile);
                 break;
             default:
                 echo 'Not Supported File';
                 exit;
         }
     }
     /**
      *     @$this->img["lebar"] image X
      *    @$this->img['tinggi'] image Y
      */
     $this->img['lebar'] = $this->img["lebar_thumb"] = $this->img["width"] = $aImageSize[0];
     //imagesx($this->img["src"]);
     $this->img['tinggi'] = $this->img["tinggi_thumb"] = $this->img["height"] = $aImageSize[1];
     // imagesy($this->img["src"]);
     //default quality jpeg
     $this->img["quality"] = 85;
     $this->img['src_x'] = 0;
     $this->img['src_y'] = 0;
 }
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);
    }
}
 function thumbnail($imgfile)
 {
     // ----- imagepfad speichern
     $this->imgfile = $imgfile;
     // ----- gif support ?
     $this->gifsupport = false;
     if (function_exists('imageGIF')) {
         $this->gifsupport = true;
     }
     // ----- detect image format
     $this->img["format"] = ereg_replace(".*\\.(.*)\$", "\\1", $imgfile);
     $this->img["format"] = strtoupper($this->img["format"]);
     if (!eregi('cache/', $imgfile)) {
         if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
             // --- JPEG
             $this->img["format"] = "JPEG";
             $this->img["src"] = ImageCreateFromJPEG($imgfile);
         } elseif ($this->img["format"] == "PNG") {
             // --- PNG
             $this->img["format"] = "PNG";
             $this->img["src"] = ImageCreateFromPNG($imgfile);
         } elseif ($this->img["format"] == "GIF") {
             // --- GIF
             $this->img["format"] = "GIF";
             if ($this->gifsupport) {
                 $this->img["src"] = ImageCreateFromGIF($imgfile);
             }
         } elseif ($this->img["format"] == "WBMP") {
             // --- WBMP
             $this->img["format"] = "WBMP";
             $this->img["src"] = ImageCreateFromWBMP($imgfile);
         } else {
             // --- DEFAULT
             echo "Not Supported File";
             exit;
         }
         @($this->img["width"] = imagesx($this->img["src"]));
         @($this->img["height"] = imagesy($this->img["src"]));
         // --- default quality jpeg
         $this->img["quality"] = 75;
     }
 }
 function rex_thumbnail($imgfile)
 {
     global $REX;
     // ----- imagepfad speichern
     $this->img = array();
     $this->imgfile = $imgfile;
     // ----- gif support ?
     $this->gifsupport = function_exists('imageGIF');
     // ----- detect image format
     $this->img['format'] = strtoupper(OOMedia::_getExtension($imgfile));
     $this->img['src'] = false;
     if (strpos($imgfile, 'cache/') === false) {
         if ($this->img['format'] == 'JPG' || $this->img['format'] == 'JPEG') {
             // --- JPEG
             $this->img['format'] = 'JPEG';
             $this->img['src'] = @ImageCreateFromJPEG($imgfile);
         } elseif ($this->img['format'] == 'PNG') {
             // --- PNG
             $this->img['src'] = @ImageCreateFromPNG($imgfile);
         } elseif ($this->img['format'] == 'GIF') {
             // --- GIF
             if ($this->gifsupport) {
                 $this->img['src'] = @ImageCreateFromGIF($imgfile);
             }
         } elseif ($this->img['format'] == 'WBMP') {
             // --- WBMP
             $this->img['src'] = @ImageCreateFromWBMP($imgfile);
         }
         // ggf error image senden
         if (!$this->img['src']) {
             $this->sendError();
             exit;
         }
         $this->img['width'] = imagesx($this->img['src']);
         $this->img['height'] = imagesy($this->img['src']);
         $this->img['width_offset_thumb'] = 0;
         $this->img['height_offset_thumb'] = 0;
         // --- default quality jpeg
         $this->img['quality'] = $REX['ADDON']['image_resize']['jpg_quality'];
         $this->filters = array();
     }
 }