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); } }
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; } }
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; }
public function src($src, $ext = null) { if (!is_file($src)) { throw new FileNotFoundException($src); } $this->src = $src; if (!$ext) { $info = new \SplFileInfo($src); $this->ext = strtoupper($info->getExtension()); } else { $this->ext = strtoupper($ext); } if (is_file($src) && ($this->ext == "JPG" or $this->ext == "JPEG")) { $this->image = ImageCreateFromJPEG($src); } else { if (is_file($src) && $this->ext == "PNG") { $this->image = ImageCreateFromPNG($src); } else { throw new FileNotFoundException($src); } } $this->input_width = imagesx($this->image); $this->input_height = imagesy($this->image); return $this; }
/** * getColorForCaptcha Test * * @param string $hexColorString * @param string $expectedResult * @dataProvider getColorForCaptchaReturnIntDataProvider * @return void * @test */ public function getColorForCaptchaReturnInt($hexColorString, $expectedResult) { $imageResource = ImageCreateFromPNG(GeneralUtility::getFileAbsFileName('typo3conf/ext/powermail/Resources/Private/Image/captcha_bg.png')); $this->generalValidatorMock->_set('configuration', array('captcha.' => array('default.' => array('textColor' => $hexColorString)))); $result = $this->generalValidatorMock->_call('getColorForCaptcha', $imageResource); $this->assertSame($expectedResult, $result); }
function TransFormPicture($inputfname, $outputfname, $transform, $backgroundcolor) { $img_in = ImageCreateFromPNG($inputfname); $sizex = imagesx($img_in); $sizey = imagesy($img_in); $img_out = @ImageCreateTrueColor($sizex, $sizey) or die("Cannot create image handle."); imagefill($img_out, 0, 0, hexdec($backgroundcolor)); ImageCopy($img_out, $img_in, 0, 0, 0, 0, $sizex, $sizey); for ($x = 0; $x < $sizex; $x++) { for ($y = 0; $y < $sizey; $y++) { $color = imagecolorat($img_in, $x, $y); $allcolors[dechex($color)]++; $blue = 0xff & $color; $green = (0xff00 & $color) >> 8; $red = (0xff0000 & $color) >> 16; foreach ($transform as $line) { list($from, $to) = split("\t", $line); list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x'); if ($blue == $fb and $red == $fr and $green == $fg) { imagesetpixel($img_out, $x, $y, hexdec($to)); } } } } ImagePNG($img_out, "out/{$outputfname}"); imagedestroy($img_in); imagedestroy($img_out); print_r($allcolors); }
function marcadeagua($img_original, $img_marcadeagua, $img_nueva, $calidad) { // obtener datos de la fotografia $info_original = getimagesize($img_original); $anchura_original = $info_original[0]; $altura_original = $info_original[1]; // obtener datos de la "marca de agua" $info_marcadeagua = getimagesize($img_marcadeagua); $anchura_marcadeagua = $info_marcadeagua[0]; $altura_marcadeagua = $info_marcadeagua[1]; // calcular la posición donde debe copiarse la "marca de agua" en la fotografia /* // Posicion: Centrado $horizmargen = ($anchura_original - $anchura_marcadeagua)/2; $vertmargen = ($altura_original - $altura_marcadeagua)/2; */ // Posicion: abajo a la izquierda $horizmargen = 10; $vertmargen = $altura_original - $altura_marcadeagua - 10; // crear imagen desde el original $original = ImageCreateFromJPEG($img_original); ImageAlphaBlending($original, true); // crear nueva imagen desde la marca de agua $marcadeagua = ImageCreateFromPNG($img_marcadeagua); // copiar la "marca de agua" en la fotografia ImageCopy($original, $marcadeagua, $horizmargen, $vertmargen, 0, 0, $anchura_marcadeagua, $altura_marcadeagua); // guardar la nueva imagen ImageJPEG($original, $img_nueva, $calidad); // cerrar las imágenes ImageDestroy($original); ImageDestroy($marcadeagua); }
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; }
/** * 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); }
/** * @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; }
function TransformPicture($inputfname, $outputfname, $transform) { $img = ImageCreateFromPNG($inputfname); Imagesavealpha($img, true); $sizex = imagesx($img); $sizey = imagesy($img); for ($x = 0; $x < $sizex; $x++) { for ($y = 0; $y < $sizey; $y++) { $color = imagecolorat($img, $x, $y); $allcolors[dechex($color)]++; $blue = 0xff & $color; $green = (0xff00 & $color) >> 8; $red = (0xff0000 & $color) >> 16; foreach ($transform as $line) { list($from, $to) = split("\t", $line); list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x'); if ($blue == $fb and $red == $fr and $green == $fg) { imagesetpixel($img, $x, $y, hexdec($to)); } } } } ImagePNG($img, "{$outputfname}"); imagedestroy($img); print_r($allcolors); }
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); }
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); }
private function openImage($file) { // *** Get extension $extension = strtolower(strrchr($file, '.')); //$extension = DataHandler::returnExtensionOfFile($file); switch ($extension) { case '.jpg': case '.jpeg': $img = @imagecreatefromjpeg($file); break; case '.gif': $img = @imagecreatefromgif($file); break; case '.png': $img = @ImageCreateFromPNG($file); // //abaixo do php.net // imagealphablending($img, false); // imagesavealpha($img, true); break; default: $img = false; break; } return $img; }
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; }
/** * 把图片生成缩略图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); } }
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; } }
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 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 watermark($pngImage, $left = 0, $top = 0) { ImageAlphaBlending($this->image, true); $layer = ImageCreateFromPNG($pngImage); $logoW = ImageSX($layer); $logoH = ImageSY($layer); ImageCopy($this->image, $layer, $left, $top, 0, 0, $logoW, $logoH); }
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); } }
function get_wm_img_size() { $info = @getimagesize(DIR_WATERMARK . $this->wm_image); if ($info[2] != 3) { return; } $this->wm_original["src"] = ImageCreateFromPNG(DIR_WATERMARK . $this->wm_image); $this->wm_original["width"] = $info[0]; $this->wm_original["height"] = $info[1]; }
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; }
function imageblend($x, $y, $filename, $image) { $image2 = ImageCreateFromPNG($filename); imageAlphaBlending($image2, true); imageSaveAlpha($image2, true); $w = imagesx($image2); $h = imagesy($image2); imagecopy($image, $image2, $x, $y, 0, 0, $w, $h); imageAlphaBlending($image, true); imageSaveAlpha($image, true); }
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); }
function main($inFile) { $img = ImageCreateFromPNG($inFile); $width = ImageSX($img); $height = ImageSY($img); if ($width != 640 || $height != 960) { $resizedImg = ImageCreateTrueColor(640, 960); ImageCopyResampled($resizedImg, $img, 0, 0, 0, 0, 640, 960, $width, $height); $img = $resizedImg; } $this->extractAppInfo($img); }
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); } }
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; }
/** * Image_Graph_ImageFill [Constructor] * @param string $filename The filename and path of the image to use for filling */ function &Image_Graph_Fill_Image($fileName) { parent::__construct(); if (file_exists($fileName)) { if (strtolower(substr($fileName, -4)) == ".png") { $this->_image = ImageCreateFromPNG($this->_fileName = $fileName); } else { $this->_image = ImageCreateFromJPEG($this->_fileName = $fileName); } } else { $this->_image = false; } }