function draw_heatmap($image, &$clicks)
{
    if (function_exists('imageantialias')) {
        // Only available with compiled in version of GD
        imageantialias($image, true);
    }
    // Heatmap colors
    $blue = imagecolorallocate($image, 0, 0, 255);
    $lightblue = imagecolorallocate($image, 0, 63, 255);
    $seagreen = imagecolorallocate($image, 32, 178, 170);
    $greenyellow = imagecolorallocate($image, 173, 255, 47);
    $yellow = imagecolorallocate($image, 255, 255, 0);
    $orange = imagecolorallocate($image, 255, 165, 0);
    $orangered = imagecolorallocate($image, 255, 69, 0);
    $red = imagecolorallocate($image, 255, 0, 0);
    $pointsize = 40;
    colorcircle($image, &$clicks, $click, 10, $pointsize, $blue);
    colorcircle($image, &$clicks, $click, 15, $pointsize, $lightblue);
    colorcircle($image, &$clicks, $click, 20, $pointsize, $seagreen);
    colorcircle($image, &$clicks, $click, 25, $pointsize, $greenyellow);
    colorcircle($image, &$clicks, $click, 30, $pointsize, $yellow);
    colorcircle($image, &$clicks, $click, 35, $pointsize, $orange);
    colorcircle($image, &$clicks, $click, 40, $pointsize, $red);
    return true;
}
 public function output_image($size = null)
 {
     if ($size != null) {
         $this->width = intval($size);
         $this->height = intval($size);
     }
     header("Content-type: image/{$this->imagetype_extension}");
     header("Content-disposition: inline; filename={$this->imagename}");
     $this->image = @imagecreatetruecolor($this->width + 1, $this->height + 1) or die("Could not create new Image!");
     imageantialias($this->image, true);
     $background = imagecolorallocate($this->image, 255, 255, 255);
     imagefill($this->image, 0, 0, $background);
     $max = 1000;
     $start = 40;
     $increment = 0;
     foreach ($this->lines as $line) {
         if ($increment >= $start and $increment < $max or true) {
             $this->drawcrease($line);
         }
         $increment++;
     }
     $f = $this->imagefunction;
     $f($this->image);
     // !
     imagedestroy($this->image);
 }
예제 #3
0
파일: Images.php 프로젝트: rendix2/QW_MVS
 public function antialias($enable = TRUE)
 {
     if (!Validator::isBool($enable)) {
         throw new IllegalArgumentException();
     }
     return imageantialias($this->imageResource, $enable);
 }
 function build($margin = 2, $bg = 'ffffff', $fg = '000000')
 {
     $TextBoxSize = $this->imagettfbbox($this->size, $this->angle, $this->font, preg_replace("/\\[nl\\]/is", "\r\n", $this->text));
     $TxtBx_Lwr_L_x = $TextBoxSize[0];
     $TxtBx_Lwr_L_y = $TextBoxSize[1];
     $TxtBx_Lwr_R_x = $TextBoxSize[2];
     $TxtBx_Lwr_R_y = $TextBoxSize[3];
     $TxtBx_Upr_R_x = $TextBoxSize[4];
     $TxtBx_Upr_R_y = $TextBoxSize[5];
     $TxtBx_Upr_L_x = $TextBoxSize[6];
     $TxtBx_Upr_L_y = $TextBoxSize[7];
     if ($this->angle <= 90 || $this->angle >= 270) {
         $width = max($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x) - min($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x);
         $height = max($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y) - min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
         $x = -min($TxtBx_Upr_L_x, $TxtBx_Lwr_L_x);
         $y = -min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     } else {
         $width = max($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x) - min($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x);
         $height = max($TxtBx_Upr_R_y, $TxtBx_Upr_L_y) - min($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y);
         $x = -min($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x);
         $y = -min($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y);
     }
     $this->img = imagecreate($width + $margin, $height + $margin);
     // Only PHP-Version 4.3.2 or higher
     if (function_exists('imageantialias')) {
         imageantialias($this->img, true);
     }
     $bgc = $this->imagecolorallocate($bg);
     $fgc = $this->imagecolorallocate($fg);
     imagefill($this->img, 0, 0, $bgc);
     imagecolortransparent($this->img, $bgc);
     imagettftext($this->img, $this->size, $this->angle, $x + ceil($margin / 2), $y + ceil($margin / 2), $fgc, $this->font, preg_replace("/\\[nl\\]/is", "\r\n", $this->text));
 }
 function create_error($text)
 {
     $text = $text;
     $size = "8";
     $font = "classes/fonts/trebuchet.ttf";
     $TextBoxSize = imagettfbbox($size, 0, $font, preg_replace("/\\[br\\]/is", "\r\n", $text));
     $TxtBx_Lwr_L_x = $TextBoxSize[0];
     $TxtBx_Lwr_L_y = $TextBoxSize[1];
     $TxtBx_Lwr_R_x = $TextBoxSize[2];
     $TxtBx_Lwr_R_y = $TextBoxSize[3];
     $TxtBx_Upr_R_x = $TextBoxSize[4];
     $TxtBx_Upr_R_y = $TextBoxSize[5];
     $TxtBx_Upr_L_x = $TextBoxSize[6];
     $TxtBx_Upr_L_y = $TextBoxSize[7];
     $width = max($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x) - min($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x);
     $height = max($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y) - min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $x = -min($TxtBx_Upr_L_x, $TxtBx_Lwr_L_x);
     $y = -min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $img = imagecreate($width + 2, $height + 1);
     // Only PHP-Version 4.3.2 or higher
     if (function_exists('imageantialias')) {
         imageantialias($img, FALSE);
     }
     $white = imagecolorallocate($img, 255, 255, 255);
     $black = imagecolorallocate($img, 0, 0, 0);
     imagecolortransparent($img, $white);
     ImageTTFText($img, $size, 0, $x, $y, $black, $font, preg_replace("/<br>/is", "\r\n", $text));
     header("Content-Type: image/png");
     ImagePNG($img);
     ImageDestroy($img);
     exit;
 }
