Example #1
1
 /**
  * Adds to the PNG image object, the data related to a row in the GIS dataset.
  *
  * @param string $spatial    GIS POLYGON object
  * @param string $label      Label for the GIS POLYGON object
  * @param string $fill_color Color for the GIS POLYGON object
  * @param array  $scale_data Array containing data related to scaling
  * @param object $image      Image object
  *
  * @return object the modified image object
  * @access public
  */
 public function prepareRowAsPng($spatial, $label, $fill_color, $scale_data, $image)
 {
     // allocate colors
     $black = imagecolorallocate($image, 0, 0, 0);
     $red = hexdec(mb_substr($fill_color, 1, 2));
     $green = hexdec(mb_substr($fill_color, 3, 2));
     $blue = hexdec(mb_substr($fill_color, 4, 2));
     $color = imagecolorallocate($image, $red, $green, $blue);
     // Trim to remove leading 'POLYGON((' and trailing '))'
     $polygon = mb_substr($spatial, 9, mb_strlen($spatial) - 11);
     // If the polygon doesn't have an inner polygon
     if (mb_strpos($polygon, "),(") === false) {
         $points_arr = $this->extractPoints($polygon, $scale_data, true);
     } else {
         // Separate outer and inner polygons
         $parts = explode("),(", $polygon);
         $outer = $parts[0];
         $inner = array_slice($parts, 1);
         $points_arr = $this->extractPoints($outer, $scale_data, true);
         foreach ($inner as $inner_poly) {
             $points_arr = array_merge($points_arr, $this->extractPoints($inner_poly, $scale_data, true));
         }
     }
     // draw polygon
     imagefilledpolygon($image, $points_arr, sizeof($points_arr) / 2, $color);
     // print label if applicable
     if (isset($label) && trim($label) != '') {
         imagestring($image, 1, $points_arr[2], $points_arr[3], trim($label), $black);
     }
     return $image;
 }
Example #2
1
 public function getAvatar($string, $widthHeight = 12, $theme = 'default')
 {
     $widthHeight = max($widthHeight, 12);
     $md5 = md5($string);
     $fileName = _TMP_DIR_ . '/' . $md5 . '.png';
     if ($this->tmpFileExists($fileName)) {
         return $fileName;
     }
     // Create seed.
     $seed = intval(substr($md5, 0, 6), 16);
     mt_srand($seed);
     $body = array('legs' => mt_rand(0, count($this->availableParts[$theme]['legs']) - 1), 'hair' => mt_rand(0, count($this->availableParts[$theme]['hair']) - 1), 'arms' => mt_rand(0, count($this->availableParts[$theme]['arms']) - 1), 'body' => mt_rand(0, count($this->availableParts[$theme]['body']) - 1), 'eyes' => mt_rand(0, count($this->availableParts[$theme]['eyes']) - 1), 'mouth' => mt_rand(0, count($this->availableParts[$theme]['mouth']) - 1));
     // Avatar random parts.
     $parts = array('legs' => $this->availableParts[$theme]['legs'][$body['legs']], 'hair' => $this->availableParts[$theme]['hair'][$body['hair']], 'arms' => $this->availableParts[$theme]['arms'][$body['arms']], 'body' => $this->availableParts[$theme]['body'][$body['body']], 'eyes' => $this->availableParts[$theme]['eyes'][$body['eyes']], 'mouth' => $this->availableParts[$theme]['mouth'][$body['mouth']]);
     $avatar = imagecreate($widthHeight, $widthHeight);
     imagesavealpha($avatar, true);
     imagealphablending($avatar, false);
     $background = imagecolorallocate($avatar, 0, 0, 0);
     $line_colour = imagecolorallocate($avatar, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55);
     imagecolortransparent($avatar, $background);
     imagefilledrectangle($avatar, 0, 0, $widthHeight, $widthHeight, $background);
     // Fill avatar with random parts.
     foreach ($parts as &$part) {
         $this->drawPart($part, $avatar, $widthHeight, $line_colour, $background);
     }
     imagepng($avatar, $fileName);
     imagecolordeallocate($avatar, $line_colour);
     imagecolordeallocate($avatar, $background);
     imagedestroy($avatar);
     return $fileName;
 }
