private function lagBildeMedStorrelse($sti, $filnavn, $nyttFilnavn, $nyBredde, $nyHoyde) { $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]; $hx = 100 / ($bredde / $nyBredde) * 0.01; $hx = @round($hoyde * $hx); $wx = 100 / ($hoyde / $nyHoyde) * 0.01; $wx = @round($bredde * $wx); if ($hx < $nyHoyde) { $nyHoyde = 100 / ($bredde / $nyBredde) * 0.01; $nyHoyde = @round($hoyde * $nyHoyde); } else { $nyBredde = 100 / ($hoyde / $nyHoyde) * 0.01; $nyBredde = @round($bredde * $nyBredde); } $resBilde = @ImageCreateTrueColor($nyBredde, $nyHoyde); @ImageCopyResampled($resBilde, $bi, 0, 0, 0, 0, $nyBredde, $nyHoyde, $bredde, $hoyde); @Imagejpeg($resBilde, $sti . $nyttFilnavn, 50); return $nyttFilnavn; } else { return -1; } }
function captcha($numchars) { $vals = "ABCDEFGHIJKLMNOPQRSETUVWZYZabcdefghijklmnopqrstuvwxyz0123456789"; $numvals = strlen($vals); $im = ImageCreate(38 * $numchars + 10, 40); $white = ImageColorAllocate($im, 0, 0, 0); $black = ImageColorAllocate($im, 120, 200, 68); srand((double) microtime() * 1000000); $string = ""; ImageFill($im, 0, 0, $black); ImageString($im, 1, 0, 0, "Arcath.net", $white); for ($i = 1; $i <= $numchars; $i++) { $rand = rand(0, $numvals - 1); $out = $vals[$rand]; $string .= $out; ImageString($im, rand(1, 5), $i * 38, rand(5, 25), $out, $white); } Imagejpeg($im, "images/verify.jpeg"); ImageDestroy($im); return $string; }
private function create_do() { $this->im = Imagecreate($this->config['width'], $this->config['height']); //设置背景为白色 Imagecolorallocate($this->im, $this->config['color'][0], $this->config['color'][1], $this->config['color'][2]); //为此背景加个边框 if ($this->config['boxline'] == True) { $bordercolor = Imagecolorallocate($this->im, 37, 37, 37); Imagerectangle($this->im, 0, 0, $this->config['width'] - 1, $this->config['height'] - 1, $bordercolor); } //生成验证码 $this->create_str(); $coder = $_SESSION[$this->config['codname']]; //输入文字 $fontcolor = Imagecolorallocate($this->im, 46, 46, 46); for ($i = 0; $i < $this->config['length']; $i++) { Imagestring($this->im, 5, $i * 10 + 6, rand(2, 5), $coder[$i], $fontcolor); } //加入干扰线 $interfere = $this->config['interfere']; $interfere = $interfere > 30 ? "30" : $interfere; if (!empty($interfere) && $interfere > 1) { for ($i = 1; $i < $interfere; $i++) { $linecolor = Imagecolorallocate($this->im, rand(0, 255), rand(0, 255), rand(0, 255)); $x = rand(1, $this->config['width']); $y = rand(1, $this->config['height']); $x2 = rand($x - 10, $x + 10); $y2 = rand($y - 10, $y + 10); Imageline($this->im, $x, $y, $x2, $y2, $linecolor); } } ob_clean(); Header("Pragma:no-cache\r\n"); Header("Cache-Control:no-cache\r\n"); Header("Expires:0\r\n"); Header("Content-type:Image/jpeg\r\n"); Imagejpeg($this->im); Imagedestroy($this->im); exit; }
function forumbadge_run() { global $session; $acctid = httpget("acctid"); page_header("Badge!"); //PHP's GD class functions can create a variety of output image //types, this example creates a jpeg header("Content-Type: image/jpeg"); //open up the image you want to put text over $im = ImageCreateFromPng("modules/buttonbase.png"); //The numbers are the RGB values of the color you want to use $black = ImageColorAllocate($im, 0, 0, 0); //The canvas's (0,0) position is the upper left corner //So this is how far down and to the right the text should start $start_x = 10; $start_y = 20; $sql = "SELECT race, login, level, dragonkills FROM " . db_prefix("accounts") . " WHERE acctid = {$acctid}"; $result = db_fetch_assoc(db_query($sql)); $name = $result['login']; $race = $result['race']; $level = "Level " . $result['level']; $dragonkills = "Drive Kills: " . $result['dragonkills']; debug($result); //This writes your text on the image in 12 point using verdana.ttf //For the type of effects you quoted, you'll want to use a truetype font //And not one of GD's built in fonts. Just upload the ttf file from your //c: windows fonts directory to your web server to use it. Imagettftext($im, 10, 0, 65, 12, $black, 'modules/verdana.ttf', $name); Imagettftext($im, 10, 0, 65, 27, $black, 'modules/verdana.ttf', $race); Imagettftext($im, 10, 0, 65, 42, $black, 'modules/verdana.ttf', $level); Imagettftext($im, 10, 0, 65, 57, $black, 'modules/verdana.ttf', $dragonkills); //Creates the jpeg image and sends it to the browser //100 is the jpeg quality percentage Imagejpeg($im, '', 60); ImageDestroy($im); page_footer(); }
function imageResize() { global $engine_path, $ImageTrimX, $ImageTrimY; $source = $this->image; $newWidth = $this->newWidth; $newHeight = $this->newHeight; $imType = $this->type; if ($imType == "jpeg" || $imType == "pjpeg") { $srcImage = ImageCreateFromJPEG($source); } elseif ($imType == "gif") { $srcImage = LoadGif($source); } else { $srcImage = ImageCreateFromPNG($source); } $srcWidth = ImageSX($srcImage); $srcHeight = ImageSY($srcImage); $ratioWidth = $srcWidth / $newWidth; $ratioHeight = $srcHeight / $newHeight; if ($ratioWidth < 1 && $this->fix == "width" || $ratioHeight < 1 && $this->fix == "height") { $destWidth = $srcWidth; $destHeight = $srcHeight; //print "mode 1"; //exit; } elseif ($ratioWidth > $ratioHeight || $ratioWidth < $ratioHeight && $this->fix != "width" || $this->fix == "height") { $destWidth = $srcWidth / $ratioHeight; $destHeight = $newHeight; //print "mode 2"; //exit; } else { $destWidth = $newWidth; $destHeight = $srcHeight / $ratioWidth; //print "mode 3 $ratioHeight $ratioWidth $this->fix"; //exit; } //$this->newWidth=$destWidth; //$this->newHeight=$desHeight; //print "$this->newWidth - $this->newHeight"; //print $srcImage." $ratioWidth $ratioHeight $this->fix $destWidth $destHeight"; //print "-($newHeight-$destHeight)/2"; //exit; if ($newWidth != $srcWidth && $newHeight != $srcHeight && $newWidth != 160) { if (!strlen($ImageTrim)) { $ImageTrim = 2; } if ($ImageTrimY == 0) { $y = 0; } elseif ($ImageTrimY == 1) { $y = ($newHeight - $destHeight) / 4; } elseif ($ImageTrimY == 2) { $y = ($newHeight - $destHeight) / 2; } elseif ($ImageTrimY == 3) { $y = 3 * ($newHeight - $destHeight) / 2; } elseif ($ImageTrimY == 4) { $y = 5 * ($newHeight - $destHeight) / 2; } if ($ImageTrimX == 0) { $x = 0; } elseif ($ImageTrimX == 1) { $x = ($newWidth - $destWidth) / 4; } elseif ($ImageTrimX == 2) { $x = ($newWidth - $destWidth) / 2; } elseif ($ImageTrimX == 3) { $x = 3 * ($newWidth - $destWidth) / 2; } elseif ($ImageTrimX == 4) { $x = 5 * ($newWidth - $destWidth) / 2; } //print "$ImageTrimY $ImageTrimX $x $y"; //exit; $destImage = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($destImage, $srcImage, $x, $y, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); } else { $destImage = imagecreatetruecolor($destWidth, $destHeight); imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); } if ($this->mix) { $destImage = $this->mix($destImage); } $name = $engine_path . "img/small/" . $this->name; if ($imType == "jpeg" || $imType == "pjpeg") { Imagejpeg($destImage, $name); } elseif ($imType == "gif") { Imagegif($destImage, $name); } else { Imagepng($destImage, $name); } $file['tmp_name'] = $name; ImageDestroy($srcImage); ImageDestroy($destImage); return $file; }
<?php define("THUMB_MAX_HEIGHT", 75); define("THUMB_MAX_WIDTH", 75); if (is_file("{$image}")) { header("Content-type: image/jpeg"); Header("Last-Modified: " . gmdate('D, d M Y H:i:s T', filemtime($image))); Header("Expires: " . gmdate('D, d M Y H:i:s T', filemtime($image) + 60 * 60 * 24 * 7)); $src_img = imagecreatefromjpeg("{$image}"); if (imagesx($src_img) > imagesy($src_img)) { $xsize = THUMB_MAX_HEIGHT; $ysize = intval(THUMB_MAX_WIDTH / imagesx($src_img) * imagesy($src_img)); } else { $ysize = THUMB_MAX_WIDTH; $xsize = intval(THUMB_MAX_HEIGHT / imagesy($src_img) * imagesx($src_img)); } $dst_img = @imagecreatetruecolor($xsize, $ysize); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $xsize, $ysize, imagesx($src_img), imagesy($src_img)); Imagejpeg($dst_img); ImageDestroy($dst_img); } else { header("HTTP/1.1 404 Not Found"); exit; } ?>
imagettftext($finalimage, 9, 0, 35, 376, $black, $font, $level . "%"); $value = array(2, 19, 7, 101, 27, 101, 27, 19); imagefilledpolygon($finalimage, $value, 4, $red); $value = array(7, 102, 12, 162, 27, 162, 27, 102); imagefilledpolygon($finalimage, $value, 4, $orange); $value = array(12, 163, 17, 221, 27, 221, 27, 163); imagefilledpolygon($finalimage, $value, 4, $yellow); $value = array(17, 222, 22, 281, 27, 281, 27, 222); imagefilledpolygon($finalimage, $value, 4, $yellgr); $value = array(22, 282, 27, 348, 27, 348, 27, 282); imagefilledpolygon($finalimage, $value, 4, $green); imagefilledellipse($finalimage, 65, 101, 6, 6, $red); imagefilledellipse($finalimage, 65, 161, 6, 6, $orange); imagefilledellipse($finalimage, 65, 221, 6, 6, $yellow); imagefilledellipse($finalimage, 65, 281, 6, 6, $yellgr); imagefilledellipse($finalimage, 65, 346, 6, 6, $green); if ($t_current > $t_max) { $burstImg = ImageCreateFromjpeg('burst.jpg'); $burstW = ImageSX($burstImg); $burstH = ImageSY($burstImg); ImageCopy($finalimage, $burstImg, 0, 0, 0, 0, $burstW, $burstH); } //Create the final image Imagejpeg($finalimage, NULL, 99); //Destroy de rest of images Imagedestroy($finalimage); Imagedestroy($thermImage); Imagedestroy($thermbarImage); ?>
if ($crop == 'c' and $dx > $x) { // scale it to tempImage $tempImage = imagecreatetruecolor($dx, $dy); ImageCopyResampled($tempImage, $srcImage, 0, 0, 0, 0, $dx, $dy, $srcWidth, $srcHeight); // crop it to destImage $destImage = imagecreatetruecolor($x, $dy); imagecopy($destImage, $tempImage, 0, 0, 0, 0, $x, $dy); $bordercolor = ImageColorAllocate($destImage, 0, 0, 0); ImageRectangle($destImage, 0, 0, $x - 1, $dy - 1, $bordercolor); imagedestroy($tempImage); } else { $destImage = imagecreatetruecolor($dx, $dy); ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $dx, $dy, $srcWidth, $srcHeight); } } Imagejpeg($destImage, $file_cache_path, 100); if (prepWritableFile($file_cache_path)) { header("Content-type: image/jpeg"); readfile($file_cache_path); } else { // if all caching fails, output directly header("Content-type: image/jpeg"); imagejpeg($destImage); } imagedestroy($srcImage); imagedestroy($destImage); } } function getExtension($str) { $i = strrpos($str, ".");
function setThumbnail($file, $upload_dir = ".", $thumbnail_upload_dir = "./thumb", $filename = "", $thumbnail_size = 250, $thumbnail_quality = 76, $limit_size = 2, $type = 1, $check = 0, $image_type = 0, $image_width = 800, $image_height = 600, $limit_length = 30) { if ($filename == "") { $filename = $file[name]; } $img_size = $this->setFileUpload($file, $upload_dir, $filename, $limit_size, $type, $check, $image_type, $image_width, $image_height = 600, $limit_length = 30); //앨범에서의 썸네일 이미지를 위해 JPG GD를 사용하여 썸네일 이미지를 생성한다. if ($img_size[0] > $img_size[1]) { //가로방향 이미지 if ($img_size[0] > $thumbnail_size) { $img_width = $thumbnail_size; $img_height = $img_size[1] * $thumbnail_size / $img_size[0]; } else { $img_width = $img_size[0]; $img_height = $img_size[1]; } } else { //세로방향 이미지 if ($img_size[1] > $thumbnail_size) { $img_width = $img_size[0] * $thumbnail_size / $img_size[1]; $img_height = $thumbnail_size; } else { $img_width = $img_size[0]; $img_height = $img_size[1]; } } if ($file[type] == "image/pjpeg" && (eregi("\\.jpg\$", $file[name]) || eregi("\\.jpeg\$", $file[name])) && $this->varGDPermit[jpg] == 'Y') { $dst_img = ImageCreate($img_width, $img_height); // 위에서 계산한대로 빈 이미지 파일을 만듭니다. $src_img = ImageCreateFromjpeg("{$upload_dir}/{$filename}"); // 이미지파일을 읽어들입니다. ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img)); //빈 이미지에다 원본이미지를 줄여서 그립니다. $creat_file_name = "{$thumbnail_upload_dir}/{$filename}"; Imagejpeg($dst_img, $creat_file_name, $thumbnail_quality); // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다. } else { if ($file[type] == "image/x-png" && eregi("\\.png\$", $file[name]) && $this->varGDPermit[png] == 'Y') { $dst_img = ImageCreate($img_width, $img_height); // 위에서 계산한대로 빈 이미지 파일을 만듭니다. $src_img = ImageCreateFrompng("{$upload_dir}/{$filename}"); // 이미지파일을 읽어들입니다. ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img)); //빈 이미지에다 원본이미지를 줄여서 그립니다. $creat_file_name = "{$thumbnail_upload_dir}/{$filename}"; Imagepng($dst_img, $creat_file_name, $thumbnail_quality); // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다. } else { if ($file[type] == "image/gif" && eregi("\\.gif\$", $file[name]) && $this->varGDPermit[gif] == 'Y') { $dst_img = ImageCreate($img_width, $img_height); // 위에서 계산한대로 빈 이미지 파일을 만듭니다. $src_img = ImageCreateFromgif("{$upload_dir}/{$filename}"); // 이미지파일을 읽어들입니다. ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img)); //빈 이미지에다 원본이미지를 줄여서 그립니다. $creat_file_name = "{$thumbnail_upload_dir}/{$filename}"; Imagegif($dst_img, $creat_file_name, $thumbnail_quality); // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다. } else { $this->errmsg("{$file['type']}은 GD를 지원하지 않습니다!!"); } } } ImageDestroy($dst_img); //로드한 메모리를 비워줍니다. gd는 꼭 이걸 해주어야 합니다. ImageDestroy($src_img); }
function cropped() { Header("Content-Type: image/jpeg"); $_SEGS = $this->uri->ruri_to_assoc(); $this->im = $this->gallery_model->get_data_row($_SEGS['file_id'], $_SEGS['id']); $width_max = 600; $height_max = 600; //echo $this->im['links']; $this->im = str_replace(base_url(), '', $this->im['links']); if (file_exists($this->im)) { list($width, $height, $type, $attr) = getimagesize($this->im); if ($width >= $height) { $percent = $width_max / $width; $width_new = $width * $percent; $height_new = $height * $percent; } else { $percent = $height_max / $height; $width_new = $width * $percent; $height_new = $height * $percent; } } //echo $percent;die; $new = imagecreatetruecolor($width_new, $height_new); $this->im = imagecreatefromjpeg($this->im); imagecopyresized($new, $this->im, 0, 0, 0, 0, $width_new, $height_new, $width, $height); Imagejpeg($new); ImageDestroy($new); }
function resizeimage($imgp, $imgw, $imgh) { $imagepath = base64_decode($imgp); #echo '.... ' . base64_decode( $imgp ); #flush();die(' stop!'); # Thanks to Michał Albrecht! $suffix = strtolower(substr($imagepath, -4)); $imgsize = @getimagesize($imagepath); # http://be.php.net/getimagesize $head = "Content-type: {$imgsize['mime']}"; if ($suffix == ".gif") { #$head = "Content-type: image/gif"; $img = imagecreatefromgif($imagepath); if (!$img) { brokenimage("Error loading GIF"); } } else { if ($suffix == ".jpg" or $suffix == "jpeg") { #$head = "Content-type: image/jpeg"; $img = imagecreatefromjpeg($imagepath); if (!$img) { brokenimage("Error loading JPG"); } } else { if ($suffix == ".png") { #$head = "Content-type: image/png"; $img = imagecreatefrompng($imagepath); if (!$img) { brokenimage("Error loading PNG"); } } } } # Resize the image $src_h = ImageSY($img); $src_w = ImageSX($img); $dst_img = imagecreatetruecolor($imgw, $imgh); imagecopyresampled($dst_img, $img, 0, 0, 0, 0, $imgw, $imgh, $src_w, $src_h); $img = $dst_img; imageinterlace($img, 1); imagecolortransparent($img); ob_start(); if ($suffix == ".gif") { Imagegif($img); } else { if ($suffix == ".jpg" or $suffix == ".jpeg") { Imagejpeg($img, '', 80); } else { if ($suffix == ".png") { Imagepng($img); } } } $result = ob_get_clean(); #ImageDestroy($img); $result = serialize(array($head, base64_encode($result))); return $result; }
public function image_handler($source_image, $destination, $tn_w = 100, $tn_h = 100, $quality = 80, $wmsource = false) { #find out what type of image this is $info = getimagesize($source_image); $imgtype = image_type_to_mime_type($info[2]); #assuming the mime type is correct switch ($imgtype) { case 'image/jpeg': $source = imagecreatefromjpeg($source_image); break; case 'image/gif': $source = imagecreatefromgif($source_image); break; case 'image/png': $source = imagecreatefrompng($source_image); break; default: die('Invalid image type.'); } #Figure out the dimensions of the image and the dimensions of the desired thumbnail $src_w = imagesx($source); $src_h = imagesy($source); $src_ratio = $src_w / $src_h; if (empty($tn_h)) { $tn_h = $tn_w / $src_ratio; } if ($tn_w / $tn_h > $src_ratio) { $new_h = $tn_w / $src_ratio; $new_w = $tn_w; } else { $new_w = $tn_h * $src_ratio; $new_h = $tn_h; } #Do some math to figure out which way we'll need to crop the image #to get it proportional to the new size, then crop or adjust as needed $x_mid = $new_w / 2; $y_mid = $new_h / 2; $newpic = imagecreatetruecolor(round($new_w), round($new_h)); imagecopyresampled($newpic, $source, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h); $final = imagecreatetruecolor($tn_w, $tn_h); //imagecopyresampled($final, $newpic, 0, 0, 0, 0, $tn_w, $tn_h, $tn_w, $tn_h); imagecopyresampled($final, $newpic, 0, 0, $x_mid - $tn_w / 2, $y_mid - $tn_h / 2, $tn_w, $tn_h, $tn_w, $tn_h); #if we need to add a watermark if ($wmsource) { #find out what type of image the watermark is $info = getimagesize($wmsource); $imgtype = image_type_to_mime_type($info[2]); #assuming the mime type is correct switch ($imgtype) { case 'image/jpeg': $watermark = imagecreatefromjpeg($wmsource); break; case 'image/gif': $watermark = imagecreatefromgif($wmsource); break; case 'image/png': $watermark = imagecreatefrompng($wmsource); break; default: die('Invalid watermark type.'); } #if we're adding a watermark, figure out the size of the watermark #and then place the watermark image on the bottom right of the image $wm_w = imagesx($watermark); $wm_h = imagesy($watermark); imagecopy($final, $watermark, $tn_w - $wm_w, $tn_h - $wm_h, 0, 0, $tn_w, $tn_h); } return Imagejpeg($final, $destination, $quality); }
public function func_resize_save($dst_file, $src_file, $save_path, $max_x, $max_y) { $img_size = getimagesize($src_file); $img_replace = basename($src_file); switch ($img_size[2]) { //gif case 1: $src_img = ImageCreateFromgif($src_file); $dst_img = ImageCreateTrueColor($max_x, $max_y); ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]); Imagegif($dst_img, $save_path . $img_replace, 100); break; //jpeg or jpg //jpeg or jpg case 2: $src_img = ImageCreateFromjpeg($src_file); $dst_img = ImageCreateTrueColor($max_x, $max_y); ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]); Imagejpeg($dst_img, $save_path . $img_replace, 100); break; //png //png case 3: $src_img = ImageCreateFrompng($src_file); $dst_img = ImageCreateTrueColor($max_x, $max_y); ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]); Imagepng($dst_img, $save_path . $img_replace, 9); break; } ImageDestroy($dst_img); ImageDestroy($src_img); }
/** * redimensionne la photo * * @param $chemin répertoire de la photo * @param $photo la photo que l'on souhaite redimensionner * @param $taille la taille désiré */ function redimPhoto($chemin, $photo, $taille) { //redimensionnement photo petit format $size = getimagesize($chemin . "o" . $photo); if ($size[0] > $taille || $size[1] > $taille) { if ($size[0] > $size[1]) { // largeur suprieure la hauteur $wg = $taille; $hg = number_format($size[1] / ($size[0] / $taille), 0, ",", ""); } else { // hauteur suprieure la largeur $hg = $taille; $wg = number_format($size[0] / ($size[1] / $taille), 0, ",", ""); } } else { $wg = $size[0]; $hg = $size[1]; } $src_img = imagecreatefromjpeg($chemin . "o" . $photo); $dst_img = imagecreatetruecolor($wg, $hg); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $wg, $hg, $size[0], $size[1]); Imagejpeg($dst_img, $chemin . $photo, 100); }
$image = $_POST['image']; $filter_image = str_replace("data:image/png;base64,", "", $image); // input is in format 1,2,3...|1,2,3...|... if ($filter_image == $invalid) { $im = ""; echo "false"; } else { $im = imagecreatetruecolor(320, 240); foreach (explode("|", $_POST['image']) as $y => $csv) { foreach (explode(";", $csv) as $x => $color) { imagesetpixel($im, $x, $y, $color); } } } } else { // input is in format: data:image/png;base64,... $image = $_POST['image']; $filter_image = str_replace("data:image/png;base64,", "", $image); if ($filter_image == $invalid) { $im = ""; echo "false"; } else { $im = imagecreatefrompng($_POST['image']); } } if ($im) { $filename = time() . $uid . ".jpg"; $data = $FbWall->Image_Upload($uid, $filename); imagejpeg($im); Imagejpeg($im, "uploads/" . $filename); }
function scaleImage($image = '', $imageType = 'jpg', $path = 'default', $x = 0, $y = 0, $dx = 0, $dy = 0, $fixed = '', $crop = '', $file_cache_path = '') { // else create a new scaled image switch ($path) { case 'uploads': $path = PATH_UPLOAD_IMAGES; break; case 'submissions': $path = PATH_UPLOAD_SUBMISSIONS; break; default: $path = PATH_CACHE; break; } $file_orig = $path . '/' . $image . '.' . $imageType; //$this->db->log($file_orig); //$imageType=$this->getExtension($imaqe); $imageType = strtolower($imageType); //$this->db->log('scaleimage name'.$file_orig.' type'.$imageType.' '.$file_cache_path); switch ($imageType) { case 'jpg': $srcImage = imagecreatefromjpeg($file_orig); break; case 'png': $srcImage = imagecreatefrompng($file_orig); break; case 'gif': $srcImage = imagecreatefromgif($file_orig); break; default: // error die('No valid image type'); break; } list($srcWidth, $srcHeight) = getimagesize($file_orig); $srcWidth > $srcHeight ? $layout = 'landscape' : ($layout = 'portrait'); if ($layout == 'landscape' and $srcWidth < $dx or $layout == 'portrait' and $srcHeight < $dy) { // too small, use original image $dx = $srcWidth; $dy = $srcHeight; } switch ($fixed) { case 'y': // scale the width to the requested height $dx = round($srcWidth * ($dy / $srcHeight)); break; case 'x': // scale the height to the requested width $dy = round($srcHeight * ($dx / $srcWidth)); break; default: // scale the shortest axis if ($layout == 'portrait') { $dx = round($srcWidth * ($dy / $srcHeight)); } else { $dy = round($srcHeight * ($dx / $srcWidth)); } break; } if ($crop == 'c' and $dy > $y) { // scale it to tempImage $tempImage = imagecreatetruecolor($dx, $dy); imageColorAllocate($tempImage, 255, 255, 255); imagealphablending($tempImage, false); imagesavealpha($tempImage, true); ImageCopyResampled($tempImage, $srcImage, 0, 0, 0, 0, $dx, $dy, $srcWidth, $srcHeight); // crop it to destImage $destImage = imagecreatetruecolor($dx, $y); imagecopy($destImage, $tempImage, 0, 0, 0, 0, $dx, $y); //$bordercolor = ImageColorAllocate($destImage,0,0,0); //ImageRectangle($destImage,0,0,($dx-1),($y-1),$bordercolor); imagedestroy($tempImage); } else { if ($crop == 'c' and $dx > $x) { // scale it to tempImage $tempImage = imagecreatetruecolor($dx, $dy); ImageColorAllocate($tempImage, 255, 255, 255); imagealphablending($tempImage, false); imagesavealpha($tempImage, true); ImageCopyResampled($tempImage, $srcImage, 0, 0, 0, 0, $dx, $dy, $srcWidth, $srcHeight); // crop it to destImage $destImage = imagecreatetruecolor($x, $dy); imagecopy($destImage, $tempImage, 0, 0, 0, 0, $x, $dy); //$bordercolor = ImageColorAllocate($destImage,0,0,0); //ImageRectangle($destImage,0,0,($x-1),($dy-1),$bordercolor); imagedestroy($tempImage); } else { $destImage = imagecreatetruecolor($dx, $dy); ImageColorAllocate($destImage, 255, 255, 255); imagealphablending($destImage, false); imagesavealpha($destImage, true); ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $dx, $dy, $srcWidth, $srcHeight); } } Imagejpeg($destImage, $file_cache_path, 100); if ($this->prepWritableFile($file_cache_path)) { header("Content-type: image/jpeg"); readfile($file_cache_path); } else { // if all caching fails, output directly header("Content-type: image/jpeg"); imagejpeg($destImage); } imagedestroy($srcImage); imagedestroy($destImage); }
$text = $username; $textsize = imagettfbbox($fontsize, 0, $fontfile, $text); ImageTTFText($im, $fontsize, 0, imagesx($im) - ($textsize[2] - $textsize[0]) - 5 > $maxtextwidth ? imagesx($im) - ($textsize[2] - $textsize[0]) - 5 : $maxtextwidth, 15, $clrBlack, $fontfile, $text); $fontsize = 7.5; $textsize = imagettfbbox($fontsize, 0, $fontfile, $logotext); ImageTTFText($im, $fontsize, 0, imagesx($im) - ($textsize[2] - $textsize[0]) - 5 > $maxtextwidth ? imagesx($im) - ($textsize[2] - $textsize[0]) - 5 : $maxtextwidth, 32, $clrBlack, $fontfile, $logotext); break; case 1: default: // write text $fontsize = 10; $text = $username; $textsize = imagettfbbox($fontsize, 0, $fontfile, $text); ImageTTFText($im, $fontsize, 0, imagesx($im) - ($textsize[2] - $textsize[0]) - 5 > $maxtextwidth ? imagesx($im) - ($textsize[2] - $textsize[0]) - 5 : $maxtextwidth, 15, $clrBlack, $fontfile, $text); $fontsize = 7; $text = "Gefunden: {$found} Versteckt: {$hidden}"; $textsize = imagettfbbox($fontsize, 0, $fontfile, $text); ImageTTFText($im, $fontsize, 0, imagesx($im) - ($textsize[2] - $textsize[0]) - 5 > $maxtextwidth ? imagesx($im) - ($textsize[2] - $textsize[0]) - 5 : $maxtextwidth, 29, $clrBlack, $fontfile, $text); $fontsize = 8; $textsize = imagettfbbox($fontsize, 0, $fontfile, $logotext); ImageTTFText($im, $fontsize, 0, imagesx($im) - ($textsize[2] - $textsize[0]) - 5 > $maxtextwidth ? imagesx($im) - ($textsize[2] - $textsize[0]) - 5 : $maxtextwidth, 45, $clrBlack, $fontfile, $logotext); } // draw border ImageRectangle($im, 0, 0, imagesx($im) - 1, imagesy($im) - 1, $clrBorder); // write output Imagejpeg($im, $opt['rootpath'] . 'images/statpics/statpic' . $userid . '.jpg', $jpeg_qualitaet); ImageDestroy($im); sql("INSERT INTO `user_statpic` (`user_id`) VALUES ('&1') ON DUPLICATE KEY UPDATE `date_created`=NOW()", $userid); } // Redirect auf das gespeicherte Bild $tpl->redirect('images/statpics/statpic' . $userid . '.jpg');
function imageMix($mix) { global $engine_path, $ImageTrimX, $ImageTrimY; $source = $this->image; $imType = $this->type; if (!$imType || $imType == "jpeg" || $imType == "pjpeg") { $srcImage = ImageCreateFromJPEG($source); } elseif ($imType == "gif") { $srcImage = LoadGif($source); } else { $srcImage = ImageCreateFromPNG($source); } if ($mix) { $srcImage = $this->mix($srcImage, $mix); } $name = $engine_path . "tmp/" . "mix" . $this->name; if (!file_exists($engine_path . "tmp/")) { mkdir_r($engine_path . "tmp/"); } if ($imType == "jpeg" || $imType == "pjpeg") { Imagejpeg($srcImage, $name); } elseif ($imType == "gif") { Imagegif($srcImage, $name); } else { Imagepng($srcImage, $name); } $file['tmp_name'] = $name; ImageDestroy($srcImage); return $file; }
function get_image_profile($id) { header('Content-Type: image/jpeg'); $config['width'] = 140; $data = $this->spkp_model->get_user_profile($id); $filename = getcwd() . "/media/images/user/" . $data['image']; if (!file_exists($filename) || $data['image'] == "") { $filename = getcwd() . "/media/images/smily-user-icon.jpg"; } list($width, $height) = getimagesize($filename); $percent = $config['width'] / $width; $newwidth = $width * $percent; $newheight = $height * $percent; $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); Imagejpeg($thumb); ImageDestroy($thumb); }
function GD2_make_thumb_x($max_x, $dst_name, $src_file) { //가로 사이즈만 지정하는 썸네일 생성. $img_info = @getimagesize($src_file); $sx = $img_info[0]; $sy = $img_info[1]; //썸네일 보다 큰가? if ($sx > $max_x) { $thumb_y = ceil($sy * $max_x / $sx); $thumb_x = $max_x; } else { $thumb_y = $sy; $thumb_x = $sx; } // JPG 파일인가? if (true) { $_dq_tempFile = basename($src_file); //파일명 추출 $_dq_tempDir = str_replace($_dq_tempFile, "", $src_file); //경로 추출 $_dq_tempFile = $_dq_tempDir . $dst_name . $_dq_tempFile; //경로 + 새 파일명 생성 $_create_thumb_file = true; if (file_exists($_dq_tempFile)) { //섬네일 파일이 이미 존제한다면 이미지의 사이즈 비교 $old_img = @getimagesize($_dq_tempFile); if ($old_img[0] != $thumb_x) { $_create_thumb_file = true; } else { $_create_thumb_file = false; } if ($old_img[1] != $thumb_y) { $_create_thumb_file = true; } else { $_create_thumb_file = false; } } if ($_create_thumb_file) { // 복제 $src_img = ImageCreateFromAnything($src_file); $dst_img = ImageCreateTrueColor($thumb_x, $thumb_y); if ($img_info[2] == 1 or $img_info[2] == 3) { imagealphablending($dst_img, false); imagesavealpha($dst_img, true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, $thumb_x, $thumb_y, $transparent); } ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_x, $thumb_y, $sx, $sy); switch ($img_info[2]) { case 1: imagegif($dst_img, $_dq_tempFile); break; case 2: imagejpeg($dst_img, $_dq_tempFile); break; case 3: imagepng($dst_img, $_dq_tempFile); break; default: Imagejpeg($dst_img, $_dq_tempFile, 100); break; } // 메모리 초기화 ImageDestroy($dst_img); ImageDestroy($src_img); } } }
function resize_picture($bild, $breite, $thumbname, $quali = 100, $mode = 1) { @chmod($bild, 0777); $image_array = getimagesize($bild); if ($mode == 0 and $image_array[0] < $image_array[1]) { $verh = $image_array[1] / $breite; $hoehe = $image_array[0] / $verh; $breite = $hoehe * $image_array[0] / $image_array[1]; } else { $verh = $image_array[0] / $breite; $hoehe = $image_array[1] / $verh; } $original = ImageCreateFromJPEG($bild); @unlink($path . $thumbname); $thumbnail = imagecreatetruecolor($breite, $hoehe); // bei GD version 2.0.1 oder h�her imagecopyresized($thumbnail, $original, 0, 0, 0, 0, $breite, $hoehe, $image_array[0], $image_array[1]); Imagejpeg($thumbnail, $path . $thumbname, $quali); // absolute Pfadangabe des Uploadverzeichnisses umask(0); chmod($thumbnail, $path . $thumbname, CHMOD); ImageDestroy($thumbnail); }
case 9: default: // write text $fontsize = 10; $text = $username; $textsize = imagettfbbox($fontsize, 0, $fontfile, $text); ImageTTFText($im, $fontsize, 0, imagesx($im) - ($textsize[2] - $textsize[0]) - 5 > $maxtextwidth ? imagesx($im) - ($textsize[2] - $textsize[0]) - 5 : $maxtextwidth, 15, $clrBlack, $fontfile, $text); $fontsize = 7; $text = $text_counterstat; $textsize = imagettfbbox($fontsize, 0, $fontfile, $text); ImageTTFText($im, $fontsize, 0, imagesx($im) - ($textsize[2] - $textsize[0]) - 5 > $maxtextwidth ? imagesx($im) - ($textsize[2] - $textsize[0]) - 5 : $maxtextwidth, 29, $clrBlack, $fontfile, $text); $fontsize = 8; $textsize = imagettfbbox($fontsize, 0, $fontfile, $logotext); ImageTTFText($im, $fontsize, 0, imagesx($im) - ($textsize[2] - $textsize[0]) - 5 > $maxtextwidth ? imagesx($im) - ($textsize[2] - $textsize[0]) - 5 : $maxtextwidth, 45, $clrBlack, $fontfile, $logotext); } if ($drawRectangle == true) { // draw border ImageRectangle($im, 0, 0, imagesx($im) - 1, imagesy($im) - 1, $clrBorder); } // write output Imagejpeg($im, $filename, $jpeg_qualitaet); ImageDestroy($im); sql("INSERT INTO `user_statpic` (`user_id`, `lang`) VALUES ('&1', '&2') ON DUPLICATE KEY UPDATE `date_created`=NOW()", $userid, $lang); } // Redirect auf das gespeicherte Bild $tpl->redirect('images/statpics/statpic' . $userid . $lang . '.jpg'); function GetFilename($userid, $lang) { global $opt; return $opt['rootpath'] . 'images/statpics/statpic' . $userid . $lang . '.jpg'; }
function Dump_down($count) { $gallery_count_downloads = $count + 1; $gallery_cells = array('gallery_count_downloads'); $gallery_save = array($gallery_count_downloads); cs_sql_update(__FILE__, 'gallery', $gallery_cells, $gallery_save, $_REQUEST['pic']); # disable browser / proxy caching header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header('Content-Transfer-Encoding: none'); header("Accept-Ranges: bytes"); header("Content-type: image/jpg"); header("Content-Disposition: attachment; filename=image.jpg"); echo @readfile(Imagejpeg($this->image, null, 100), "r"); exit; }
public function createBarCode($image_type = 'png', $file_name = null) { $this->parseCode(); $this->image = ImageCreate($this->width + 2 * $this->quiet_zone, $this->height + $this->font_height + $this->quiet_zone); $this->bgcolor = imagecolorallocate($this->image, $this->bgcolor >> 16, $this->bgcolor >> 8 & 0xff, $this->bgcolor & 0xff); $this->color = imagecolorallocate($this->image, $this->color >> 16, $this->color >> 8 & 0xff, $this->color & 0xff); ImageFilledRectangle($this->image, 0, 0, $this->width + 2 * $this->quiet_zone, $this->height + $this->font_height, $this->bgcolor); $sx = $this->quiet_zone; $sy = $this->font_height - 1; $fw = 10; //編號為2或3的字體的寬度為10,為4或5的字體寬度為11 if ($this->font_type > 3) { $sy++; $fw = 11; } $ex = 0; if ($this->text) { //不显示号码,则生成满的条码 if ($this->showType == 'top') { $ey = $this->height + $this->font_height - 2; //条码显示上方 } else { if ($this->showType == 'bottom') { $ey = $this->height - 2; //条码显示下方 $sy = $this->quiet_zone; } } } else { $ey = $this->height + $this->font_height; $sy = $this->quiet_zone; } for ($i = 0; $i < strlen($this->bin_code); $i++) { $ex = $sx + $this->unit_width * (int) $this->bin_code[$i] - 1; if ($i % 2 == 0) { ImageFilledRectangle($this->image, $sx, $sy, $ex, $ey, $this->color); } $sx = $ex + 1; } if ($this->text) { //存在条码号再显示 $t_num = strlen($this->text); $t_x = $this->width / $t_num; $t_sx = ($t_x - $fw) / 2; //目的为了使文字居中平均分布 if ($this->showType == 'top') { $y = 0; } else { if ($this->showType == 'bottom') { $y = $this->height; } } for ($i = 0; $i < $t_num; $i++) { imagechar($this->image, $this->font_type, 6 * $this->unit_width + $t_sx + $i * $t_x, $y, $this->text[$i], $this->color); } } if (!$file_name) { header("Content-Type: image/" . $image_type); } switch ($image_type) { case 'jpg': case 'jpeg': Imagejpeg($this->image, $file_name); break; case 'png': Imagepng($this->image, $file_name); break; case 'gif': break; Imagegif($this->image, $file_name); default: Imagepng($this->image, $file_name); break; } }
$new_h = ceil($imagedata[1] * ($new_w / $imagedata[0])); if ($_height_min_ and $new_h != $_height_min_) { $new_h = $_height_min_; //$new_w = ceil($imagedata[0]*($new_h/$imagedata[1])); } if (strtolower(substr($_GET['img'], -3)) == "jpg") { header("Content-type: image/jpg"); if (file_exists($path)) { echo file_get_contents($path); } else { $dst_img = ImageCreate($new_w, $new_h); $src_img = ImageCreateFromJpeg($_image_); $dst_img = imagecreatetruecolor($new_w, $new_h); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img)); ob_start(); $img = Imagejpeg($dst_img, '', $_quality_); $ob_contents = ob_get_contents(); // Save file $fp = fopen("{$path}", 'wb'); fwrite($fp, $ob_contents); fclose($fp); ob_end_flush(); } } if (substr($_GET['img'], -3) == "gif") { header("Content-type: image/gif"); if (file_exists($path)) { echo file_get_contents($path); } else { $dst_img = ImageCreate($new_w, $new_h); $src_img = ImageCreateFromGif($_image_);
if ($pos == "bottomleft") { $src_x = 0; $src_y = $by - 20; } else { if ($pos == "bottomright") { $src_x = $bx - 270; $src_y = $by - 10; } } } } // position in pixel from bottom // blend the watermark with the picture ImageAlphaBlending($lm, true) or die("Could not create the watermark"); // enable GD 2+ // file that will be used as the watermark (png format) if (file_exists('images/watermark.png')) { $logoImage = ImageCreateFromPNG('images/watermark.png'); $logoW = ImageSX($logoImage); $logoH = ImageSY($logoImage); ImageCopy($lm, $logoImage, $src_x, $src_y, 0, 0, $logoW, $logoH); } elseif (file_exists('images/watermark_default.png')) { $logoImage = ImageCreateFromPNG('images/watermark_default.png'); $logoW = ImageSX($logoImage); $logoH = ImageSY($logoImage); ImageCopy($lm, $logoImage, $src_x, $src_y, 0, 0, $logoW, $logoH); } } // jpeg quality level- here defined to 80 Imagejpeg($lm, '', 80); imageDestroy($lm);
$content .= '<p><img src="graphs/BarGraphustat.php?userid=' . $user_id . '&t=cfy" border="0" alt="" width="500" height="200" /></p>'; } // Parameter $jpeg_qualitaet = 80; $fontfile = "./lib/fonts/arial.ttf"; $tplpath = 'images/PLmapa.gif'; $im = ImageCreateFromGIF($tplpath); $clrWhite = ImageColorAllocate($im, 255, 255, 255); $clrBorder = ImageColorAllocate($im, 70, 70, 70); $clrBlack = ImageColorAllocate($im, 0, 0, 0); $clrRed = ImageColorAllocate($im, 255, 0, 0); $clrBlue = ImageColorAllocate($im, 0, 0, 255); $fontsize = 18; $wojewodztwa = array('PL11' => array(110, 138), 'PL12' => array(155, 108), 'PL21' => array(135, 208), 'PL22' => array(103, 188), 'PL31' => array(200, 150), 'PL32' => array(180, 200), 'PL33' => array(146, 170), 'PL34' => array(195, 75), 'PL41' => array(65, 115), 'PL42' => array(26, 55), 'PL43' => array(19, 100), 'PL51' => array(35, 149), 'PL52' => array(78, 169), 'PL61' => array(90, 85), 'PL62' => array(145, 50), 'PL63' => array(85, 43)); $wyniki = XDb::xSql("SELECT cache_location.code3 wojewodztwo, COUNT(*) ilosc FROM cache_logs, cache_location\n WHERE cache_logs.user_id= ? AND cache_logs.type='1'\n AND cache_logs.deleted='0'\n AND cache_location.code3 IN ('PL11','PL12','PL21','PL22','PL31','PL32','PL33','PL34','PL41','PL42','PL43','PL51','PL52','PL61','PL62','PL63')\n AND cache_logs.cache_id=cache_location.cache_id\n GROUP BY cache_location.code3", $user_id); while ($wynik = XDb::xFetchArray($wyniki)) { $text = $wynik['ilosc']; if ($text != "0") { ImageTTFText($im, 14, 0, $wojewodztwa[$wynik['wojewodztwo']][0], $wojewodztwa[$wynik['wojewodztwo']][1], $clrBlack, $fontfile, $text); } } // write output Imagejpeg($im, $dynbasepath . 'images/statpics/mapstat' . $user_id . '.jpg', $jpeg_qualitaet); ImageDestroy($im); // generate number for refresh image $rand = rand(); $content .= '<p style="margin-left: 125px;"><img src=/images/statpics/mapstat' . $user_id . '.jpg?rand=' . $rand . ' border="0" alt="" width="250" height="235" /></p>'; tpl_set_var('content', $content); } } tpl_BuildTemplate();
function imageResize() { global $engine_path, $ImageTrimX, $ImageTrimY; $source = $this->image; $newWidth = $this->newWidth; $newHeight = $this->newHeight; $imType = $this->type; if (!$imType || $imType == "jpeg" || $imType == "pjpeg") { $srcImage = ImageCreateFromJPEG($source); } elseif ($imType == "gif") { $srcImage = LoadGif($source); } else { $srcImage = ImageCreateFromPNG($source); } $srcWidth = ImageSX($srcImage); $srcHeight = ImageSY($srcImage); $ratioWidth = $srcWidth / $newWidth; $ratioHeight = $srcHeight / $newHeight; if ($ratioWidth < 1 && $this->fix == "width" || $ratioHeight < 1 && $this->fix == "height") { $destWidth = $srcWidth; $destHeight = $srcHeight; $mode = 1; } elseif ($ratioWidth > $ratioHeight && $newHeight != 120 || $ratioWidth < $ratioHeight && $this->fix != "width" || $this->fix == "height") { $destWidth = $srcWidth / $ratioHeight; $destHeight = $newHeight; $mode = 2; } else { $destWidth = $newWidth; $destHeight = $srcHeight / $ratioWidth; $mode = 3; } //print "$ratioWidth > $ratioHeight) || ( $ratioWidth < $ratioHeight && $this->fix ".$mode; //exit; if ($newWidth != $srcWidth && $newHeight != $srcHeight && $newWidth != 160 && $mode != 1 && $newHeight != 120) { if (!strlen($ImageTrim)) { $ImageTrim = 2; } if ($newy) { $y = $newy; } elseif ($ImageTrimY == 0) { $y = 0; } elseif ($ImageTrimY == 1) { $y = ($newHeight - $destHeight) / 4; } elseif ($ImageTrimY == 2) { $y = ($newHeight - $destHeight) / 2; } elseif ($ImageTrimY == 3) { $y = 3 * ($newHeight - $destHeight) / 2; } elseif ($ImageTrimY == 4) { $y = 5 * ($newHeight - $destHeight) / 2; } if ($newx) { $x = $newx; } elseif ($ImageTrimX == 0) { $x = 0; } elseif ($ImageTrimX == 1) { $x = ($newWidth - $destWidth) / 4; } elseif ($ImageTrimX == 2) { $x = ($newWidth - $destWidth) / 2; } elseif ($ImageTrimX == 3) { $x = 3 * ($newWidth - $destWidth) / 2; } elseif ($ImageTrimX == 4) { $x = 5 * ($newWidth - $destWidth) / 2; } $destImage = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($destImage, $srcImage, $x, $y, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); } else { $destImage = imagecreatetruecolor($destWidth, $destHeight); imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); } $this->newWidth = $destWidth; $this->newHeight = $destHeight; if ($this->mix) { $destImage = $this->mix($destImage); } $name = $engine_path . "tmp/" . $this->name; if (!file_exists($engine_path . "tmp/")) { mkdir_r($engine_path . "tmp/"); } if ($imType == "jpeg" || $imType == "pjpeg") { Imagejpeg($destImage, $name); } elseif ($imType == "gif") { Imagegif($destImage, $name); } else { Imagepng($destImage, $name); } $file['tmp_name'] = $name; ImageDestroy($srcImage); ImageDestroy($destImage); return $file; }
public function createBarCode($image_type = 'jpg', $file_name = null) { $this->parseCode(); //新建一个调色板 $this->image = ImageCreate($this->width + 2 * $this->quiet_zone, $this->heith + $this->font_height); $this->bgcolor = imagecolorallocate($this->image, $this->bgcolor >> 16, $this->bgcolor >> 8 & 0xff, $this->bgcolor & 0xff); $this->color = imagecolorallocate($this->image, $this->color >> 16, $this->color >> 8 & 0xff, $this->color & 0xff); ImageFilledRectangle($this->image, 0, 0, $this->width + 2 * $this->quiet_zone, $this->heith + $this->font_height, $this->bgcolor); $sx = $this->quiet_zone; //$sy = $this->font_height -1; $sy = 0; $fw = 10; //編號為2或3的字體的寬度為10,為4或5的字體寬度為11 if ($this->font_type > 3) { $sy++; $fw = 11; } $ex = 0; //$ey = $this->heith + $this->font_height - 2; $ey = $this->heith; for ($i = 0; $i < strlen($this->bin_code); $i++) { $ex = $sx + $this->unit_width * (int) $this->bin_code[$i] - 1; if ($i % 2 == 0) { ImageFilledRectangle($this->image, $sx, $sy, $ex, $ey, $this->color); } $sx = $ex + 1; } $t_num = strlen($this->text); $t_x = $this->width / $t_num; $t_sx = ($t_x - $fw) / 2; //目的为了使文字居中平均分布 for ($i = 0; $i < $t_num; $i++) { imagechar($this->image, $this->font_type, 6 * $this->unit_width + $t_sx + $i * $t_x, $this->heith, $this->text[$i], $this->color); } if (!$file_name) { header("Content-Type: image/" . $image_type); } switch ($image_type) { case 'jpg': case 'jpeg': return Imagejpeg($this->image, $file_name); break; case 'png': Imagepng($this->image, $file_name); break; case 'gif': break; Imagegif($this->image, $file_name); default: Imagepng($this->image, $file_name); break; } }
fclose($fp); $im = LoadJpeg($savefile); // output $im_width = imageSX($im); $im_height = imageSY($im); // work out new sizes if ($im_width >= $im_height) { $factor = $sz / $im_width; $new_width = $sz; $new_height = $im_height * $factor; } else { $factor = $sz / $im_height; $new_height = $sz; $new_width = $im_width * $factor; } // resize $new_im = ImageCreate($new_width, $new_height); ImageCopyResized($new_im, $im, 0, 0, 0, 0, $new_width, $new_height, $im_width, $im_height); // output Header("Content-type: image/jpeg"); header("Content-Disposition:attachment;filename={$filename}"); header("Content-Description:PHP Generated Image"); Imagejpeg($new_im, '', 75); // quality 75 // cleanup ImageDestroy($im); ImageDestroy($new_im); unlink($savefile); ?>