예제 #6
0
 /**
  * 输出图片
  * 
  * @param  string $size     [description]
  * @param  string $bgcolor  [description]
  * @param  string $color    [description]
  * @param  string $text     [description]
  * @param  [type] $fontsize [description]
  * @return [type]           [description]
  */
 public function index($size = '100x100', $bgcolor = 'ccc', $color = '555', $text = '', $fontsize = NULL)
 {
     $cache_filepath = storage_path('placeholders/' . md5(serialize(func_get_args())) . '.png');
     if (!file_exists($cache_filepath)) {
         // Dimensions
         list($width, $height) = explode('x', $size);
         empty($height) && ($height = $width);
         $bgcolor = hex2rgb($bgcolor);
         $color = hex2rgb($color);
         empty($text) && ($text = $width . ' x ' . $height);
         //$hash_key = md5(serialize(compact('width','height','bgcolor','color','text')));
         // Create image
         $image = imagecreate($width, $height);
         // Colours
         $setbg = imagecolorallocate($image, $bgcolor['r'], $bgcolor['g'], $bgcolor['b']);
         $fontcolor = imagecolorallocate($image, $color['r'], $color['g'], $color['b']);
         // Text positioning
         empty($fontsize) && ($fontsize = $width > $height ? $height / 10 : $width / 10);
         $font = APPPATH . 'static/common/fonts/msyh.ttf';
         $fontbox = calculate_textbox($fontsize, 0, $font, $text);
         // Generate text
         function_exists('imageantialias') && imageantialias($image, true);
         imagettftext($image, $fontsize, 0, ceil(($width - $fontbox['width']) / 2 + $fontbox['left']), ceil(($height - $fontbox['height']) / 2 + $fontbox['top']), $fontcolor, $font, $text);
         // Render image
         imagepng($image, $cache_filepath);
         imagedestroy($image);
     }
     return response()->preview($cache_filepath, ['Content-Type' => 'image/png']);
 }
예제 #7
0
/**
 * Crop an Image to a given size.
 *
 * @since 2.1.0
 *
 * @param string|int $src_file The source file or Attachment ID.
 * @param int $src_x The start x position to crop from.
 * @param int $src_y The start y position to crop from.
 * @param int $src_w The width to crop.
 * @param int $src_h The height to crop.
 * @param int $dst_w The destination width.
 * @param int $dst_h The destination height.
 * @param int $src_abs Optional. If the source crop points are absolute.
 * @param string $dst_file Optional. The destination file to write to.
 * @return string New filepath on success, String error message on failure.
 */