Example #3
1
 static function load($filename)
 {
     $info = getimagesize($filename);
     list($width, $height) = $info;
     if (!$width || !$height) {
         return null;
     }
     $image = null;
     switch ($info['mime']) {
         case 'image/gif':
             $image = imagecreatefromgif($filename);
             break;
         case 'image/jpeg':
             $image = imagecreatefromjpeg($filename);
             break;
         case 'image/png':
             $image = imagecreatetruecolor($width, $height);
             $white = imagecolorallocate($image, 255, 255, 255);
             imagefill($image, 0, 0, $white);
             $png = imagecreatefrompng($filename);
             imagealphablending($png, true);
             imagesavealpha($png, true);
             imagecopy($image, $png, 0, 0, 0, 0, $width, $height);
             imagedestroy($png);
             break;
     }
     if ($image) {
         return new image($image, $width, $height);
     } else {
         return null;
     }
 }
 /**
  * Applies the sepia filter to an image resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     if ($this->degrees === 0) {
         return;
     }
     $width = $aResource->getX();
     $height = $aResource->getY();
     // cache calculated colors in a map...
     $colorMap = array();
     for ($x = 0; $x < $width; ++$x) {
         for ($y = 0; $y < $height; ++$y) {
             $color = ColorUtil::getColorAt($aResource, Coordinate::create($x, $y));
             if (!isset($colorMap[$color->getColorIndex()])) {
                 // calculate the new color
                 $hsl = ColorUtil::rgb2hsl($color->getRed(), $color->getGreen(), $color->getBlue());
                 $hsl[0] += $this->degrees;
                 $rgb = ColorUtil::hsl2rgb($hsl[0], $hsl[1], $hsl[2]);
                 $newcol = imagecolorallocate($aResource->getResource(), $rgb[0], $rgb[1], $rgb[2]);
                 $colorMap[$color->getColorIndex()] = $newcol;
             } else {
                 $newcol = $colorMap[$color->getColorIndex()];
             }
             imagesetpixel($aResource->getResource(), $x, $y, $newcol);
         }
     }
     $colorMap = null;
 }
function hacknrollify($picfilename)
{
    $logofilename = "logo.png";
    $logoPicPath = "logopics/" . $logofilename;
    $originalPicPath = "originalpics/" . $picfilename;
    $editedfilename = "hnr_" . $picfilename;
    $editedPicPath = "editedpics/" . $editedfilename;
    // read the original image from file
    $profilepic = imagecreatefromjpeg($originalPicPath);
    $profilepicWidth = imagesx($profilepic);
    $profilepicHeight = imagesy($profilepic);
    // create the black image overlay
    $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
    imagecolorallocate($blackoverlay, 0, 0, 0);
    // then merge the black and profilepic
    imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
    imagedestroy($blackoverlay);
    // merge the resized logo
    $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
    imageAlphaBlending($logo, false);
    imageSaveAlpha($logo, true);
    $logoWidth = imagesx($logo);
    $logoHeight = imagesy($logo);
    $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
    $horizontalOffset = 40;
    imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
    $mergeSuccess = imagejpeg($profilepic, $editedPicPath);
    if (!$mergeSuccess) {
        echo "Image merge failed!";
    }
    imagedestroy($profilepic);
    imagedestroy($logo);
    return $editedPicPath;
}
Example #6
0
 /**
  * @param $text
  * @return resource
  */
 private function createImage($text)
 {
     if (!is_string($text) || trim($text) == '') {
         $text = 'ERROR';
     }
     // Create an image from captchaBackground.png
     $image = imagecreatefrompng(realpath('bundles/comun/images/captchaBackground.png'));
     // Set the font colour
     $colour = imagecolorallocate($image, 183, 178, 152);
     // Set the font
     //$font = '../fonts/Anorexia.ttf';
     $font = realpath('bundles/comun/fonts/Anorexia.ttf');
     // Set a random integer for the rotation between -15 and 15 degrees
     $rotate = rand(-15, 15);
     // Create an image using our original image and adding the detail
     imagettftext($image, 14, $rotate, 18, 30, $colour, $font, $text);
     // Output the image as a png
     //imagepng($image);
     /*return new Response(
           $captchaText,
           200,
           array(
               'Content-Type' => 'image/png',
               'Cache-Control' => 'no-cache'
           )
       );*/
     return $image;
 }
 /**
  * Adds to the PNG image object, the data related to a row in the GIS dataset.
  *
  * @param string $spatial    GIS MULTILINESTRING object
  * @param string $label      Label for the GIS MULTILINESTRING object
  * @param string $line_color Color for the GIS MULTILINESTRING object
  * @param array  $scale_data Array containing data related to scaling
  * @param object $image      Image object
  *
  * @return object the modified image object
  * @access public
  */
 public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image)
 {
     // allocate colors
     $black = imagecolorallocate($image, 0, 0, 0);
     $red = hexdec(mb_substr($line_color, 1, 2));
     $green = hexdec(mb_substr($line_color, 3, 2));
     $blue = hexdec(mb_substr($line_color, 4, 2));
     $color = imagecolorallocate($image, $red, $green, $blue);
     // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
     $multilinestirng = mb_substr($spatial, 17, mb_strlen($spatial) - 19);
     // Separate each linestring
     $linestirngs = explode("),(", $multilinestirng);
     $first_line = true;
     foreach ($linestirngs as $linestring) {
         $points_arr = $this->extractPoints($linestring, $scale_data);
         foreach ($points_arr as $point) {
             if (!isset($temp_point)) {
                 $temp_point = $point;
             } else {
                 // draw line section
                 imageline($image, $temp_point[0], $temp_point[1], $point[0], $point[1], $color);
                 $temp_point = $point;
             }
         }
         unset($temp_point);
         // print label if applicable
         if (isset($label) && trim($label) != '' && $first_line) {
             imagestring($image, 1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
         }
         $first_line = false;
     }
     return $image;
 }
Example #8
0
 static function codeimage()
 {
     $image = imagecreatetruecolor(100, 30);
     $bgcolor = imagecolorallocate($image, 255, 255, 255);
     imagefill($image, 0, 0, $bgcolor);
     $code = '';
     for ($i = 0; $i < 4; $i++) {
         $fontsize = 6;
         $fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
         $data = "abcdefghjkmnpqrstuvwxy3456789";
         $fontcontent = substr($data, rand(1, strlen($data) - 1), 1);
         $code .= $fontcontent;
         $x = $i * 100 / 4 + rand(5, 10);
         $y = rand(5, 10);
         imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
     }
     for ($i = 0; $i < 200; $i++) {
         $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
         imagesetpixel($image, rand(1, 99), rand(1, 29), $pointcolor);
     }
     for ($i = 0; $i < 2; $i++) {
         $linecolor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220));
         imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $linecolor);
     }
     $return['code'] = $code;
     $return['image'] = $image;
     return $return;
     //		header('content-type:image/png');
     //		imagepng($image);
 }
