function MyImageBlur($im, $pct) { // w00t. my very own blur function // in GD2, there's a gaussian blur function. smarmy bastards. ;-) $width = imagesx($im); $height = imagesy($im); $temp_im = ImageCreate($width, $height); $bg = ImageColorAllocate($temp_im, 255, 255, 255); // preserves transparency if in orig image ImageColorTransparent($temp_im, $bg); // fill bg ImageFill($temp_im, 0, 0, $bg); $distance = 1; // emboss: ImageCopyMerge($temp_im, $im, 0, 0, $distance, $distance, $width, $height, $pct); ImageCopyMerge($im, $temp_im, -$distance, -$distance, 0, 0, $width, $height, $pct); ImageFill($temp_im, 0, 0, $bg); ImageCopyMerge($temp_im, $im, 0, $distance, $distance, 0, $width, $height, $pct); ImageCopyMerge($im, $temp_im, $distance, 0, 0, $distance, $width, $height, $pct); // blur: ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, $pct); ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, $pct); ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height, $pct); ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width, $height, $pct); // remove temp image ImageDestroy($temp_im); return $im; }
function JPGText($str, $fontname, $fontsize, $backcol, $txtcol) { global $layout; Header("Last-Modified: " . gmDate("D, d M Y H:i:s", Time()) . " GMT"); Header("Expires: " . gmDate("D, d M Y H:i:s", Time() - 3601) . " GMT"); Header("Pragma: no-cache"); Header("Cache-control: no-cache"); Header("Content-Type: image/jpeg"); $a = ImageTTFBBox($fontsize, 0, $fontname, $str); $width = $a[2] + 4; $bla = get_maximum_height($fontname, $fontsize); $height = $bla[0] + 3; $bl = $bla[1]; $im = ImageCreate($width, $height); $bgcol = ImageColorAllocate($im, $backcol['red'], $backcol['green'], $backcol['blue']); $fgcol = ImageColorAllocate($im, $txtcol['red'], $txtcol['green'], $txtcol['blue']); if (!function_exists(imagegif)) { imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str); imagejpeg($im, "", 80); } else { ImageColorTransparent($im, $bgcol); imageTTFText($im, $fontsize, 0, 2, $bl + $fontsize / 6 + 2, $fgcol, $fontname, $str); imagegif($im); } ImageDestroy($im); }
public static function run($res, $width = NULL, $height = NULL) { $dst_w = Image::width($res); $dst_h = Image::height($res); if (!empty($width) && !empty($height)) { $dst_w = $width; $dst_h = $height; } elseif (empty($height)) { $ratio = $dst_h / $dst_w; $dst_w = $width; $dst_h = round($dst_w * $ratio); } elseif (empty($width)) { $ratio = $dst_w / $dst_h; $dst_h = $height; $dst_w = round($dst_h * $ratio); } $dst = imagecreatetruecolor($dst_w, $dst_h); /* making the new image transparent */ $background = imagecolorallocate($dst, 0, 0, 0); ImageColorTransparent($dst, $background); // make the new temp image all transparent imagealphablending($dst, false); imagesavealpha($dst, true); imageAntiAlias($dst, true); self::__fill($dst); imagecopyresampled($dst, $res, 0, 0, 0, 0, $dst_w, $dst_h, Image::width($res), Image::height($res)); @imagedestroy($res); return $dst; }
function TextToImage($text, $separate_line_after_chars = 40, $size = 24, $rotate = 0, $padding = 2, $transparent = true, $color = array('red' => 0, 'grn' => 0, 'blu' => 0), $bg_color = array('red' => 255, 'grn' => 255, 'blu' => 255)) { $amount_of_lines = ceil(strlen($text) / $separate_line_after_chars); $x = explode("\n", $text); $final = ''; foreach ($x as $key => $value) { $returnes = ''; do { $first_part = mb_substr($value, 0, $separate_line_after_chars, 'utf-8'); $value = "\n" . mb_substr($value, $separate_line_after_chars, null, 'utf-8'); $returnes .= $first_part; } while (mb_strlen($value, 'utf-8') > $separate_line_after_chars); $final .= $returnes . "\n"; } $text = $final; $width = $height = $offset_x = $offset_y = 0; $font = $_SERVER['DOCUMENT_ROOT'] . '/assets/css/journal.ttf'; // get the font height. $bounds = ImageTTFBBox($size, $rotate, $font, "W"); if ($rotate < 0) { $font_height = abs($bounds[7] - $bounds[1]); } elseif ($rotate > 0) { $font_height = abs($bounds[1] - $bounds[7]); } else { $font_height = abs($bounds[7] - $bounds[1]); } // determine bounding box. $bounds = ImageTTFBBox($size, $rotate, $font, $text); if ($rotate < 0) { $width = abs($bounds[4] - $bounds[0]); $height = abs($bounds[3] - $bounds[7]); $offset_y = $font_height; $offset_x = 0; } elseif ($rotate > 0) { $width = abs($bounds[2] - $bounds[6]); $height = abs($bounds[1] - $bounds[5]); $offset_y = abs($bounds[7] - $bounds[5]) + $font_height; $offset_x = abs($bounds[0] - $bounds[6]); } else { $width = abs($bounds[4] - $bounds[6]); $height = abs($bounds[7] - $bounds[1]); $offset_y = $font_height; $offset_x = 0; } $image = imagecreate($width + $padding * 2 + 1, $height + $padding * 2 + 1); $background = ImageColorAllocate($image, $bg_color['red'], $bg_color['grn'], $bg_color['blu']); $foreground = ImageColorAllocate($image, $color['red'], $color['grn'], $color['blu']); if ($transparent) { ImageColorTransparent($image, $background); } ImageInterlace($image, true); // render the image ImageTTFText($image, $size, $rotate, $offset_x + $padding, $offset_y + $padding, $foreground, $font, $text); imagealphablending($image, true); imagesavealpha($image, true); // output PNG object. imagePNG($image, 'signature.png'); imagedestroy($image); }
function show_emptyimg($format = 'gif') { header('Content-Type: image/' . $format); $width = 1; $height = 1; $img = imageCreate($width, $height); //imageFilledRectangle($img, 0, 0, $width, $height, imagecolorallocate($img, 255, 255, 255)); ImageColorTransparent($img, imagecolorallocate($img, 255, 255, 255)); imagegif($img); imagedestroy($img); exit; }
function draw() { $width = 0; $height = 0; $offset_x = 0; $offset_y = 0; $bounds = array(); $image = ""; // get the font height. $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W"); if ($this->rot < 0) { $font_height = abs($bounds[7] - $bounds[1]); } else { if ($this->rot > 0) { $font_height = abs($bounds[1] - $bounds[7]); } else { $font_height = abs($bounds[7] - $bounds[1]); } } // determine bounding box. $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg); if ($this->rot < 0) { $width = abs($bounds[4] - $bounds[0]); $height = abs($bounds[3] - $bounds[7]); $offset_y = $font_height; $offset_x = 0; } else { if ($this->rot > 0) { $width = abs($bounds[2] - $bounds[6]); $height = abs($bounds[1] - $bounds[5]); $offset_y = abs($bounds[7] - $bounds[5]) + $font_height; $offset_x = abs($bounds[0] - $bounds[6]); } else { $width = abs($bounds[4] - $bounds[6]); $height = abs($bounds[7] - $bounds[1]); $offset_y = $font_height; $offset_x = 0; } } $image = imagecreate($width + $this->padX * 2 + 1, $height + $this->padY * 2 + 1); $background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu); $foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu); if ($this->transparent) { ImageColorTransparent($image, $background); } ImageInterlace($image, false); // render the image ImageTTFText($image, $this->size, $this->rot, $offset_x + $this->padX, $offset_y + $this->padY, $foreground, $this->font, $this->msg); // output PNG object. imagePNG($image); }
/** * Create the transparent unitPng and return its URL * * @return string * @access private */ function _unitpng() { if (file_exists($this->_oboxUnitPngPath)) { return $this->_oboxUnitPngURL; } $im = ImageCreate(1, 1); $trans = ImageColorAllocate($im, 128, 128, 128); ImageColorTransparent($im, $trans); ImageFilledRectangle($im, 0, 0, 1, 1, $trans); $this->_makeUnitPngPath(); ImagePNG($im, $this->_oboxUnitPngPath); ImageDestroy($im); return $this->_oboxUnitURL; }
/** * Create the PNG canvas * * @param array $param Parameter array */ function Image_Canvas_GD_PNG($param) { parent::Image_Canvas_GD($param); if (isset($param['transparent']) && $param['transparent'] && $this->_gd2) { if ($param['transparent'] === true) { $transparent = '#123ABD'; } else { $transparent = $param['transparent']; } $color = $this->_color($transparent); $trans = ImageColorTransparent($this->_canvas, $color); $this->rectangle(array('x0' => $this->_left, 'y0' => $this->_top, 'x1' => $this->_left + $this->_width - 1, 'y1' => $this->_top + $this->_height - 1, 'fill' => 'opague', 'line' => 'transparent')); } else { $this->rectangle(array('x0' => $this->_left, 'y0' => $this->_top, 'x1' => $this->_left + $this->_width - 1, 'y1' => $this->_top + $this->_height - 1, 'fill' => 'white', 'line' => 'transparent')); } }
/** * 将图片缩放到指定大小,并保存到指定路径,如果图片类型不支持则直接复制文件 * * @param string $src 源文件的绝对路径 * @param string $dest 目标文件的绝对路径 * @param int $w 目标宽度 * @param int $h 目标高度 */ public static function image_resize($src, $dest, $w, $h) { $img = getimagesize($src); switch ($img[2]) { case 1: $im_in = imagecreatefromgif($src); $im_out = imagecreate($w, $h); $bgcolor = imagecolorallocate($im_out, 0, 0, 0); $bgcolortrans = ImageColorTransparent($im_out, $bgcolor); break; case 2: $im_in = imagecreatefromjpeg($src); $im_out = imagecreatetruecolor($w, $h); break; case 3: $im_in = imagecreatefrompng($src); $im_out = imagecreatetruecolor($w, $h); imagealphablending($im_out, true); imagesavealpha($im_out, true); $trans_colour = imagecolorallocatealpha($im_out, 0, 0, 0, 127); imagefill($im_out, 0, 0, $trans_colour); break; default: copy($src, $dest); } if (!$im_in || !$im_out) { return false; } imagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $w, $h, $img[0], $img[1]); switch ($img[2]) { case 1: imagegif($im_out, $dest); break; case 2: imagejpeg($im_out, $dest); break; case 3: imagepng($im_out, $dest); break; default: return -5; //保存失败 } imagedestroy($im_out); imagedestroy($im_in); }
function myImageBlur($im) { $width = imagesx($im); $height = imagesy($im); $temp_im = ImageCreateTrueColor($width, $height); $bg = ImageColorAllocate($temp_im, 150, 150, 150); // preserves transparency if in orig image ImageColorTransparent($temp_im, $bg); // fill bg ImageFill($temp_im, 0, 0, $bg); $distance = 1; // blur by merging with itself at different x/y offsets: ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height - $distance, 70); ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width - $distance, $height, 70); ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, 70); ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, 70); // remove temp image ImageDestroy($temp_im); return $im; }
function output_png($poll_id, $radius) { if ($radius < 20) { $radius = 90; } $diameter = $radius * 2; $img_size = $diameter + 2; if ($this->is_valid_poll_id($poll_id)) { $img = ImageCreate($img_size, $img_size); for (reset($this->colors); $key = key($this->colors); next($this->colors)) { eval("\$poll_colors[\$key]=ImageColorAllocate(\$img," . $this->colors[$key] . ");"); } ImageFill($img, 0, 0, $poll_colors['blank']); Imagearc($img, $radius, $radius, $diameter, $diameter, 0, 360, $poll_colors['black']); if (!isset($this->options[$poll_id])) { $this->get_poll_data($poll_id); } $totalvotes = $this->options[$poll_id]['total'] == 0 ? 1 : $this->options[$poll_id]['total']; for ($i = 0; $i < sizeof($this->options[$poll_id]['option_id']); $i++) { $img_width = $this->options[$poll_id]['votes'][$i] * 360 / $totalvotes; $end = $this->begin + $img_width; $y1 = sin($end / 180 * M_PI) * $radius; $x1 = cos($end / 180 * M_PI) * $radius; Imageline($img, $radius, $radius, $radius + $x1, $radius + $y1, $poll_colors['black']); $end2 = $this->begin + $img_width * 0.5; $x2 = (int) ($radius + cos($end2 / 180 * M_PI) * 15); $y2 = (int) ($radius + sin($end2 / 180 * M_PI) * 15); Imagefilltoborder($img, $x2, $y2, $poll_colors['black'], $poll_colors[$this->options[$poll_id]['color'][$i]]); $this->begin += $img_width; } $this->begin = 0; ImageColorTransparent($img, $poll_colors['blank']); ImagePNG($img); } else { $loc = "{$pollvars['base_url']}/image/error.png"; header("Location: {$loc}"); exit; } }
function makeBlankImage($width = 4, $height = 7) { //bild generieren $ImageOut = ImageCreate($width, $height); $White = ImageColorAllocate($ImageOut, 255, 255, 255); $FC = $White; $BG = $White; $TC = $BG; ImageColorTransparent($ImageOut, $TC); ImageFill($ImageOut, 0, 0, $BG); Imageinterlace($ImageOut, 1); return $ImageOut; }
/** * 创建头像动态gif缩略图 * @param $imageSource * @param $srcW * @param $srcH * @param $dstW * @param $dstH */ function makeAvatarGifThumb($imageSource, $srcW, $srcH, $dstW, $dstH) { if ($srcW <= $dstW && $srcH <= $dstH) { return $imageSource; } $imageSource = imagecreatefromstring($imageSource); list($imagecreate, $imagecopyre) = GetImageCreate('gif'); if ($srcW / $dstW < $srcH / $dstH) { $finalW = round($dstH / $srcH * $srcW); $finalH = $dstH; } elseif ($srcW / $dstW > $srcH / $dstH) { $finalW = $dstW; $finalH = round($dstW / $srcW * $srcH); } else { $finalW = $dstW; $finalH = $dstH; } $thumb = $imagecreate($finalW, $finalH); if (function_exists('ImageColorAllocate') && function_exists('ImageColorTransparent')) { //背景透明处理 $black = ImageColorAllocate($thumb, 0, 0, 0); $bgTransparent = ImageColorTransparent($thumb, $black); } $imagecopyre($thumb, $imageSource, 0, 0, 0, 0, $finalW, $finalH, $srcW, $srcH); ob_start(); imagegif($thumb); imagedestroy($thumb); $imageStream = ob_get_contents(); ob_end_clean(); return $imageStream; }
/** * Fixes saving PNG alpha channel * * @param resource $imageHandler * @return void */ private function _saveAlpha($imageHandler) { $background = imagecolorallocate($imageHandler, 0, 0, 0); ImageColorTransparent($imageHandler, $background); imagealphablending($imageHandler, false); imagesavealpha($imageHandler, true); }
function _resizeGD($sSrcImage, $sDstImage) { $iErr = 0; $src_im =& $this->_createGDImage($sSrcImage, $size, $iErr); $sizeOrig = $size; if ($iErr) { return $iErr; } if (!$src_im) { return IMAGE_ERROR_GD_OPEN_FAILED; } $xd = $yd = 0; $xs = $ys = 0; if ($this->_isCrop) { $size[0] = $this->_cropW; $size[1] = $this->_cropH; $xs = $this->_cropX; $ys = $this->_cropY; $destW = $this->w; $destH = $this->h; } elseif ($this->_isSquareResize) { $destW = $this->w; $destH = $this->h; if ($size[0] < $size[1]) { $d = ($size[1] - $size[0]) / 2; $size[1] = $size[0]; $xs = 0; $ys = (int) $d; } else { $d = ($size[0] - $size[1]) / 2; $size[0] = $size[1]; $xs = (int) $d; $ys = 0; } } else { // determ destination size $sourceRatio = (double) ($size[0] / $size[1]); $destRatio = (double) ($this->w / $this->h); if ($sourceRatio > $destRatio) { $resizeRatio = (double) ($this->w / $size[0]); } else { $resizeRatio = (double) ($this->h / $size[1]); } $destW = (int) ($resizeRatio * $size[0]); $destH = (int) ($resizeRatio * $size[1]); } // this is more qualitative function, but it doesn't exist in old GD and doesn't support GIF format if (function_exists('imagecreatetruecolor') && $size[2] != IMAGE_TYPE_GIF) { // resize only if size is larger than needed if ($this->_isCrop || $sizeOrig[0] > $this->w || $sizeOrig[1] > $this->h) { $dst_im = imagecreatetruecolor($destW, $destH); imagecolortransparent($dst_im, imagecolorallocate($dst_im, 0, 0, 0)); imagealphablending($dst_im, false); imagesavealpha($dst_im, true); $convertResult = imagecopyresampled($dst_im, $src_im, $xd, $yd, $xs, $ys, $destW, $destH, $size[0], $size[1]); } else { $dst_im = $src_im; $convertResult = true; } } else { // this is for old GD versions and for GIF images // resize only if size is larger than needed if ($size[0] > $this->w || $size[1] > $this->h) { $dst_im = imagecreate($destW, $destH); if ($size[2] == IMAGE_TYPE_GIF) { ImageColorTransparent($dst_im, imagecolorallocate($dst_im, 0, 0, 0)); imagealphablending($dst_im, false); } $convertResult = imagecopyresized($dst_im, $src_im, $xd, $yd, $xs, $ys, $destW, $destH, $size[0], $size[1]); } else { $dst_im = $src_im; $convertResult = true; } } if (!$convertResult) { return IMAGE_ERROR_GD_RESIZE_ERROR; } // if output always in JPG if ($forceJPGOutput) { $writeResult = imagejpeg($dst_im, $sDstImage, $this->_iJpegQuality); } else { // otherwise switch ($size[2]) { case IMAGE_TYPE_GIF: $writeResult = imagegif($dst_im, $sDstImage); break; case IMAGE_TYPE_JPG: $writeResult = imagejpeg($dst_im, $sDstImage, $this->_iJpegQuality); break; case IMAGE_TYPE_PNG: $writeResult = imagepng($dst_im, $sDstImage); break; } } // free memory if ($dst_im != $src_im) { imagedestroy($src_im); imagedestroy($dst_im); } else { imagedestroy($src_im); } if ($writeResult && file_exists($sDstImage)) { return IMAGE_ERROR_SUCCESS; } return IMAGE_ERROR_GD_WRITE_FAILED; }
/** * Get the color index for the RGB color * * @param int $color The color * @return int The GD image index of the color * @access private */ function _color($color = false) { if ($color === false || $color === 'opague' || $color === 'transparent') { return ImageColorTransparent($this->_canvas); } else { return Image_Canvas_Color::allocateColor($this->_canvas, $color); } }
/** * Faster method than only calling imagecopyresampled() * * @return boolean Success/fail */ function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $system, $quality = 3) { /* Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example 1.5. 1 = Up to 600 times faster. Poor results, just uses imagecopyresized but removes black edges. 2 = Up to 95 times faster. Images may appear too sharp, some people may prefer it. 3 = Up to 60 times faster. Will give high quality smooth results very close to imagecopyresampled. 4 = Up to 25 times faster. Almost identical to imagecopyresampled for most images. 5 = No speedup. Just uses imagecopyresampled, highest quality but no advantage over imagecopyresampled. */ if (empty($src_image) || empty($dst_image) || $quality <= 0) { return false; } if (preg_match("/png/", $system[0]) || preg_match("/gif/", $system[0])) { $colorcount = imagecolorstotal($src_image); if ($colorcount <= 256 && $colorcount != 0) { imagetruecolortopalette($dst_image, true, $colorcount); imagepalettecopy($dst_image, $src_image); $transparentcolor = imagecolortransparent($src_image); imagefill($dst_image, 0, 0, $transparentcolor); imagecolortransparent($dst_image, $transparentcolor); } else { imageAlphaBlending($dst_image, false); imageSaveAlpha($dst_image, true); //If the image has Alpha blending, lets save it } } if ($quality < 5 && ($dst_w * $quality < $src_w || $dst_h * $quality < $src_h)) { $temp = imagecreatetruecolor($dst_w * $quality + 1, $dst_h * $quality + 1); if (preg_match("/png/", $system[0])) { $background = imagecolorallocate($temp, 0, 0, 0); ImageColorTransparent($temp, $background); // make the new temp image all transparent imagealphablending($temp, false); // turn off the alpha blending to keep the alpha channel } imagecopyresized($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h * $quality + 1, $src_w, $src_h); imagecopyresampled($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality, $dst_h * $quality); imagedestroy($temp); } else { imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } return true; }
function ImageRoundEdges($image, $size, $args = array()){ if (!is_numeric($size)){ throw new Exception("Not a valid size: " . $size); } $width = ImageSX($image); $height = ImageSY($image); if ($args["border"]){ $bordercolor = ImageHTMLColor($image, $args["border"]); $oldimage = $image; $image = ImageCreateTrueColor($width, $height); ImageFilledRectangle($image, 0, 0, $width, $height, $bordercolor); ImageCopyResized($image, $oldimage, 1, 1, 0, 0, $width - 2, $height - 2, $width, $height); }else{ $oldimage = $image; $image = ImageCreateTrueColor($width, $height); ImageCopyResized($image, $oldimage, 0, 0, 0, 0, $width, $height, $width, $height); } $transp = ImageColorTransparent($image); if (!$transp or $transp == -1){ if ($args["htmltranscolor"]){ $transp = ImageHTMLColor($image, $args["htmltranscolor"]); }else{ $transp = ImageHTMLColor($image, "#d91da2"); } } for($i = 1; $i < $size / 2; $i++){ //Upper left corner. $center = $i - 2; ImageArc($image, $center, $center, $size, $size, 180, 270, $white); ImageArc($image, $center - 1, $center, $size, $size, 180, 270, $white); ImageArc($image, $center, $center, $size, $size, 180, 270, $transp); ImageArc($image, $center - 1, $center, $size, $size, 180, 270, $transp); //Upper right corner. $left = $width - $i + 2; $top = $i - 2; ImageArc($image, $left, $top, $size, $size, 270, 360, $transp); ImageArc($image, $left, $top - 1, $size, $size, 270, 360, $transp); //Lower left corner. $left = $i - 2; $top = $height - $i + 2; ImageArc($image, $left, $top, $size, $size, 90, 180, $transp); ImageArc($image, $left, $top - 1, $size, $size, 90, 180, $transp); //Lower right corner. $left = $width - $i + 2; $top = $height - $i + 2; ImageArc($image, $left, $top, $size, $size, 0, 90, $transp); ImageArc($image, $left, $top - 1, $size, $size, 0, 90, $transp); } if ($args["border"]){ //Lower right corner. $left = $width - $i + 2; $top = $height - $i + 2; ImageArc($image, $left, $top, $size, $size, 0, 90, $bordercolor); //Lower left corn $left = $i - 2; $top = $height - $i + 2; ImageArc($image, $left, $top, $size, $size, 90, 180, $bordercolor); //Upper left corner. $center = $i - 2; ImageArc($image, $center, $center - 1, $size, $size, 180, 270, $bordercolor); //Upper right corner. $left = $width - $i + 2; $top = $i - 2; ImageArc($image, $left, $top - 1, $size, $size, 270, 360, $bordercolor); } ImageColorTransparent($image, $transp); return $image; }
function SetTransparentColor($which_color) { ImageColorTransparent($this->img, $this->SetIndexColor($which_color)); return TRUE; }
function SetTransparentColor($which_color) { $ndx = $this->SetIndexColor($which_color); if (!isset($ndx)) { return FALSE; } ImageColorTransparent($this->img, $ndx); return TRUE; }
public function _AutoGenerateInsThumb($ImageName, $Size = "thumb", $OverrideExisting = false) { // Takes the filename of an image already uploaded into the // image directory, generates a thumbnal from it, stores it // in the image directory and returns its name $imgFile = realpath(ISC_BASE_PATH . "/install_images"); $imgFile .= "/" . $ImageName; if ($ImageName == '' || !file_exists($imgFile)) { return false; } // A list of thumbnails too $tmp = explode(".", $imgFile); $ext = isc_strtolower($tmp[count($tmp) - 1]); // If overriding the existing image, set the output filename to the input filename //Large and medium size images by Simha if ($Size == 'large') { $thumbFileName = $ImageName; } else { if ($Size == 'medium') { $thumbFileName = GenRandFileName($ImageName, $Size); } else { if ($OverrideExisting == true) { $thumbFileName = $ImageName; } else { $thumbFileName = GenRandFileName($ImageName, $Size); } } } $attribs = @getimagesize($imgFile); $width = $attribs[0]; $height = $attribs[1]; if (!is_array($attribs)) { return false; } // Check if we have enough available memory to create this image - if we don't, attempt to bump it up setImageFileMemLimit($imgFile); $thumbFile = realpath(ISC_BASE_PATH . "/install_images"); $thumbFile .= "/" . $thumbFileName; if ($ext == "jpg") { $srcImg = @imagecreatefromjpeg($imgFile); } else { if ($ext == "gif") { $srcImg = @imagecreatefromgif($imgFile); if (!function_exists("imagegif")) { $gifHack = 1; } } else { $srcImg = @imagecreatefrompng($imgFile); } } if (!$srcImg) { return false; } $srcWidth = @imagesx($srcImg); $srcHeight = @imagesy($srcImg); //Large and medium size images by Simha if ($Size == 'large') { $AutoThumbSize = 800; } else { if ($Size == 'medium') { $AutoThumbSize = 70; } else { if ($Size == "tiny") { $AutoThumbSize = ISC_TINY_THUMB_SIZE; } else { $AutoThumbSize = GetConfig('AutoThumbSize'); } } } // This thumbnail is smaller than the Interspire Shopping Cart dimensions, simply copy the image and return if ($srcWidth <= $AutoThumbSize && $srcHeight <= $AutoThumbSize) { @imagedestroy($srcImg); if ($OverrideExisting == false) { @copy($imgFile, $thumbFile); } return $thumbFileName; } // Make sure the thumb has a constant height $thumbWidth = $width; $thumbHeight = $height; if ($width > $AutoThumbSize) { $thumbWidth = $AutoThumbSize; $thumbHeight = ceil($height * ($AutoThumbSize * 100 / $width) / 100); $height = $thumbHeight; $width = $thumbWidth; } if ($height > $AutoThumbSize) { $thumbHeight = $AutoThumbSize; $thumbWidth = ceil($width * ($AutoThumbSize * 100 / $height) / 100); } $thumbImage = @imagecreatetruecolor($thumbWidth, $thumbHeight); if ($ext == "gif" && !isset($gifHack)) { $colorTransparent = @imagecolortransparent($srcImg); @imagepalettecopy($srcImg, $thumbImage); @imagecolortransparent($thumbImage, $colorTransparent); @imagetruecolortopalette($thumbImage, true, 256); } else { if ($ext == "png") { @ImageColorTransparent($thumbImage, @ImageColorAllocate($thumbImage, 0, 0, 0)); @ImageAlphaBlending($thumbImage, false); } } @imagecopyresampled($thumbImage, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight); if ($ext == "jpg") { @imagejpeg($thumbImage, $thumbFile, 100); } else { if ($ext == "gif") { if (isset($gifHack) && $gifHack == true) { $thumbFile = isc_substr($thumbFile, 0, -3) . "jpg"; @imagejpeg($thumbImage, $thumbFile, 100); } else { @imagegif($thumbImage, $thumbFile); } } else { @imagepng($thumbImage, $thumbFile); } } @imagedestroy($thumbImage); @imagedestroy($srcImg); // Change the permissions on the thumbnail file isc_chmod($thumbFile, ISC_WRITEABLE_FILE_PERM); return $thumbFileName; }
<?php if (!$size > 0) { $size = 300; } $radius = floor($size / 2); header("content-Type: image/gif"); $img = ImageCreate($size, $size); $color_alpha = ImageColorAllocate($img, 254, 254, 254); $color_white = ImageColorAllocate($img, 255, 255, 255); $color_black = ImageColorAllocate($img, 0, 0, 0); $color_grey = ImageColorAllocate($img, 192, 192, 192); $color_red = ImageColorAllocate($img, 255, 0, 0); $color_blue = ImageColorAllocate($img, 0, 0, 255); ImageColorTransparent($img, $color_alpha); ImageArc($img, $radius, $radius, $size, $size, 0, 360, $color_black); ImageFill($img, $radius, $radius, $color_white); $min = 0; while ($min++ < 0) { if ($min % 15 == 0) { $len = $radius / 5; } else { if ($min % 5 == 0) { $len = $radius / 10; } else { $len = $radius / 25; } } $ang = 2 * M_PI * $min / 60; $x1 = sin($ang) * ($radius - $len) + $radius; $y1 = cos($ang) * ($radius - $len) + $radius;
$rgb = imagecolorat($im_base, $x, $y); $r = $rgb >> 16; $g = $rgb >> 8 & 255; $b = $rgb & 255; if ($r == $rf and $g == $gf and $b == $bf) { imagesetpixel($im_base, $x, $y, $background); } } } } /** * Step 5: resize if needed */ if ($size) { $width = imagesx($im_base); $height = imagesy($im_base); $w = $width * $size; $h = $height * $size; $im = imagecreatetruecolor($w, $h); $background = imagecolorallocate($im, 254, 0, 0); ImageColorTransparent($im, $background); // make the new temp image all transparent /* making the new image transparent */ imagealphablending($im, false); // turn off the alpha blending to keep the alpha channel imagesavealpha($im, true); imagecopyresampled($im, $im_base, 0, 0, 0, 0, $w, $h, $width, $height); ImageDestroy($im_base); } else { $im = $im_base; }
$xsize = 420; $ysize = 400; $dx = 24; $dy = 45; $xstep = 12; $ystep = 30; //строим изображение Header ("Content-Type: image/png"); $im = ImageCreate ($xsize, $ysize); $white = ImageColorAllocate($im, 255, 255, 255); //цвет фона $black = ImageColorAllocate($im, 0, 0, 0); $silver = ImageColorAllocate($im, 205, 205, 205); $gray = ImageColorAllocate($im, 135, 135, 135); ImageColorTransparent($im, $white); //ImageTTFText($im, 16, 0, 40, 50, $black, "arialbd.ttf", $max); //делаем разметку по ox for ($i=0; $i<32; $i++) { imageline($im, $i*$xstep + $dx, $dy + 10, $i*$xstep + $dx, $ysize-$dy, $silver); if (($i % 5) == 0) { imageline($im, $i*$xstep + $dx, $dy + 10, $i*$xstep + $dx, $ysize-$dy, $gray); $mydate = ($timenow - 86400*31) + $i * 86400; $mydate = date("m.d", $mydate); imageString($im, 1, $i*$xstep + $dx, $ysize - $dy + 12, $mydate, $black); } }
/** * Generate a thumbnail version of a particular image. * * @param string The file system path of the image to create a thumbnail of. * @param string The file system path of the name/location to save the thumbnail. * @param int The maximum width of the image. * @param boolean If the image is small enough, copy it to destLocation, otherwise just return. */ function GenerateThumbnail($sourceLocation, $destLocation, $maxWidth, $maxHeight = null) { if (is_null($maxHeight)) { $maxHeight = $maxWidth; } if ($sourceLocation == '' || !file_exists($sourceLocation)) { return false; } else { if (!is_dir(dirname($destLocation)) || !is_writable(dirname($destLocation))) { return false; } } // A list of thumbnails too $tmp = explode(".", $sourceLocation); $ext = isc_strtolower($tmp[count($tmp) - 1]); $attribs = @getimagesize($sourceLocation); $srcWidth = $attribs[0]; $srcHeight = $attribs[1]; if (!is_array($attribs)) { return false; } // Check if we have enough available memory to create this image - if we don't, attempt to bump it up SetImageFileMemLimit($sourceLocation); if ($ext == "jpg") { $srcImg = @imagecreatefromjpeg($sourceLocation); } else { if ($ext == "gif") { $srcImg = @imagecreatefromgif($sourceLocation); if (!function_exists("imagegif")) { $gifHack = 1; } } else { $srcImg = @imagecreatefrompng($sourceLocation); } } if (!$srcImg) { return false; } // This image dimensions. Simply copy and return if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { @imagedestroy($srcImg); if ($sourceLocation != $destLocation && copy($sourceLocation, $destLocation)) { return true; } } // Make sure the thumb has a constant height $width = $srcWidth; $thumbWidth = $srcWidth; $height = $srcHeight; $thumbHeight = $srcHeight; if ($width > $maxWidth) { $thumbWidth = $maxWidth; $thumbHeight = $maxWidth / $srcWidth * $srcHeight; } else { $thumbHeight = $maxHeight; $thumbWidth = $maxHeight / $srcHeight * $srcWidth; } $thumbImage = @imagecreatetruecolor($thumbWidth, $thumbHeight); if ($ext == "gif" && !isset($gifHack)) { $colorTransparent = @imagecolortransparent($srcImg); @imagepalettecopy($srcImg, $thumbImage); @imagecolortransparent($thumbImage, $colorTransparent); @imagetruecolortopalette($thumbImage, true, 256); } else { if ($ext == "png") { @ImageColorTransparent($thumbImage, @ImageColorAllocate($thumbImage, 0, 0, 0)); @ImageAlphaBlending($thumbImage, false); } } @imagecopyresampled($thumbImage, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight); if ($ext == "jpg") { @imagejpeg($thumbImage, $destLocation, 100); } else { if ($ext == "gif") { if (isset($gifHack) && $gifHack == true) { $thumbFile = isc_substr($thumbFile, 0, -3) . "jpg"; @imagejpeg($thumbImage, $destLocation, 100); } else { @imagegif($thumbImage, $destLocation); } } else { @imagepng($thumbImage, $destLocation); } } @imagedestroy($thumbImage); @imagedestroy($srcImg); // Change the permissions on the thumbnail file isc_chmod($destLocation, ISC_WRITEABLE_FILE_PERM); return true; }
private function _create($file1, $file2) { $image1 = $this->_create_image($file1); if (!$image1) { return false; } $image2 = $this->_create_image($file2); if (!$image2) { return false; } $imageWidth1 = imagesx($image1); $imageWidth2 = imagesx($image2); $imageHeight1 = imagesy($image1); $imageHeight2 = imagesy($image2); $width = $imageWidth1 > $imageWidth2 ? $imageWidth1 : $imageWidth2; $height = $imageHeight1 + $imageHeight2; $image = imagecreatetruecolor($width, $height); $bgcolor = ImageColorAllocate($image, 0, 0, 0); $bgcolor = ImageColorTransparent($image, $bgcolor); if (!imagecopymerge($image, $image1, 0, 0, 0, 0, $imageWidth1, $imageHeight1, 100)) { return false; } if (!imagecopymerge($image, $image2, 0, $imageHeight1, 0, 0, $imageWidth2, $imageHeight2, 100)) { return false; } imagedestroy($image1); imagedestroy($image2); return $image; }
public static function ImprovedImageRotate(&$gdimg_source, $rotate_angle = 0, $config_background_hexcolor = 'FFFFFF', $bg = null, &$phpThumbObject) { while ($rotate_angle < 0) { $rotate_angle += 360; } $rotate_angle = $rotate_angle % 360; if ($rotate_angle != 0) { $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_source, $config_background_hexcolor); if (phpthumb_functions::gd_version() >= 2 && !$bg && $rotate_angle % 90) { //$this->DebugMessage('Using alpha rotate', __FILE__, __LINE__); if ($gdimg_rotate_mask = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg_source), ImageSY($gdimg_source))) { for ($i = 0; $i <= 255; $i++) { $color_mask[$i] = ImageColorAllocate($gdimg_rotate_mask, $i, $i, $i); } ImageFilledRectangle($gdimg_rotate_mask, 0, 0, ImageSX($gdimg_rotate_mask), ImageSY($gdimg_rotate_mask), $color_mask[255]); $imageX = ImageSX($gdimg_source); $imageY = ImageSY($gdimg_source); for ($x = 0; $x < $imageX; $x++) { for ($y = 0; $y < $imageY; $y++) { $pixelcolor = phpthumb_functions::GetPixelColor($gdimg_source, $x, $y); ImageSetPixel($gdimg_rotate_mask, $x, $y, $color_mask[255 - round($pixelcolor['alpha'] * 255 / 127)]); } } $gdimg_rotate_mask = ImageRotate($gdimg_rotate_mask, $rotate_angle, $color_mask[0]); $gdimg_source = ImageRotate($gdimg_source, $rotate_angle, $background_color); ImageAlphaBlending($gdimg_source, false); ImageSaveAlpha($gdimg_source, true); //$this->is_alpha = true; $phpThumbFilters = new phpthumb_filters(); //$phpThumbFilters->phpThumbObject = $this; $phpThumbFilters->phpThumbObject = $phpThumbObject; $phpThumbFilters->ApplyMask($gdimg_rotate_mask, $gdimg_source); ImageDestroy($gdimg_rotate_mask); } else { //$this->DebugMessage('ImageCreateFunction() failed', __FILE__, __LINE__); } } else { if (phpthumb_functions::gd_version() < 2) { //$this->DebugMessage('Using non-alpha rotate because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__); } elseif ($bg) { //$this->DebugMessage('Using non-alpha rotate because $this->bg is "'.$bg.'"', __FILE__, __LINE__); } elseif ($rotate_angle % 90) { //$this->DebugMessage('Using non-alpha rotate because ($rotate_angle % 90) = "'.($rotate_angle % 90).'"', __FILE__, __LINE__); } else { //$this->DebugMessage('Using non-alpha rotate because $this->thumbnailFormat is "'.$this->thumbnailFormat.'"', __FILE__, __LINE__); } if (ImageColorTransparent($gdimg_source) >= 0) { // ImageRotate() forgets all about an image's transparency and sets the transparent color to black // To compensate, flood-fill the transparent color of the source image with the specified background color first // then rotate and the colors should match if (!function_exists('ImageIsTrueColor') || !ImageIsTrueColor($gdimg_source)) { // convert paletted image to true-color before rotating to prevent nasty aliasing artifacts //$this->source_width = ImageSX($gdimg_source); //$this->source_height = ImageSY($gdimg_source); $gdimg_newsrc = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg_source), ImageSY($gdimg_source)); $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $config_background_hexcolor); ImageFilledRectangle($gdimg_newsrc, 0, 0, ImageSX($gdimg_source), ImageSY($gdimg_source), phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $config_background_hexcolor)); ImageCopy($gdimg_newsrc, $gdimg_source, 0, 0, 0, 0, ImageSX($gdimg_source), ImageSY($gdimg_source)); ImageDestroy($gdimg_source); unset($gdimg_source); $gdimg_source = $gdimg_newsrc; unset($gdimg_newsrc); } else { ImageColorSet($gdimg_source, ImageColorTransparent($gdimg_source), hexdec(substr($config_background_hexcolor, 0, 2)), hexdec(substr($config_background_hexcolor, 2, 2)), hexdec(substr($config_background_hexcolor, 4, 2))); ImageColorTransparent($gdimg_source, -1); } } $gdimg_source = ImageRotate($gdimg_source, $rotate_angle, $background_color); } } return true; }
private function SaveQValueAssociationImage() { if (!array_key_exists('associationimage', $_FILES) || $_FILES['associationimage']['error'] !== 0 || strtolower(substr($_FILES['associationimage']['type'], 0, 6)) !== 'image/') { return false; } // Attempt to set the memory limit setImageFileMemLimit($_FILES['associationimage']['tmp_name']); // Generate the destination path $randomDir = strtolower(chr(rand(65, 90))); $destPath = realpath(ISC_BASE_PATH . '/' . GetConfig('ImageDirectory')); if (!is_dir($destPath . '/' . $randomDir)) { if (!@mkdir($destPath . '/' . $randomDir, 0777)) { $randomDir = ''; } } $destFile = GenRandFileName($_FILES['associationimage']['name'], 'category'); $destPath = $destPath . '/' . $randomDir . '/' . $destFile; $returnPath = $randomDir . '/' . $destFile; $tmp = explode('.', $_FILES['associationimage']['name']); $ext = strtolower($tmp[count($tmp) - 1]); if ($ext == 'jpg') { $srcImg = imagecreatefromjpeg($_FILES['associationimage']['tmp_name']); } else { if ($ext == 'gif') { $srcImg = imagecreatefromgif($_FILES['associationimage']['tmp_name']); if (!function_exists('imagegif')) { $gifHack = 1; } } else { $srcImg = imagecreatefrompng($_FILES['associationimage']['tmp_name']); } } $srcWidth = imagesx($srcImg); $srcHeight = imagesy($srcImg); $widthLimit = GetConfig('BrandImageWidth'); $heightLimit = GetConfig('BrandImageHeight'); // If the image is small enough, simply move it and leave it as is if ($srcWidth <= $widthLimit && $srcHeight <= $heightLimit) { imagedestroy($srcImg); move_uploaded_file($_FILES['associationimage']['tmp_name'], $destPath); return $returnPath; } // Otherwise, the image needs to be resized $attribs = getimagesize($_FILES['associationimage']['tmp_name']); $width = $attribs[0]; $height = $attribs[1]; if ($width > $widthLimit) { $height = ceil($widthLimit / $width * $height); $width = $widthLimit; } if ($height > $heightLimit) { $width = ceil($heightLimit / $height * $width); $height = $heightLimit; } $dstImg = imagecreatetruecolor($width, $height); if ($ext == "gif" && !isset($gifHack)) { $colorTransparent = imagecolortransparent($srcImg); imagepalettecopy($srcImg, $dstImg); imagecolortransparent($dstImg, $colorTransparent); imagetruecolortopalette($dstImg, true, 256); } else { if ($ext == "png") { ImageColorTransparent($dstImg, ImageColorAllocate($dstImg, 0, 0, 0)); ImageAlphaBlending($dstImg, false); } } imagecopyresampled($dstImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight); if ($ext == "jpg") { imagejpeg($dstImg, $destPath, 100); } else { if ($ext == "gif") { if (isset($gifHack) && $gifHack == true) { $thumbFile = isc_substr($destPath, 0, -3) . "jpg"; imagejpeg($dstImg, $destPath, 100); } else { imagegif($dstImg, $destPath); } } else { imagepng($dstImg, $destPath); } } @imagedestroy($dstImg); @imagedestroy($srcImg); @unlink($_FILES['associationimage']['tmp_name']); // Change the permissions on the thumbnail file isc_chmod($returnPath, ISC_WRITEABLE_FILE_PERM); return $returnPath; }
/** * resizeImage * * @param string $path, * @param string $resWidth * @param string $resHeight * @param string $saveTo default value null * * @return void */ public function resizeImage($path, $resWidth, $resHeight, $saveTo = null) { $imageInfo = @getimagesize($path); if (!$imageInfo) { throw new Exception("Could not get image information"); } list($width, $height) = $imageInfo; $percentHeight = $resHeight / $height; $percentWidth = $resWidth / $width; $percent = $percentWidth < $percentHeight ? $percentWidth : $percentHeight; $resWidth = $width * $percent; $resHeight = $height * $percent; // Resample $image_p = imagecreatetruecolor($resWidth, $resHeight); imagealphablending($image_p, false); imagesavealpha($image_p, true); $background = imagecolorallocate($image_p, 0, 0, 0); ImageColorTransparent($image_p, $background); // make the new temp image all transparent //Assume 3 channels if we can't find that information if (!array_key_exists("channels", $imageInfo)) { $imageInfo["channels"] = 3; } $memoryNeeded = Round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] + Pow(2, 16)) * 1.95) / (1024 * 1024); if ($memoryNeeded < 80) { $memoryNeeded = 80; } ini_set('memory_limit', intval($memoryNeeded) . 'M'); $functions = array(IMAGETYPE_GIF => array('imagecreatefromgif', 'imagegif'), IMAGETYPE_JPEG => array('imagecreatefromjpeg', 'imagejpeg'), IMAGETYPE_PNG => array('imagecreatefrompng', 'imagepng')); if (!array_key_exists($imageInfo[2], $functions)) { throw new Exception("Image format not supported"); } list($inputFn, $outputFn) = $functions[$imageInfo[2]]; $image = $inputFn($path); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $resWidth, $resHeight, $width, $height); $outputFn($image_p, $saveTo); if (!is_null($saveTo)) { G::LoadSystem('inputfilter'); $filter = new InputFilter(); $saveTo = $filter->validateInput($saveTo, "path"); } @chmod($saveTo, 0666); }
function draw() { putenv('GDFONTPATH=' . APPLICATION_PATH . '/../library/fonts'); $width = 0; $height = 0; $offset_x = 0; $offset_y = 0; $bounds = array(); $image = ""; $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W"); if ($this->rot < 0) { $font_height = abs($bounds[7] - $bounds[1]); } else { if ($this->rot > 0) { $font_height = abs($bounds[1] - $bounds[7]); } else { $font_height = abs($bounds[7] - $bounds[1]); } } $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg); if ($this->rot < 0) { $width = abs($bounds[4] - $bounds[0]); $height = abs($bounds[3] - $bounds[7]); $offset_y = $font_height; $offset_x = 0; } else { if ($this->rot > 0) { $width = abs($bounds[2] - $bounds[6]); $height = abs($bounds[1] - $bounds[5]); $offset_y = abs($bounds[7] - $bounds[5]) + $font_height; $offset_x = abs($bounds[0] - $bounds[6]); } else { $width = abs($bounds[4] - $bounds[6]); $height = abs($bounds[7] - $bounds[1]); $offset_y = $font_height; $offset_x = 0; } } $image = imagecreate($width + $this->pad * 2 + 1, $height + $this->pad * 2 + 1); $background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu); $foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu); if ($this->transparent) { ImageColorTransparent($image, $background); } ImageInterlace($image, false); ImageTTFText($image, $this->size, $this->rot, $offset_x + $this->pad, $offset_y + $this->pad, $foreground, $this->font, $this->msg); imagePNG($image); }