function wp_crop_image($src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false)
{
    if (is_numeric($src_file)) {
        // Handle int as attachment ID
        $src_file = get_attached_file($src_file);
    }
    $src = wp_load_image($src_file);
    if (!is_resource($src)) {
        return $src;
    }
    $dst = wp_imagecreatetruecolor($dst_w, $dst_h);
    if ($src_abs) {
        $src_w -= $src_x;
        $src_h -= $src_y;
    }
    if (function_exists('imageantialias')) {
        imageantialias($dst, true);
    }
    imagecopyresampled($dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    imagedestroy($src);
    // Free up memory
    if (!$dst_file) {
        $dst_file = str_replace(basename($src_file), 'cropped-' . basename($src_file), $src_file);
    }
    $dst_file = preg_replace('/\\.[^\\.]+$/', '.jpg', $dst_file);
    if (imagejpeg($dst, $dst_file, apply_filters('jpeg_quality', 90, 'wp_crop_image'))) {
        return $dst_file;
    } else {
        return false;
    }
}
예제 #8
0
	function create($Width, $Height) {
		$this->Image = imagecreate($Width, $Height);
		$this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF';
		if(function_exists('imageantialias')){
			imageantialias($this->Image, true);
		}
	}
예제 #9
0
 private function _textToImage()
 {
     $bgc = $this->_bgcolor;
     $fgc = $this->_fgcolor;
     $str = wordwrap(urldecode(stripslashes($this->_text)), 50, "\n", 1);
     $lines = explode("\n", $str);
     $longest = '';
     foreach ($lines as $l) {
         if (strlen($l) > strlen($longest)) {
             $longest = $l;
         }
     }
     $tl = count($lines);
     $w = $this->_textWidth($this->_font, $longest, $this->_size) + 25;
     $h = $tl * ($this->_size * ($tl > 1 ? 1.5 : 2));
     $im = imagecreatetruecolor($w, $h);
     imagealphablending($im, true);
     imageantialias($im, true);
     $bg = imagecolorallocatealpha($im, $bgc['r'], $bgc['g'], $bgc['b'], $bgc['a']);
     $fg = imagecolorallocatealpha($im, $fgc['r'], $fgc['g'], $fgc['b'], $fgc['a']);
     imagefill($im, 0, 0, $bg);
     $x = 10;
     $y = $this->_size * 1.5;
     foreach ($lines as $l) {
         imagettftext($im, $this->_size, 0, $x, $y, $fg, $this->_font, $l);
         $y += $fh * 1.5;
     }
     if (file_exists($this->_CACHE_PATH)) {
         unlink($this->_CACHE_PATH);
     }
     imagepng($im, $this->_CACHE_PATH);
     return $im;
 }
예제 #10
0
파일: captcha.php 프로젝트: kuell/chat
function draw_captcha($security_code)
{
    //Set the image width and height
    $width = 100;
    $height = 25;
    //Create the image resource
    $image = ImageCreate($width, $height);
    if (function_exists('imageantialias')) {
        imageantialias($image, true);
    }
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 15, 50, 15);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    $ellipsec = ImageColorAllocate($image, 0, 100, 60);
    //Make the background black
    ImageFill($image, 0, 0, $black);
    imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
    //Add randomly generated string in white to the image
    ImageString($image, 5, 30, 4, $security_code, $white);
    //Throw in some lines to make it a little bit harder for any bots to break
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
    imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/jpeg");
    //Output the newly created image in jpeg format
    ImageJpeg($image);
    //Free up resources
    ImageDestroy($image);
}
예제 #11
0
파일: Gd.php 프로젝트: heg-arc-ne/cscart
 /**
  * Resizes image
  * @param string $src path to image
  * @param array $params resize parameters
  * @return array content and format
  */
 public static function resize($src, $params)
 {
     $img_functions = self::supportedFormats();
     $ext = $params['ext'];
     $new_width = $params['new_width'];
     $new_height = $params['new_height'];
     $dst_width = $params['dst_width'];
     $dst_height = $params['dst_height'];
     $width = $params['width'];
     $height = $params['height'];
     $bg_color = $params['bg_color'];
     $convert_to = $params['convert_to'];
     $jpeg_quality = $params['jpeg_quality'];
     $x = $params['x'];
     $y = $params['y'];
     $dst = imagecreatetruecolor($dst_width, $dst_height);
     if (function_exists('imageantialias')) {
         imageantialias($dst, true);
     }
     if ($ext == 'gif') {
         $new = imagecreatefromgif($src);
     } elseif ($ext == 'jpg') {
         $new = imagecreatefromjpeg($src);
     } elseif ($ext == 'png') {
         $new = imagecreatefrompng($src);
     }
     list($r, $g, $b) = empty($bg_color) ? fn_parse_rgb('#ffffff') : fn_parse_rgb($bg_color);
     $c = imagecolorallocate($dst, $r, $g, $b);
     if (empty($bg_color) && ($ext == 'png' || $ext == 'gif')) {
         if (function_exists('imagecolorallocatealpha') && function_exists('imagecolortransparent') && function_exists('imagesavealpha') && function_exists('imagealphablending')) {
             $c = imagecolorallocatealpha($dst, 255, 255, 255, 127);
             imagecolortransparent($dst, $c);
             imagesavealpha($dst, true);
             imagealphablending($dst, false);
         }
     }
     imagefilledrectangle($dst, 0, 0, $dst_width, $dst_height, $c);
     imagecopyresampled($dst, $new, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
     // Free memory from image
     imagedestroy($new);
     if ($convert_to == 'original') {
         $convert_to = $ext;
     } elseif (!empty($img_functions[$convert_to])) {
         $convert_to = $convert_to;
     } else {
         $convert_to = key($img_functions);
     }
     ob_start();
     if ($convert_to == 'gif') {
         imagegif($dst);
     } elseif ($convert_to == 'jpg') {
         imagejpeg($dst, null, $jpeg_quality);
     } elseif ($convert_to == 'png') {
         imagepng($dst);
     }
     $content = ob_get_clean();
     imagedestroy($dst);
     return array($content, $convert_to);
 }
예제 #12
0
파일: Pie.php 프로젝트: besters/My-Base
 public function generate($f_image, $n_image)
 {
     ImageFilledArc($f_image, $this->_width, $this->_height, $this->_width * 2, $this->_height * 2, 0, 300, $this->_completeColorAllocate, IMG_ARC_PIE);
     ImageFilledArc($f_image, $this->_width, $this->_height, $this->_width * 2, $this->_height * 2, 300, 360, $this->_incompleteColorAllocate, IMG_ARC_PIE);
     imageantialias($n_image, true);
     imagecopyresampled($n_image, $f_image, 0, 0, 0, 0, $this->_width, $this->_height, $this->_width * 2, $this->_height * 2);
     return $this;
 }
예제 #13
0
파일: gd.php 프로젝트: eXcomm/alive
 public function Initialize()
 {
     $this->mImg = imagecreatetruecolor($this->mWidth, $this->mHeight);
     imageantialias($this->mImg, $this->mAntialiasing);
     $this->mBlack = imagecolorallocate($this->mImg, 0, 0, 0);
     $this->mWhite = imagecolorallocate($this->mImg, 255, 255, 255);
     imagefill($this->mImg, 0, 0, $this->mWhite);
 }
예제 #14
0
 private function make_thumbnail_GD($src_path, $width, $height, $dest)
 {
     $size = @getimagesize($src_path);
     if ($size === false) {
         return false;
     }
     // не удалось получить параметры файла;
     $w = $size[0];
     $h = $size[1];
     $format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1));
     // Создаем ресурс картинки
     $image = @imagecreatefromstring(file_get_contents($src_path));
     if (!is_resource($image)) {
         return false;
     }
     // не получилось получить картинку
     // если не указана одна из сторон задаем ей пропорциональное значение
     if (!$width) {
         $width = round($w * ($height / $h));
     }
     if (!$height) {
         $height = round($h * ($width / $w));
     }
     // Создаем холст полноцветного изображения
     $thumb = imagecreatetruecolor($width, $height);
     if (function_exists('imagealphablending') && function_exists('imagesavealpha')) {
         imagealphablending($thumb, false);
         // режим сопряжения цвета и альфа цвета
         imagesavealpha($thumb, true);
         // флаг сохраняющий прозрачный канал
     }
     if (function_exists('imageantialias')) {
         imageantialias($thumb, true);
     }
     // включим функцию сглаживания
     list($dx, $dy, $wsrc, $hsrc) = $this->crop_coordinates($height, $h, $width, $w);
     if (!imagecopyresampled($thumb, $image, 0, 0, $dx, $dy, $width, $height, $wsrc, $hsrc)) {
         return false;
     }
     // не удалось изменить размер
     //
     // Сохраняем картинку
     if ($format == 'png') {
         // convert from full colors to index colors, like original PNG.
         if (function_exists('imageistruecolor') && !imageistruecolor($thumb)) {
             imagetruecolortopalette($thumb, false, imagecolorstotal($thumb));
         }
         imagepng($thumb, $dest);
     } elseif ($format == 'gif') {
         imagegif($thumb, $dest);
     } else {
         imagejpeg($thumb, $dest, 85);
     }
     chmod($dest, 0755);
     imagedestroy($image);
     imagedestroy($thumb);
     return true;
 }