Example #9
0
 /**
  * Outputs the Captcha image.
  *
  * @param   boolean  html output
  * @return  mixed
  */
 public function render($html)
 {
     // Creates a black image to start from
     $this->image_create(Captcha::$config['background']);
     // Add random white/gray arcs, amount depends on complexity setting
     $count = (Captcha::$config['width'] + Captcha::$config['height']) / 2;
     $count = $count / 5 * min(10, Captcha::$config['complexity']);
     for ($i = 0; $i < $count; $i++) {
         imagesetthickness($this->image, mt_rand(1, 2));
         $color = imagecolorallocatealpha($this->image, 255, 255, 255, mt_rand(0, 120));
         imagearc($this->image, mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(0, 360), mt_rand(0, 360), $color);
     }
     // Use different fonts if available
     $font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
     // Draw the character's white shadows
     $size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / strlen($this->response));
     $angle = mt_rand(-15 + strlen($this->response), 15 - strlen($this->response));
     $x = mt_rand(1, Captcha::$config['width'] * 0.9 - $size * strlen($this->response));
     $y = (Captcha::$config['height'] - $size) / 2 + $size;
     $color = imagecolorallocate($this->image, 255, 255, 255);
     imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, $font, $this->response);
     // Add more shadows for lower complexities
     Captcha::$config['complexity'] < 10 and imagefttext($this->image, $size, $angle, $x - 1, $y - 1, $color, $font, $this->response);
     Captcha::$config['complexity'] < 8 and imagefttext($this->image, $size, $angle, $x - 2, $y + 2, $color, $font, $this->response);
     Captcha::$config['complexity'] < 6 and imagefttext($this->image, $size, $angle, $x + 2, $y - 2, $color, $font, $this->response);
     Captcha::$config['complexity'] < 4 and imagefttext($this->image, $size, $angle, $x + 3, $y + 3, $color, $font, $this->response);
     Captcha::$config['complexity'] < 2 and imagefttext($this->image, $size, $angle, $x - 3, $y - 3, $color, $font, $this->response);
     // Finally draw the foreground characters
     $color = imagecolorallocate($this->image, 0, 0, 0);
     imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response);
     // Output
     return $this->image_render($html);
 }
Example #10
0
function resize($photo_src, $width, $name)
{
    $parametr = getimagesize($photo_src);
    list($width_orig, $height_orig) = getimagesize($photo_src);
    $ratio_orig = $width_orig / $height_orig;
    $new_width = $width;
    $new_height = $width / $ratio_orig;
    $newpic = imagecreatetruecolor($new_width, $new_height);
    $col2 = imagecolorallocate($newpic, 255, 255, 255);
    imagefilledrectangle($newpic, 0, 0, $new_width, $new_width, $col2);
    switch ($parametr[2]) {
        case 1:
            $image = imagecreatefromgif($photo_src);
            break;
        case 2:
            $image = imagecreatefromjpeg($photo_src);
            break;
        case 3:
            $image = imagecreatefrompng($photo_src);
            break;
    }
    imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
    imagejpeg($newpic, $name, 100);
    return true;
}
 protected function createMask(sfImage $image, $w, $h)
 {
     // Create a mask png image of the area you want in the circle/ellipse (a 'magicpink' image with a black shape on it, with black set to the colour of alpha transparency) - $mask
     $mask = $image->getAdapter()->getTransparentImage($w, $h);
     // Set the masking colours
     if (false === $this->getColor() || 'image/png' == $image->getMIMEType()) {
         $mask_black = imagecolorallocate($mask, 0, 0, 0);
     } else {
         $mask_black = $image->getAdapter()->getColorByHex($mask, $this->getColor());
     }
     // Cannot use white as transparent mask if color is set to white
     if ($this->getColor() === '#FFFFFF' || $this->getColor() === false) {
         $mask_transparent = imagecolorallocate($mask, 255, 0, 0);
     } else {
         $mask_color = imagecolorsforindex($mask, imagecolorat($image->getAdapter()->getHolder(), 0, 0));
         $mask_transparent = imagecolorallocate($mask, $mask_color['red'], $mask_color['green'], $mask_color['blue']);
     }
     imagecolortransparent($mask, $mask_transparent);
     imagefill($mask, 0, 0, $mask_black);
     // Draw the rounded rectangle for the mask
     $this->imagefillroundedrect($mask, 0, 0, $w, $h, $this->getRadius(), $mask_transparent);
     $mask_image = clone $image;
     $mask_image->getAdapter()->setHolder($mask);
     return $mask_image;
 }
