function kicsinyites($forras, $kimenet, $max) { if (!isset($max)) { $max = 120; } # maximum size of 1 side of the picture. $src_img = ImagecreateFromJpeg($forras); $oh = imagesy($src_img); # original height $ow = imagesx($src_img); # original width $new_h = $oh; $new_w = $ow; if ($oh > $max || $ow > $max) { $r = $oh / $ow; $new_h = $oh > $ow ? $max : $max * $r; $new_w = $new_h / $r; } // note TrueColor does 256 and not.. 8 $dst_img = ImageCreateTrueColor($new_w, $new_h); /* imageantialias($dst_img, true); */ /* ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img)); */ ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img)); ImageJpeg($dst_img, "{$kimenet}"); }
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); }
public function __construct($cSym) { switch (strlen($cSym)) { case 3: $this->base = $cSym; $this->key = base2view($cSym); $this->bsw = key2bsw($this->key); break; case 5: $this->base = substr($cSym, 0, 3); $this->key = $cSym; $this->bsw = key2bsw($this->key); break; case 9: $this->base = substr($cSym, 0, 3); $this->key = bsw2key($cSym); $this->bsw = $cSym; break; } $this->png = key2png($this->key); $img = imagecreatefromstring($this->png); $this->width = ImageSX($img); $this->height = ImageSY($img); $this->centerX = ImageSX($img) / 2; $this->centerY = ImageSY($img) / 2; imagedestroy($img); }
/** * Loads image source and its properties to the instanciated object * * @param string $filename * @return ImageResize * @throws \Exception */ public function __construct($filename) { $image_info = @getimagesize($filename); if (!$image_info) { throw new \Exception('Could not read file'); } list($this->original_w, $this->original_h, $this->source_type) = $image_info; switch ($this->source_type) { case IMAGETYPE_GIF: $this->source_image = imagecreatefromgif($filename); break; case IMAGETYPE_JPEG: $this->source_image = $this->imageCreateJpegfromExif($filename); // set new width and height for image, maybe it has changed $this->original_w = ImageSX($this->source_image); $this->original_h = ImageSY($this->source_image); break; case IMAGETYPE_PNG: $this->source_image = imagecreatefrompng($filename); break; default: throw new \Exception('Unsupported image type'); break; } return $this->resize($this->getSourceWidth(), $this->getSourceHeight()); }
function getimagesize_remote($image_url) { if (($handle = @fopen($image_url, "rb")) != true) { return; } $contents = ""; $count = 0; if ($handle) { do { $count += 1; $data = fread($handle, 8192); if (strlen($data) == 0) { break; } $contents .= $data; } while (true); } else { return false; } fclose($handle); $im = ImageCreateFromString($contents); if (!$im) { return false; } $gis[0] = ImageSX($im); $gis[1] = ImageSY($im); // array member 3 is used below to keep with current getimagesize standards $gis[3] = "width={$gis[0]} height={$gis[1]}"; ImageDestroy($im); return $gis; }
/** * 把图片生成缩略图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 resize_image_gd($src, $dest, $quality, $width, $height, $image_info) { global $convert_options; $types = array(1 => "gif", 2 => "jpeg", 3 => "png"); if ($convert_options['convert_gd2']) { $thumb = imagecreatetruecolor($width, $height); } else { $thumb = imagecreate($width, $height); } $image_create_handle = "imagecreatefrom" . $types[$image_info[2]]; if ($image = $image_create_handle($src)) { if ($convert_options['convert_gd2']) { imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image)); } else { imagecopyresized($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image)); } if ($image_info[2] == 3) { $quality = 9; } $image_handle = "image" . $types[$image_info[2]]; $image_handle($thumb, $dest, $quality); imagedestroy($image); imagedestroy($thumb); } return file_exists($dest) ? 1 : 0; }
/** * Saves the specified file to the target directory. File data and properties * are taken from an entry in the provided files array * * @param array $filesArray * @param string $fileKey * @param string $destinationDir * @param string $destinationFile */ public static function saveFile($filesArray, $fileKey, $destinationDir, $destinationFile) { if ($filesArray[$fileKey]["name"]) { if (!file_exists($destinationDir)) { mkdir($destinationDir); } $extension = self::getExtensionForMimeType($filesArray, $fileKey); $finalFile = $destinationDir . "/" . $destinationFile . "." . $extension; //$file = $upload_path;// . $new_cnt . "." . $extension; $result = move_uploaded_file($filesArray[$fileKey]["tmp_name"], $finalFile); // TODO update this for GIF, PNG, etc. if (self::isResizableImageType($extension)) { $ds = new dropShadow(); // resize to 800 px wide IF this is a horizontal image (width > height) $ds->loadImage($finalFile); if (ImageSX($ds->_imgOrig) > ImageSY($ds->_imgOrig)) { $ds->resizeToSize(800, 0); } else { if (ImageSX($ds->_imgOrig) > 800) { $ds->resizeToSize(800, 0); } } $ds->saveFinal($finalFile); } } }
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); }
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); }
/** * Convert a GD image into a BMP string representation * @param resource $gdimage is a GD image * @return type */ public static function convert($gdimage = null) { self::loadImg($gdimage); if (!is_resource(self::$img)) { return ''; } $imageX = ImageSX(self::$img); $imageY = ImageSY(self::$img); $bmp = ''; for ($y = $imageY - 1; $y >= 0; $y--) { $thisline = ''; for ($x = 0; $x < $imageX; $x++) { $argb = self::getPixelColor(self::$img, $x, $y); $thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']); } while (strlen($thisline) % 4) { $thisline .= ""; } $bmp .= $thisline; } $bmpSize = strlen($bmp) + 14 + 40; // bitMapHeader [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp $bitMapHeader = 'BM'; // WORD bfType; $bitMapHeader .= self::littleEndian2String($bmpSize, 4); // DWORD bfSize; $bitMapHeader .= self::littleEndian2String(0, 2); // WORD bfReserved1; $bitMapHeader .= self::littleEndian2String(0, 2); // WORD bfReserved2; $bitMapHeader .= self::littleEndian2String(54, 4); // DWORD bfOffBits; // bitMapInfoHeader - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp $bitMapInfoHeader = self::littleEndian2String(40, 4); // DWORD biSize; $bitMapInfoHeader .= self::littleEndian2String($imageX, 4); // LONG biWidth; $bitMapInfoHeader .= self::littleEndian2String($imageY, 4); // LONG biHeight; $bitMapInfoHeader .= self::littleEndian2String(1, 2); // WORD biPlanes; $bitMapInfoHeader .= self::littleEndian2String(24, 2); // WORD biBitCount; $bitMapInfoHeader .= self::littleEndian2String(0, 4); // DWORD biCompression; $bitMapInfoHeader .= self::littleEndian2String(0, 4); // DWORD biSizeImage; $bitMapInfoHeader .= self::littleEndian2String(2835, 4); // LONG biXPelsPerMeter; $bitMapInfoHeader .= self::littleEndian2String(2835, 4); // LONG biYPelsPerMeter; $bitMapInfoHeader .= self::littleEndian2String(0, 4); // DWORD biClrUsed; $bitMapInfoHeader .= self::littleEndian2String(0, 4); // DWORD biClrImportant; return $bitMapHeader . $bitMapInfoHeader . $bmp; }
function drawBorder(&$img, &$color, $thickness = 1) { $x1 = 0; $y1 = 0; $x2 = ImageSX($img) - 1; $y2 = ImageSY($img) - 1; for ($i = 0; $i < $thickness; $i++) { ImageRectangle($img, $x1++, $y1++, $x2--, $y2--, $color_black); } }
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 ImagePSCenter($image, $text, $font, $size, $space = 0, $tightness = 0, $angle = 0) { // find the size of the image $xi = ImageSX($image); $yi = ImageSY($image); // find the size of the text list($xl, $yl, $xr, $yr) = ImagePSBBox($text, $font, $size, $space, $tightness, $angle); // compute centering $x = intval(($xi - $xr) / 2); $y = intval(($yi + $yr) / 2); return array($x, $y); }
function GD2BMPstring(&$gd_image) { $imageX = ImageSX($gd_image); $imageY = ImageSY($gd_image); $BMP = ''; for ($y = $imageY - 1; $y >= 0; $y--) { $thisline = ''; for ($x = 0; $x < $imageX; $x++) { $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); $thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']); } while (strlen($thisline) % 4) { $thisline .= ""; } $BMP .= $thisline; } $bmpSize = strlen($BMP) + 14 + 40; // BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp $BITMAPFILEHEADER = 'BM'; // WORD bfType; $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String($bmpSize, 4); // DWORD bfSize; $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String(0, 2); // WORD bfReserved1; $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String(0, 2); // WORD bfReserved2; $BITMAPFILEHEADER .= phpthumb_functions::LittleEndian2String(54, 4); // DWORD bfOffBits; // BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp $BITMAPINFOHEADER = phpthumb_functions::LittleEndian2String(40, 4); // DWORD biSize; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String($imageX, 4); // LONG biWidth; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String($imageY, 4); // LONG biHeight; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(1, 2); // WORD biPlanes; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(24, 2); // WORD biBitCount; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(0, 4); // DWORD biCompression; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(0, 4); // DWORD biSizeImage; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(2835, 4); // LONG biXPelsPerMeter; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(2835, 4); // LONG biYPelsPerMeter; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(0, 4); // DWORD biClrUsed; $BITMAPINFOHEADER .= phpthumb_functions::LittleEndian2String(0, 4); // DWORD biClrImportant; return $BITMAPFILEHEADER . $BITMAPINFOHEADER . $BMP; }
private static function _transform($fileName, $toWidth, $toHeight, $typeTransform) { //funkcja zwraca uchwyt do zasobu //zasob jest przeskalowanym odpowiednio obrazkiem $inImage = ImageCreateFromJPEG($fileName); $imgWidth = ImageSX($inImage); $imgHeight = ImageSY($inImage); $size = ImageTransform::_compute_size($imgWidth, $imgHeight, $toWidth, $toHeight, $typeTransform); $outImage = ImageCreatetruecolor($size['width'], $size['height']); imagecopyresampled($outImage, $inImage, 0, 0, 0, 0, $size['width'], $size['height'], $imgWidth, $imgHeight); return $outImage; }
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); } }
function ImageFTCenter($image, $size, $angle, $font, $text, $extrainfo = array()) { // find the size of the image $xi = ImageSX($image); $yi = ImageSY($image); // find the size of the text $box = ImageFTBBox($size, $angle, $font, $text, $extrainfo); $xr = abs(max($box[2], $box[4])); $yr = abs(max($box[5], $box[7])); // compute centering $x = intval(($xi - $xr) / 2); $y = intval(($yi + $yr) / 2); return array($x, $y); }
function pc_ImageTTFCenter($image, $text, $font, $size) { // find the size of the image $xi = ImageSX($image); $yi = ImageSY($image); // find the size of the text $box = ImageTTFBBox($size, 0, $font, $text); $xr = abs(max($box[2], $box[4])); $yr = abs(max($box[5], $box[7])); // compute centering $x = intval(($xi - $xr) / 2); $y = intval(($yi + $yr) / 2); return array($x, $y); }
function pc_ImageStringCenter($image, $text, $font) { // font sizes $width = imagefontwidth($font); $height = imagefontheight($font); // find the size of the image $xi = ImageSX($image); $yi = ImageSY($image); // find the size of the text $xr = $width * strlen($text); $yr = $height; // compute centering $x = intval(($xi - $xr) / 2); $y = intval(($yi - $yr) / 2); return array($x, $y); }
function ImageStringCenter($image, $text, $font) { // font sizes $width = array(1 => 5, 6, 7, 8, 9); $height = array(1 => 6, 8, 13, 15, 15); // find the size of the image $xi = ImageSX($image); $yi = ImageSY($image); // find the size of the text $xr = $width[$font] * strlen($text); $yr = $height[$font]; // compute centering $x = intval(($xi - $xr) / 2); $y = intval(($yi - $yr) / 2); return array($x, $y); }
public function createMiniPic($picString, $percent = 0.5) { $source = imagecreatefromstring($picString); $width = ImageSX($source); $height = ImageSY($source); $newwidth = $width * $percent; $newheight = $height * $percent; $thumbnail = ImageCreateTrueColor($newwidth, $newheight); imagecopyresized($thumbnail, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); ImageDestroy($source); ob_start(); imagejpeg($thumbnail); $imageString = ob_get_clean(); ImageDestroy($thumbnail); return $imageString; }
/** * 缩小图片,生成新图片文件 * * @param string $src 源文件全路径 (请保证有读权限) * @param string $dst 源文件全路径,jpg格式 (请保证有读写权限) * @param string $w 目标宽度(默认120像素) * @param string $h 目标高度(默认120像素) * @param string $fillspace 如果尺寸不符,是否用白色填充,默认为false,即从源图中间裁切,目标是源图的一部分 * @param string $quality JPEG质量 * @return boolean true or false */ function crop($src, $dst, $w = 120, $h = 120, $fillspace = false, $quality = 75) { //$src = $_FILES[$this->name]['tmp_name']; $arr = null; if (!($src_image = $this->getImage($src, $arr))) { return FALSE; } $src_w = ImageSX($src_image); $src_h = ImageSY($src_image); if ($src_w > $w || $src_h > $h) { $scalex = $src_w / $w; $scaley = $src_h / $h; if ($fillspace) { if ($scalex > 1 || $scaley > 1) { $scale = $scalex > $scaley ? $scalex : $scaley; $src_image = $this->resize($src_image, $src_w, $src_h, $scale); $src_w = ImageSX($src_image); $src_h = ImageSY($src_image); $src_x = 0; $src_y = 0; $dst_x = ($w - $src_w) / 2; $dst_y = ($h - $src_h) / 2; } } else { if ($scalex > 1 && $scaley > 1) { $scale = $scalex < $scaley ? $scalex : $scaley; $src_image = $this->resize($src_image, $src_w, $src_h, $scale); $src_w = ImageSX($src_image); $src_h = ImageSY($src_image); $src_x = ($src_w - $w) / 2; $src_y = ($src_h - $h) / 2; $dst_x = 0; $dst_y = 0; } } $crop = imagecreatetruecolor($w, $h); $white = imagecolorallocate($crop, 255, 255, 255); imagefill($crop, 0, 0, $white); imagecopy($crop, $src_image, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h); imagedestroy($src_image); } else { $crop =& $src_image; } $ret = imagejpeg($crop, $dst, $quality); imagedestroy($crop); return $ret; }
public static function resize_im($im, $width, $height) { $im_tmp = @imagecreatetruecolor($width, $height); if (@ImageSX($im) >= @ImageSY($im) && @ImageSX($im) > $width) { $thumb_ratio = @ImageSY($im) / (@ImageSX($im) / $width) / $height; //$im_new_th = @ImageCreateTrueColor($this->max_attach_width, $height); @imagecopyresampled($im_tmp, $im, 0, 0, (@ImageSX($im) - @ImageSX($im) * $thumb_ratio) / 1.5, 0, $width, $height, ImageSX($im) * $thumb_ratio, ImageSY($im)); $im = $im_tmp; } else { if (@ImageSY($im) > $height) { $thumb_ratio = @ImageSX($im) / (@ImageSY($im) / $height) / $width; //$im_new_th = @ImageCreateTrueColor($this->max_attach_width, $height); @imagecopyresampled($im_tmp, $im, 0, 0, 0, (@ImageSY($im) - @ImageSY($im) * $thumb_ratio) / 5, $width, $height, @ImageSX($im), @ImageSY($im) * $thumb_ratio); $im = $im_tmp; } } return $im; }
function __grayJpeg($imgname) { $im = @imagecreatefromjpeg($imgname); if (!$im) { $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); imagestring($im, 10, 5, 5, 'Error loading ' . $imgname, $tc); } else { $img_width = ImageSX($im); $img_height = ImageSY($im); for ($y = 0; $y < $img_height; $y++) { for ($x = 0; $x < $img_width; $x++) { $gray = ImageColorAt($im, $x, $y) >> 8 & 0xff; imagesetpixel($im, $x, $y, ImageColorAllocate($im, $gray, $gray, $gray)); } } } return $im; }
private function createImage($source_image, $imgh, $quality) { $im = imagecreatefromjpeg($source_image); $width = imagesx($im); $height = imagesy($im); if ($height > $width) { $imgw = $imgh; $imgh = $height / $width * $imgw; } else { $imgw = $width / $height * $imgh; } $thumb = imagecreatetruecolor($imgw, $imgh); imagecopyresampled($thumb, $im, 0, 0, 0, 0, $imgw, $imgh, ImageSX($im), ImageSY($im)); //makes thumb imagedestroy($im); ob_start(); imagejpeg($thumb, null, $quality); $final_image = ob_get_contents(); ob_end_clean(); imagedestroy($thumb); return $final_image; }
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); }
private function generateImage() { $file = $this->filetmpname; $ext = pathinfo($file, PATHINFO_EXTENSION); switch ($this->fileext) { case "jpg": $im = imagecreatefromjpeg($file); break; case "png": $im = imagecreatefrompng($file); break; case "jpeg": $im = imagecreatefromjpeg($file); break; } // Add Rainbow Layer $x = ImageSX($im); $y = ImageSY($im); $rh = $y / 6; $stamp = imagecreatetruecolor($x, $y); imagefilledrectangle($stamp, 0, $rh, $x, 0, 0xff0000); imagefilledrectangle($stamp, 0, $rh, $x, $rh * 2, 0xff6300); imagefilledrectangle($stamp, 0, $rh * 2, $x, $rh * 3, 0xffff00); imagefilledrectangle($stamp, 0, $rh * 3, $x, $rh * 4, 0x8000); imagefilledrectangle($stamp, 0, $rh * 4, $x, $rh * 5, 0xff); imagefilledrectangle($stamp, 0, $rh * 5, $x, $rh * 6, 0x4b0082); imagecopymerge($im, $stamp, imagesx($im) - $x - 0, imagesy($im) - $y - 0, 0, 0, imagesx($stamp), imagesy($stamp), 50); // Create Directory if not Exists if (!is_dir($this->uploaddir)) { mkdir($this->uploaddir, 0777); } // Move File on Upload Direcory imagepng($im, "{$this->uploaddir}/Rainbow_{$this->imagename}.png"); imagedestroy($im); $this->showResult(); }