예제 #15
0
 function SetAntiAliasing($aFlg = true)
 {
     $this->use_anti_aliasing = $aFlg;
     if (function_exists('imageantialias')) {
         imageantialias($this->img, $aFlg);
     } else {
         //JpGraphError::RaiseL(25128);//('The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.')
     }
 }
예제 #16
0
 public static function createImage($width, $height)
 {
     Args::int($width, 'width')->required()->min(0);
     Args::int($height, 'height')->required()->min(0);
     $imgRes = imagecreatetruecolor($width, $height);
     imageantialias($imgRes, true);
     imagealphablending($imgRes, true);
     imagesavealpha($imgRes, true);
     return $imgRes;
 }
예제 #17
0
파일: tc-lines.php 프로젝트: myfarms/PHPlot
function pre_plot($img)
{
    global $tp;
    if ($tp['antialias']) {
        imageantialias($img, True);
    }
    if ($tp['noalphablend']) {
        imagealphablending($img, False);
    }
}
예제 #18
0
/**
 * Crop an Image to a given size.
 *
 * @since 2.1.0
 *
 * @param string|int $src The source file or Attachment ID.
 * @param int $src_x The start x position to crop from.
 * @param int $src_y The start y position to crop from.
 * @param int $src_w The width to crop.
 * @param int $src_h The height to crop.
 * @param int $dst_w The destination width.
 * @param int $dst_h The destination height.
 * @param int $src_abs Optional. If the source crop points are absolute.
 * @param string $dst_file Optional. The destination file to write to.
 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
 */