Example #12
0
function GetPartialImage($url)
{
	$W = 150;
	$H = 130;
	$F = 80;
	$STEP = 1.0 / $F;
	$im = imagecreatefromjpeg($url);
	$dest = imagecreatetruecolor($W, $H);
	imagecopy($dest, $im, 0, 0, 35, 40, $W, $H);
	
	$a = 1;
	for( $y = $H - $F; $y < $H; $y++ )
	{
		for ( $x = 0; $x < $W; $x++ )
		{
			$i = imagecolorat($dest, $x, $y);
			$c = imagecolorsforindex($dest, $i);
			$c = imagecolorallocate($dest, 
				a($c['red'], $a),
				a($c['green'], $a), 
				a($c['blue'], $a)
			);
			imagesetpixel($dest, $x, $y, $c);
		}
		$a -= $STEP;
	}
	
	header('Content-type: image/png');
	imagepng($dest);
	imagedestroy($dest);
	imagedestroy($im);
}
Example #13
0
 public function testUploadFile()
 {
     $album = $this->Album->init();
     $tmp_file = "/tmp/111111111.jpg";
     # Generate custom image to test upload
     $im = imagecreatetruecolor(120, 20);
     $text_color = imagecolorallocate($im, 233, 14, 91);
     imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
     imagejpeg($im, $tmp_file);
     # Generate path to save file
     $file_path = $this->Picture->generateFilePath($album['Album']['id'], 'picturetests.jpg');
     $file = new File($file_path);
     # Get resize options
     $resize_attrs = $this->Picture->getResizeToSize();
     # Upload and save
     $should_return_3 = $this->Picture->uploadFile($file_path, $album['Album']['id'], 'samplepicture.jpg', $tmp_file, $resize_attrs['width'], $resize_attrs['height'], $resize_attrs['action'], true);
     # File was saved?
     $this->assertEqual(3, $should_return_3);
     # File was uploaded?
     $this->assertTrue($file->exists());
     # Should rise exception
     try {
         $this->Picture->uploadFile($file_path, null, 'samplepicture.jpg', $tmp_file, $resize_attrs['width'], $resize_attrs['height'], $resize_attrs['action'], true);
     } catch (ForbiddenException $e) {
         $this->assertEqual($e->getMessage(), "The album ID is required");
     }
 }
Example #14
0
 /**
  * Processes incoming text
  */
 public function action_index()
 {
     $this->request->headers['Content-type'] = 'image/png';
     // Grab text and styles
     $text = arr::get($_GET, 'text');
     $styles = $_GET;
     $hover = FALSE;
     try {
         // Create image
         $img = new PNGText($text, $styles);
         foreach ($styles as $key => $value) {
             if (substr($key, 0, 6) == 'hover-') {
                 // Grab hover associated styles and override existing styles
                 $hover = TRUE;
                 $styles[substr($key, 6)] = $value;
             }
         }
         if ($hover) {
             // Create new hover image and stack it
             $hover = new PNGText($text, $styles);
             $img->stack($hover);
         }
         echo $img->draw();
     } catch (Exception $e) {
         if (Kohana::config('pngtext.debug')) {
             // Dump error message in an image form
             $img = imagecreatetruecolor(strlen($e->getMessage()) * 6, 16);
             imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
             imagestring($img, 2, 0, 0, $e->getMessage(), imagecolorallocate($img, 0, 0, 0));
             echo imagepng($img);
         }
     }
 }