function wp_crop_image($src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false)
{
    if (0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h) {
        return is_numeric($src) ? get_attached_file($src) : $src;
    }
    if (is_numeric($src)) {
        // Handle int as attachment ID
        $src_file = get_attached_file($src);
        if (!file_exists($src_file)) {
            // If the file doesn't exist, attempt a url fopen on the src link.
            // This can occur with certain file replication plugins.
            $post = get_post($src);
            $image_type = $post->post_mime_type;
            $src = load_image_to_edit($src, $post->post_mime_type, 'full');
        } else {
            $size = @getimagesize($src_file);
            $image_type = $size ? $size['mime'] : '';
            $src = wp_load_image($src_file);
        }
    } else {
        $size = @getimagesize($src);
        $image_type = $size ? $size['mime'] : '';
        $src = wp_load_image($src);
    }
    if (!is_resource($src)) {
        return new WP_Error('error_loading_image', $src, $src_file);
    }
    $dst = wp_imagecreatetruecolor($dst_w, $dst_h);
    if ($src_abs) {
        $src_w -= $src_x;
        $src_h -= $src_y;
    }
    if (function_exists('imageantialias')) {
        imageantialias($dst, true);
    }
    imagecopyresampled($dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    imagedestroy($src);
    // Free up memory
    if (!$dst_file) {
        $dst_file = str_replace(basename($src_file), 'cropped-' . basename($src_file), $src_file);
    }
    if ('image/png' != $image_type) {
        $dst_file = preg_replace('/\\.[^\\.]+$/', '.jpg', $dst_file);
    }
    // The directory containing the original file may no longer exist when
    // using a replication plugin.
    wp_mkdir_p(dirname($dst_file));
    if ('image/png' == $image_type && imagepng($dst, $dst_file)) {
        return $dst_file;
    } elseif (imagejpeg($dst, $dst_file, apply_filters('jpeg_quality', 90, 'wp_crop_image'))) {
        return $dst_file;
    } else {
        return false;
    }
}
예제 #19
0
 private function _get_lt_rounder_corner()
 {
     $radius = $this->_radius;
     $img = imagecreatetruecolor($radius, $radius);
     imageantialias($img, true);
     $bgcolor = imagecolorallocate($img, $this->_r, $this->_g, $this->_b);
     $fgcolor = imagecolorallocate($img, 0, 0, 0);
     imagefill($img, 0, 0, $bgcolor);
     imagefilledarc($img, $radius, $radius, $radius * 2, $radius * 2, 180, 270, $fgcolor, IMG_ARC_PIE);
     imagecolortransparent($img, $fgcolor);
     return $img;
 }
 public function getPrintJpeg()
 {
     imageantialias($this->canvas, true);
     $this->draw();
     // Start a new output buffer
     ob_start();
     imagejpeg($this->canvas, NULL, 100);
     $print = ob_get_contents();
     // Stop this output buffer
     ob_end_clean();
     imagedestroy($this->canvas);
     return $print;
 }
예제 #21
0
 /**
  * Creates a transparent (PNG, JPG) image with a <code>aWidth</code> and <code>aHeight</code>.
  *
  * @param int $aWidth The width of the image
  * @param int $aHeight The height of the image
  * @return resource
  */
 public static function createTransparentImage($width, $height)
 {
     Args::int($width, 'width')->required()->min(0);
     Args::int($height, 'height')->required()->min(0);
     $color = ColorFactory::white(127);
     $imgRes = imagecreatetruecolor($width, $height);
     imageantialias($imgRes, true);
     imagealphablending($imgRes, true);
     imagesavealpha($imgRes, true);
     $transparent = self::allocateColor($imgRes, $color);
     imagefill($imgRes, 0, 0, $transparent);
     return $imgRes;
 }
예제 #22
0
파일: Line.php 프로젝트: kosinix/grafika
 /**
  * @param Image $image
  *
  * @return Image
  */
 public function draw($image)
 {
     list($x1, $y1) = $this->point1;
     list($x2, $y2) = $this->point2;
     list($r, $g, $b) = $this->color->getRgb();
     $color = imagecolorallocate($image->getCore(), $r, $g, $b);
     if (function_exists('imageantialias')) {
         // Not available on some if PHP is not precompiled with it even if GD is enabled
         imageantialias($image->getCore(), true);
     }
     imageline($image->getCore(), $x1, $y1, $x2, $y2, $color);
     return $image;
 }
예제 #23
0
function imagewheelanim($x, $y, $speed, $steps)
{
    for ($i = 0; $i < $steps; $i++) {
        $img = imagecreatetruecolor(WIDTH, HEIGHT);
        imageantialias($img, true);
        $col_back = imagecolorallocate($img, 0x0, 0x0, 0x0);
        imagefilledrectangle($img, 0, 0, WIDTH, HEIGHT, $col_back);
        imagewheelmove($img, $x, $y, $speed);
        $x += $speed;
        imagepng($img, sprintf('anim%04u.png', $i));
        imagedestroy($img);
    }
}
예제 #24
0
 function CaptchaImages($code, $width = 145, $height = 35)
 {
     /* select the type of font, must be used in directoy in which script is being called into */
     $this->font = dirname(__FILE__) . '/CALIBRI.TTF';
     $font_size = $height * 0.6;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $bgR = mt_rand(0, 255);
     $bgG = mt_rand(0, 255);
     $bgB = mt_rand(0, 255);
     $background_color = imagecolorallocate($image, $bgR, $bgG, $bgB);
     $noise_color = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB));
     $text_color = imagecolorallocate($image, abs(255 - $bgR), abs(255 - $bgG), abs(255 - $bgB));
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* set random colors */
     $w = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB));
     $r = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB));
     /* Draw a dashed line, 5 red pixels, 5 white pixels */
     $style = array($r, $r, $r, $r, $r, $w, $w, $w, $w, $w);
     imagesetstyle($image, $style);
     imageline($image, 0, 0, $width, $height, IMG_COLOR_STYLED);
     imageline($image, $width, 0, 0, $height, IMG_COLOR_STYLED);
     /* create random polygon points */
     $values = array(mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width));
     /* create Random Colors then set it to $clr */
     $r = abs(100 - mt_rand(0, 255));
     $g = abs(100 - mt_rand(0, 255));
     $b = abs(100 - mt_rand(0, 255));
     $clr = imagecolorallocate($image, $r, $g, $b);
     /* create filled polygon with random points */
     imagefilledpolygon($image, $values, 6, $clr);
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* pretty it */
     imageantialias($image, 100);
     imagealphablending($image, 1);
     imagelayereffect($image, IMG_EFFECT_OVERLAY);
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
예제 #25
0
    /**
     * Generates a wallpaper with the latest data and updates desktop background
     *
     * @param array $data Array with the latest build history per project
     */
    private function updateBackground($data)
    {
        $this->updatedAt = microtime(true);
        $this->image = imagecreatetruecolor($this->get('image_width'), $this->get('image_height'));
        imageantialias($this->image, true);
        $this->initializeColors();
        imagefill($this->image, 0, 0, $this->get('background_color'));
        $numProject = 0;
        foreach ($data['projects'] as $project => $builds) {
            // the most recent build is always shown on top
            rsort($builds);
            $x1 = $this->get('horizontal_padding') + ($this->get('bar_width') + $this->get('horizontal_gutter')) * $numProject;
            $x2 = $x1 + $this->get('bar_width');
            // plot each project slug
            $this->addTextToImage(substr($project, 0, $this->get('max_number_letters')), $x1, $this->get('vertical_padding') - 0.2 * $this->get('font_size'));
            foreach ($builds as $i => $build) {
                $y1 = $this->get('vertical_padding') + $this->get('font_size') + ($this->get('bar_height') + $this->get('vertical_gutter')) * $i;
                $y2 = $y1 + $this->get('bar_height');
                $color = 'ok' == $build ? $this->get('success_color') : $this->get('failure_color');
                // plot a bar for each project build
                imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
            }
            $numProject++;
        }
        $this->addTextToImage('Last update: ' . $data['last_update'], $this->get('horizontal_padding'), $this->get('image_height') - $this->get('font_size'));
        // Hack: two different images are needed to update the wallpaper
        // One holds the current wallpaper and the other is the new one
        // If you use just one image and modify it, the OS doesn't reload it
        if (file_exists($this->evenBackgroundImagePath)) {
            $this->imagePath = $this->oddBackgroundImagePath;
            unlink($this->evenBackgroundImagePath);
        } elseif (file_exists($this->oddBackgroundImagePath)) {
            $this->imagePath = $this->evenBackgroundImagePath;
            unlink($this->oddBackgroundImagePath);
        } else {
            $this->imagePath = $this->oddBackgroundImagePath;
        }
        imagepng($this->image, $this->imagePath);
        imagedestroy($this->image);
        // Wallpaper is reloaded via AppleScript
        $scriptPath = $this->dir . '/update-background.scpt';
        file_put_contents($scriptPath, <<<END
tell application "System Events"
    tell current desktop
        set picture to POSIX file "file://localhost/{$this->imagePath}"
    end tell
end tell
END
);
        system("osascript {$scriptPath}");
    }
 /**
  * Applies the filter to the image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     if ($this->angle == 0 || $this->angle == 360) {
         return;
     }
     imageantialias($aResource->getResource(), true);
     $aResource->setResource(imagerotate($aResource->getResource(), $this->angle, $this->bgColor->getColorIndex(), $this->bgColor->getAlpha()));
     $new_imgres = imagecreatetruecolor($aResource->getX(), $aResource->getY());
     $success = imagecopy($new_imgres, $aResource->getResource(), 0, 0, 0, 0, $aResource->getX(), $aResource->getY());
     if (!$success) {
         throw new FilterException(self::$filterType);
     }
     imagedestroy($new_imgres);
 }
예제 #27
0
/**
 * No RRD files found that could match request
 * @code HTTP error code
 * @code_msg Short text description of HTTP error code
 * @title Title for fake RRD graph
 * @msg Complete error message to display in place of graph content
 */