Example #15
0
function graph_error($string)
{
    global $vars, $config, $debug, $graphfile;
    $vars['bg'] = 'FFBBBB';
    include 'includes/graphs/common.inc.php';
    $rrd_options .= ' HRULE:0#555555';
    $rrd_options .= " --title='" . $string . "'";
    rrdtool_graph($graphfile, $rrd_options);
    if ($height > '99') {
        shell_exec($rrd_cmd);
        d_echo('<pre>' . $rrd_cmd . '</pre>');
        if (is_file($graphfile) && !$debug) {
            header('Content-type: image/png');
            $fd = fopen($graphfile, 'r');
            fpassthru($fd);
            fclose($fd);
            unlink($graphfile);
            exit;
        }
    } else {
        if (!$debug) {
            header('Content-type: image/png');
        }
        $im = imagecreate($width, $height);
        $px = (imagesx($im) - 7.5 * strlen($string)) / 2;
        imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0));
        imagepng($im);
        imagedestroy($im);
        exit;
    }
}
Example #16
0
 public function index()
 {
     $code = substr(sha1(mt_rand()), 17, 6);
     $this->session->set_userdata('captcha_code', $code);
     $width = '120';
     $height = '40';
     $font = APPPATH . 'modules/contact/assets/fonts/monofont.ttf';
     $font_size = $height * 0.75;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 20, 40, 100);
     $noise_color = imagecolorallocate($image, 100, 120, 180);
     /* 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);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $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, $font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
 /**
  * Adds to the PNG image object, the data related to a row in the GIS dataset.
  *
  * @param string $spatial     GIS MULTIPOINT object
  * @param string $label       Label for the GIS MULTIPOINT object
  * @param string $point_color Color for the GIS MULTIPOINT object
  * @param array  $scale_data  Array containing data related to scaling
  * @param object $image       Image object
  *
  * @return object the modified image object
  * @access public
  */
 public function prepareRowAsPng($spatial, $label, $point_color, $scale_data, $image)
 {
     /** @var PMA_String $pmaString */
     $pmaString = $GLOBALS['PMA_String'];
     // allocate colors
     $black = imagecolorallocate($image, 0, 0, 0);
     $red = hexdec($pmaString->substr($point_color, 1, 2));
     $green = hexdec($pmaString->substr($point_color, 3, 2));
     $blue = hexdec($pmaString->substr($point_color, 4, 2));
     $color = imagecolorallocate($image, $red, $green, $blue);
     // Trim to remove leading 'MULTIPOINT(' and trailing ')'
     $multipoint = $pmaString->substr($spatial, 11, $pmaString->strlen($spatial) - 12);
     $points_arr = $this->extractPoints($multipoint, $scale_data);
     foreach ($points_arr as $point) {
         // draw a small circle to mark the point
         if ($point[0] != '' && $point[1] != '') {
             imagearc($image, $point[0], $point[1], 7, 7, 0, 360, $color);
         }
     }
     // print label for each point
     if (isset($label) && trim($label) != '' && ($points_arr[0][0] != '' && $points_arr[0][1] != '')) {
         imagestring($image, 1, $points_arr[0][0], $points_arr[0][1], trim($label), $black);
     }
     return $image;
 }
Example #18
0
function foundation_process_image_file($file_name, $setting_name)
{
    if ($setting_name->domain == FOUNDATION_SETTING_DOMAIN && $setting_name->name == 'logo_image') {
        // Need to make sure this isn't too big
        if (function_exists('getimagesize') && function_exists('imagecreatefrompng') && function_exists('imagecopyresampled') && function_exists('imagepng')) {
            $size = getimagesize($file_name);
            if ($size) {
                $width = $size[0];
                $height = $size[1];
                if ($size['mime'] == 'image/png') {
                    if ($width > FOUNDATION_MAX_LOGO_SIZE) {
                        $new_width = FOUNDATION_MAX_LOGO_SIZE;
                        $new_height = $height * $new_width / $width;
                        $src_image = imagecreatefrompng($file_name);
                        $saved_image = imagecreatetruecolor($new_width, $new_height);
                        // Preserve Transparency
                        imagecolortransparent($saved_image, imagecolorallocate($saved_image, 0, 0, 0));
                        imagecopyresampled($saved_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                        // Get rid of the old file
                        unlink($file_name);
                        // New image, compression level 5 (make it a bit smaller)
                        imagepng($saved_image, $file_name, 5);
                    }
                }
            }
        }
    }
}
 function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.5;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 20, 20, 20);
     $text_color = imagecolorallocate($image, 230, 197, 89);
     $noise_color = imagecolorallocate($image, 0, 0, 0);
     /* 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);
     		}*/
     /* create textbox and add text */
     $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');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
     $_SESSION['security_code'] = $code;
 }
Example #20
0
 /**
  * Displays the captcha image
  *
  * @access  public
  * @param   int     $key    Captcha key
  * @return  mixed   Captcha raw image data
  */
 function image($key)
 {
     $value = Jaws_Utils::RandomText();
     $result = $this->update($key, $value);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     }
     $bg = dirname(__FILE__) . '/resources/simple.bg.png';
     $im = imagecreatefrompng($bg);
     imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
     // Write it in a random position..
     $darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70);
     $x = 5;
     $y = 20;
     $text_length = strlen($value);
     for ($i = 0; $i < $text_length; $i++) {
         $fnt = rand(7, 10);
         $y = rand(6, 10);
         imagestring($im, $fnt, $x, $y, $value[$i], $darkgray);
         $x = $x + rand(15, 25);
     }
     header("Content-Type: image/png");
     ob_start();
     imagepng($im);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $content;
 }
Example #21
0
 public function testImage()
 {
     $size = 300;
     $this->image = imagecreatetruecolor($size, $size);
     //用白色背景,黑色边框画方框
     $back = imagecolorallocate($this->image, 255, 255, 255);
     $border = imagecolorallocate($this->image, 0, 0, 0);
     imagefilledrectangle($this->image, 0, 0, $size, $size, $back);
     //画出白色背景
     imagerectangle($this->image, 0, 0, $size - 1, $size - 1, $border);
     //画出黑色边框
     $yellow_x = 150;
     $yellow_y = 75;
     $red_x = 100;
     $red_y = 160;
     $blue_x = 200;
     $blue_y = 160;
     $radius = 150;
     $yellow = imagecolorallocatealpha($this->image, 255, 255, 0, 75);
     //此函数将黄色的alpha值调为75,就是透明度
     $red = imagecolorallocatealpha($this->image, 255, 0, 0, 75);
     $blue = imagecolorallocatealpha($this->image, 0, 0, 255, 75);
     //画三个交叠的圆
     imagefilledellipse($this->image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
     //此函数就是我要在$image上画一个圆心($yellow_x,$yellow_y)半径为$radius/2颜色为$yellow的圆
     imagefilledellipse($this->image, $red_x, $red_y, $radius, $radius, $red);
     imagefilledellipse($this->image, $blue_x, $blue_y, $radius, $radius, $blue);
     //输出正确的header
     header("Content-type: image/png");
     //输出结果
     imagepng($this->image);
     imagedestroy($this->image);
 }
Example #22
0
function draw_bar_graph($width, $height, $data, $max_value, $filename)
{
    // Create the empty graph image
    $img = imagecreatetruecolor($width, $height);
    // Set a white background with black text and gray graphics
    $bg_color = imagecolorallocate($img, 255, 255, 255);
    // white
    $text_color = imagecolorallocate($img, 255, 255, 255);
    // white
    $bar_color = imagecolorallocate($img, 0, 0, 0);
    // black
    $border_color = imagecolorallocate($img, 192, 192, 192);
    // light gray
    // Fill the background
    imagefilledrectangle($img, 0, 0, $width, $height, $bg_color);
    // Draw the bars
    $bar_width = $width / (count($data) * 2 + 1);
    for ($i = 0; $i < count($data); $i++) {
        imagefilledrectangle($img, $i * $bar_width * 2 + $bar_width, $height, $i * $bar_width * 2 + $bar_width * 2, $height - $height / $max_value * $data[$i][1], $bar_color);
        imagestringup($img, 5, $i * $bar_width * 2 + $bar_width, $height - 5, $data[$i][0], $text_color);
    }
    // Draw a rectangle around the whole thing
    imagerectangle($img, 0, 0, $width - 1, $height - 1, $border_color);
    // Draw the range up the left side of the graph
    for ($i = 1; $i <= $max_value; $i++) {
        imagestring($img, 5, 0, $height - $i * ($height / $max_value), $i, $bar_color);
    }
    // Write the graph image to a file
    imagepng($img, $filename, 5);
    imagedestroy($img);
}
 /**
  *
  * @param string $playername Minecraft player name
  * @param resource $avatar the rendered avatar (for example player head)
  *
  * @param string $background Image Path or Standard Value
  * @return resource the generated banner
  */
 public static function player($playername, $avatar = NULL, $background = NULL)
 {
     $canvas = MinecraftBanner::getBackgroundCanvas(self::PLAYER_WIDTH, self::PLAYER_HEIGHT, $background);
     $head_height = self::AVATAR_SIZE;
     $head_width = self::AVATAR_SIZE;
     $avater_x = self::PLAYER_PADDING;
     $avater_y = self::PLAYER_HEIGHT / 2 - self::AVATAR_SIZE / 2;
     if ($avatar == NULL) {
         $avatar = imagecreatefrompng(__DIR__ . "/img/head.png");
         imagesavealpha($avatar, true);
         imagecopy($canvas, $avatar, $avater_x, $avater_y, 0, 0, $head_width, $head_height);
     } else {
         $head_width = imagesx($avatar);
         $head_height = imagesy($avatar);
         if ($head_width > self::AVATAR_SIZE) {
             $head_width = self::AVATAR_SIZE;
         }
         if ($head_height > self::AVATAR_SIZE) {
             $head_height = self::AVATAR_SIZE;
         }
         $center_x = $avater_x + self::AVATAR_SIZE / 2 - $head_width / 2;
         $center_y = $avater_y + self::AVATAR_SIZE / 2 - $head_height / 2;
         imagecopy($canvas, $avatar, $center_x, $center_y, 0, 0, $head_width, $head_height);
     }
     $box = imagettfbbox(self::TEXT_SIZE, 0, MinecraftBanner::FONT_FILE, $playername);
     $text_width = abs($box[4] - $box[0]);
     $text_color = imagecolorallocate($canvas, 255, 255, 255);
     $remaining = self::PLAYER_WIDTH - self::AVATAR_SIZE - $avater_x - self::PLAYER_PADDING;
     $text_posX = $avater_x + self::AVATAR_SIZE + $remaining / 2 - $text_width / 2;
     $text_posY = $avater_y + self::AVATAR_SIZE / 2 + self::TEXT_SIZE / 2;
     imagettftext($canvas, self::TEXT_SIZE, 0, $text_posX, $text_posY, $text_color, MinecraftBanner::FONT_FILE, $playername);
     return $canvas;
 }
Example #24
0
function getCode($num, $w, $h)
{
    // 去掉了 0 1 O l 等
    $str = "23456789abcdefghijkmnpqrstuvwxyz";
    $code = '';
    for ($i = 0; $i < $num; $i++) {
        $code .= $str[mt_rand(0, strlen($str) - 1)];
    }
    //将生成的验证码写入session,备验证页面使用
    $_SESSION["my_checkcode"] = $code;
    //创建图片,定义颜色值
    Header("Content-type: image/PNG");
    $im = imagecreate($w, $h);
    $black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
    $gray = imagecolorallocate($im, 118, 151, 199);
    $bgcolor = imagecolorallocate($im, 235, 236, 237);
    //画背景
    imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
    //画边框
    imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray);
    //imagefill($im, 0, 0, $bgcolor);
    //在画布上随机生成大量点,起干扰作用;
    for ($i = 0; $i < 80; $i++) {
        imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
    }
    //将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
    $strx = rand(5, 10);
    for ($i = 0; $i < $num; $i++) {
        $strpos = rand(1, 6);
        imagestring($im, 20, $strx, $strpos, substr($code, $i, 1), $black);
        $strx += $w / 5;
    }
    imagepng($im);
    imagedestroy($im);
}
Example #25
0
 /**
  * Adds to the PNG image object, the data related to a row in the GIS dataset.
  *
  * @param string $spatial    GIS LINESTRING object
  * @param string $label      Label for the GIS LINESTRING object
  * @param string $line_color Color for the GIS LINESTRING object
  * @param array  $scale_data Array containing data related to scaling
  * @param image  $image      Image object
  *
  * @return the modified image object
  */
 public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image)
 {
     // allocate colors
     $black = imagecolorallocate($image, 0, 0, 0);
     $red = hexdec(substr($line_color, 1, 2));
     $green = hexdec(substr($line_color, 3, 2));
     $blue = hexdec(substr($line_color, 4, 2));
     $color = imagecolorallocate($image, $red, $green, $blue);
     // Trim to remove leading 'LINESTRING(' and trailing ')'
     $linesrting = substr($spatial, 11, strlen($spatial) - 12);
     $points_arr = $this->extractPoints($linesrting, $scale_data);
     foreach ($points_arr as $point) {
         if (!isset($temp_point)) {
             $temp_point = $point;
         } else {
             // draw line section
             imageline($image, $temp_point[0], $temp_point[1], $point[0], $point[1], $color);
             $temp_point = $point;
         }
     }
     // print label if applicable
     if (isset($label) && trim($label) != '') {
         imagestring($image, 1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
     }
     return $image;
 }
Example #26
0
function get_default_image()
{
    $image = imagecreate(50, 50);
    $color = imagecolorallocate($image, 250, 50, 50);
    imagefill($image, 0, 0, $color);
    return $image;
}
Example #27
0
function embroidery2image($embroidery, $scale_post = 1, $scale_pre = false)
{
    // Create image
    $im = imagecreatetruecolor(ceil($embroidery->imageWidth * $scale_post), ceil($embroidery->imageHeight * $scale_post));
    imagesavealpha($im, true);
    imagealphablending($im, false);
    $color = imagecolorallocatealpha($im, 255, 255, 255, 127);
    imagefill($im, 0, 0, $color);
    // Draw stitches
    foreach ($embroidery->blocks as $block) {
        $color = imagecolorallocate($im, $block->color->r, $block->color->g, $block->color->b);
        $x = false;
        foreach ($block->stitches as $stitch) {
            if ($x !== false) {
                imageline($im, ($x - $embroidery->min->x) * $scale_post, ($y - $embroidery->min->y) * $scale_post, ($stitch->x - $embroidery->min->x) * $scale_post, ($stitch->y - $embroidery->min->y) * $scale_post, $color);
            }
            $x = $stitch->x;
            $y = $stitch->y;
        }
    }
    // Scale finished image
    if ($scale_pre) {
        $im2 = imagecreatetruecolor($embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre);
        imagesavealpha($im2, true);
        imagealphablending($im2, false);
        imagecopyresized($im2, $im, 0, 0, 0, 0, $embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre, $embroidery->imageWidth * $scale_post, $embroidery->imageHeight * $scale_post);
        imagedestroy($im);
        $im = $im2;
    }
    return $im;
}
Example #28
0
 public static function create()
 {
     $image = imagecreatetruecolor(100, 40) or die('cannot create canvas.<br>');
     $red = imagecolorallocate($image, 255, 0, 0);
     $green = imagecolorallocate($image, 0, 255, 0);
     $blue = imagecolorallocate($image, 0, 0, 255);
     $white = imagecolorallocate($image, 255, 255, 255);
     $black = imagecolorallocate($image, 0, 0, 0);
     imagefill($image, 0, 0, $white);
     imagerectangle($image, 1, 1, 99, 39, $black);
     $color = [$red, $green, $blue];
     for ($i = 1; $i <= 100; $i++) {
         imagesetpixel($image, mt_rand(2, 98), mt_rand(2, 38), $color[mt_rand(0, 2)]);
     }
     $source = "abcdefghigklmnopqrstuvwxyz0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ";
     $first = $source[mt_rand(0, 61)];
     $second = $source[mt_rand(0, 61)];
     $third = $source[mt_rand(0, 61)];
     $fourth = $source[mt_rand(0, 61)];
     $_SESSION['captcha'] = $first . $second . $third . $fourth;
     $font = dirname(dirname(__DIR__)) . '/../public/assets/fonts/SpicyRice.ttf';
     imagettftext($image, 20, mt_rand(-20, 20), 10, 30, $blue, $font, $first);
     imagettftext($image, 20, mt_rand(-20, 20), 30, 30, $blue, $font, $second);
     imagettftext($image, 20, mt_rand(-20, 20), 50, 30, $blue, $font, $third);
     imagettftext($image, 20, mt_rand(-20, 20), 70, 30, $blue, $font, $fourth);
     return imagejpeg($image);
 }
Example #29
-1
 function _qmd_img_list($pic_path = '', $user_uid = 0, $user_face = '', $topic_content = '', $topic_dateline)
 {
     header("Content-type: image/png");
     $bg = imagecreatefromjpeg($pic_path);
     $white = imagecolorallocate($bg, 00, 00, 00);
     $content = str_split($topic_content, 40);
     $content = array_iconv($this->Config['charset'], 'utf-8', $content);
     $topic_url = $this->Config['site_url'];
     $topic_date = array_iconv($this->Config['charset'], 'utf-8', $topic_dateline . ' | ' . '记事狗微博');
     imagettftext($bg, 9, 0, 130, 25, $white, "images/simsun.ttc", $content[0]);
     imagettftext($bg, 9, 0, 130, 45, $white, "images/simsun.ttc", $content[1]);
     imagettftext($bg, 9, 0, 130, 70, $white, "images/simsun.ttc", $topic_date);
     imagettftext($bg, 9, 0, 218, 90, $white, "images/simsun.ttc", $topic_url);
     $dst_im = imagecreatefromjpeg($bg);
     $dst_info = getimagesize($bg);
     $src = $user_face;
     $src_im = imagecreatefromjpeg($src);
     $src_info = getimagesize($src);
     $dst_x = 20;
     $dst_y = 12;
     $src_x = 0;
     $src_y = 0;
     $src_w = $src_info[0];
     $src_h = $src_info[1];
     $alpha = 100;
     imagecopymerge($bg, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $alpha);
     $image_path = RELATIVE_ROOT_PATH . 'images/qmd/' . face_path(MEMBER_ID);
     if (!is_dir($image_path)) {
         jio()->MakeDir($image_path);
     }
     $image_file = $image_path . MEMBER_ID . '_o.png';
     imagepng($bg, $image_file);
     imagedestroy($bg);
     return $image_file;
 }
Example #30
-1
 /**
  *	Génère l'avatar
  */
 public function run()
 {
     //On créer l'image avec les dimentions données
     $image = imagecreate($this->_size, $this->_size);
     //On créer la couleur en fonction du hash de la chaine de caractères
     $color = imagecolorallocate($image, hexdec(substr($this->_color, 0, 2)), hexdec(substr($this->_color, 2, 2)), hexdec(substr($this->_color, 4, 2)));
     //on défini le fond de l'image (blanc)
     $bg = imagecolorallocate($image, 255, 255, 255);
     //nombre de blocs à placer dans l'image (taille de l'image/taille des blocs)
     $c = $this->_size / $this->_blockSize;
     for ($x = 0; $x < ceil($c / 2); $x++) {
         for ($y = 0; $y < $c; $y++) {
             // Si le nombre est pair $pixel vaut true sinon $pixel vaut false
             $pixel = hexdec($this->_hash[(int) ($x * ceil($c / 2)) + $y]) % 2 == 0;
             if ($pixel) {
                 $pixelColor = $color;
             } else {
                 $pixelColor = $bg;
             }
             // On place chaque bloc de l'image
             //imagefilledrectangle($image, $x*$this->_blockSize, $y*$this->_blockSize, ($x+1)*$this->_blockSize, ($y+1)*$this->_blockSize, $pixelColor);
             //imagefilledrectangle($image, $this->_size-$x*$this->_blockSize, $y*$this->_blockSize, $this->_size-($x+1)*$this->_blockSize, ($y+1)*$this->_blockSize, $pixelColor);
             imagefilledrectangle($image, $x * $this->_blockSize, $y * $this->_blockSize, ($x + 1) * $this->_blockSize, ($y + 1) * $this->_blockSize, $pixelColor);
             imagefilledrectangle($image, $this->_size - $x * $this->_blockSize, $y * $this->_blockSize, $this->_size - ($x + 1) * $this->_blockSize, ($y + 1) * $this->_blockSize, $pixelColor);
         }
     }
     ob_start();
     imagepng($image);
     //on place l'image en mémoire
     $this->_image = ob_get_contents();
     ob_clean();
 }