function error($code, $code_msg, $title, $msg) {
	global $config;
	header(sprintf("HTTP/1.0 %d %s", $code, $code_msg));
	header("Pragma: no-cache");
	header("Expires: Mon, 01 Jan 2008 00:00:00 CET");
	header("Content-Type: image/png");
	$w = $config['rrd_width']+81;
	$h = $config['rrd_height']+79;

	$png     = imagecreate($w, $h);
	$c_bkgnd = imagecolorallocate($png, 240, 240, 240);
	$c_fgnd  = imagecolorallocate($png, 255, 255, 255);
	$c_blt   = imagecolorallocate($png, 208, 208, 208);
	$c_brb   = imagecolorallocate($png, 160, 160, 160);
	$c_grln  = imagecolorallocate($png, 114, 114, 114);
	$c_grarr = imagecolorallocate($png, 128,  32,  32);
	$c_txt   = imagecolorallocate($png, 0, 0, 0);
	$c_etxt  = imagecolorallocate($png, 64, 0, 0);

	if (function_exists('imageantialias'))
		imageantialias($png, true);
	imagefilledrectangle($png, 0,   0, $w, $h, $c_bkgnd);
	imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd);
	imageline($png,  51,  30,  51, $h-43, $c_grln);
	imageline($png,  48, $h-46, $w-28, $h-46, $c_grln);
	imagefilledpolygon($png, array(49, 30,    51, 26,    53, 30), 3, $c_grarr);
	imagefilledpolygon($png, array($w-28, $h-48,  $w-24, $h-46,  $w-28, $h-44), 3, $c_grarr);
	imageline($png,    0,    0,   $w,    0, $c_blt);
	imageline($png,    0,    1,   $w,    1, $c_blt);
	imageline($png,    0,    0,    0,   $h, $c_blt);
	imageline($png,    1,    0,    1,   $h, $c_blt);
	imageline($png, $w-1,    0, $w-1,   $h, $c_brb);
	imageline($png, $w-2,    1, $w-2,   $h, $c_brb);
	imageline($png,    1, $h-2,   $w, $h-2, $c_brb);
	imageline($png,    0, $h-1,   $w, $h-1, $c_brb);

	imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
	imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
	if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
		// Detailled error message
		$fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86);
		$fmtbox  = imagettfbbox(12, 0, $errorfont, $fmt_msg);
		imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg);
	} else {
		imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt);
	}

	imagepng($png);
	imagedestroy($png);
}
예제 #28
0
 public function allocate($size)
 {
     if ($this->size === $size) {
         return;
     }
     $this->size = $size;
     $this->image = $image = imagecreatetruecolor($this->size, $this->size);
     if (function_exists('imageantialias')) {
         // some installations don't have one
         imageantialias($image, true);
     }
     $bgColor = $this->bgColor;
     $this->bgColorValue = imagecolorallocate($image, $bgColor[0], $bgColor[1], $bgColor[2]);
 }
 public function generate(Blackboard $bb, $outfile)
 {
     $raw = file_get_contents($this->paths->getBlackboards() . "/{$bb->id}.json");
     $data = Json::decode($raw, Json::FORCE_ARRAY);
     $min = ['width' => PHP_INT_MAX, 'height' => PHP_INT_MAX];
     $max = ['width' => 0, 'height' => 0];
     foreach ($data['data'] as $row) {
         if ($row['type'] !== 'beginStroke' && $row['type'] !== 'strokeTo') {
             continue;
         }
         $min['width'] = min($min['width'], $row['loc']['x']);
         $min['height'] = min($min['height'], $row['loc']['y']);
         $max['width'] = max($max['width'], $row['loc']['x']);
         $max['height'] = max($max['height'], $row['loc']['y']);
     }
     $margin = 20;
     $min['width'] -= $margin;
     $min['height'] -= $margin;
     $max['width'] += $margin;
     $max['height'] += $margin;
     $ratio = 2;
     $canvas = imagecreatetruecolor(($max['width'] - $min['width']) * $ratio, ($max['height'] - $min['height']) * $ratio);
     if (function_exists('imageantialias')) {
         // this function is not in php5-gd and requires recompiling php
         imageantialias($canvas, TRUE);
     }
     $last = NULL;
     foreach ($data['data'] as $row) {
         if ($row['type'] === 'beginStroke') {
             $last = $row['loc'];
         } else {
             if ($row['type'] === 'strokeTo') {
                 $c = $row['color'];
                 $color = imagecolorallocate($canvas, $c['r'], $c['g'], $c['b']);
                 $this->imagelinethick($canvas, ($last['x'] - $min['width']) * $ratio, ($last['y'] - $min['height']) * $ratio, ($row['loc']['x'] - $min['width']) * $ratio, ($row['loc']['y'] - $min['height']) * $ratio, $color, 3);
                 $last = $row['loc'];
             } else {
                 if ($row['type'] === 'erase') {
                     $color = imagecolorallocate($canvas, 0, 0, 0);
                     $radius = 11 * $ratio;
                     $x = ($row['loc']['x'] - $min['width']) * $ratio;
                     $y = ($row['loc']['y'] - $min['height']) * $ratio;
                     imagefilledarc($canvas, $x, $y, $radius, $radius, 0, 360, $color, IMG_ARC_PIE);
                 }
             }
         }
     }
     imagepng($canvas, $outfile, 9);
 }
예제 #30
0
function loadBaseImage($img_path)
{
    $img_size = getimagesize($img_path);
    $img_png = imagecreatefrompng($img_path);
    if (!$img_png) {
        exit(1);
    }
    $img_tc = imagecreatetruecolor($img_size[0], $img_size[1]);
    imagealphablending($img_tc, false);
    imagesavealpha($img_tc, true);
    imagecopy($img_tc, $img_png, 0, 0, 0, 0, $img_size[0], $img_size[1]);
    imagedestroy($img_png);
    if (function_exists('imageantialias')) {
        imageantialias($img_tc, true);
    }
    return $img_tc;
}