示例#1
0
function drawRating($rating) {
   $width = $_GET['width'];
   $height = $_GET['height'];
   if ($width == 0) {
     $width = 102;
   }
   if ($height == 0) {
     $height = 10;
   }

   $rating = $_GET['rating'];
   $ratingbar = (($rating/100)*$width)-2;

   $image = imagecreate($width,$height);
   //colors
   $back = ImageColorAllocate($image,255,255,255);
   $border = ImageColorAllocate($image,0,0,0);
   $red = ImageColorAllocate($image,255,60,75);
   $fill = ImageColorAllocate($image,44,81,150);

   ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
   ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
   ImageRectangle($image,0,0,$width-1,$height-1,$border);
   imagePNG($image);
   imagedestroy($image);
}
示例#2
0
function drawRating()
{
    $width = $_GET['width'];
    $height = $_GET['height'];
    if ($width == 0) {
        $width = 200;
    }
    if ($height == 0) {
        $height = 7;
    }
    $rating = $_GET['rating'];
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height);
    $fill = ImageColorAllocate($image, 0, 255, 0);
    if ($rating > 49) {
        $fill = ImageColorAllocate($image, 255, 255, 0);
    }
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 255, 128, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 255, 0, 0);
    }
    $back = ImageColorAllocate($image, 205, 205, 205);
    $border = ImageColorAllocate($image, 0, 0, 0);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
示例#3
0
 function saveImage($filename)
 {
     $image =& $this->image;
     if ($this->getStatus()) {
         imagePNG($image, $filename);
     }
 }
示例#4
0
function drawRating($rating)
{
    $width = 300;
    $height = 15;
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height);
    $fill = ImageColorAllocate($image, 67, 219, 0);
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 233, 233, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 197, 6, 6);
    }
    if ($rating > 100) {
        echo "Overload Error!";
        exit;
    }
    $back = ImageColorAllocate($image, 255, 255, 255);
    $border = ImageColorAllocate($image, 151, 151, 151);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
示例#5
0
 public function save_img($path)
 {
     // Resize
     if ($this->resize) {
         $this->img_output = ImageCreateTrueColor($this->x_output, $this->y_output);
         ImageCopyResampled($this->img_output, $this->img_input, 0, 0, 0, 0, $this->x_output, $this->y_output, $this->x_input, $this->y_input);
     }
     // Save JPEG
     if ($this->format == "JPG" or $this->format == "JPEG") {
         if ($this->resize) {
             imageJPEG($this->img_output, $path, $this->quality);
         } else {
             copy($this->img_src, $path);
         }
     } elseif ($this->format == "PNG") {
         if ($this->resize) {
             imagePNG($this->img_output, $path);
         } else {
             copy($this->img_src, $path);
         }
     } elseif ($this->format == "GIF") {
         if ($this->resize) {
             imageGIF($this->img_output, $path);
         } else {
             copy($this->img_src, $path);
         }
     }
 }
示例#6
0
 public function createImage($text = '', $fontSize = 5)
 {
     // GD's built-in fonts are numbered from 1 - 5
     $font_size = $fontSize;
     // Calculate the appropriate image size
     $image_height = intval(imageFontHeight($font_size) * 2);
     $image_width = intval(strlen($text) * imageFontWidth($font_size) * 1.3);
     // Create the image
     $image = imageCreate($image_width, $image_height);
     // Create the colors to use in the image
     // gray background
     $back_color = imageColorAllocate($image, 216, 216, 216);
     // blue text
     $text_color = imageColorAllocate($image, 0, 0, 255);
     // black border
     $rect_color = imageColorAllocate($image, 0, 0, 0);
     // Figure out where to draw the text
     // (Centered horizontally and vertically
     $x = ($image_width - imageFontWidth($font_size) * strlen($text)) / 2;
     $y = ($image_height - imageFontHeight($font_size)) / 2;
     // Draw the text
     imageString($image, $font_size, $x, $y, $text, $text_color);
     // Draw a black border
     imageRectangle($image, 0, 0, imageSX($image) - 1, imageSY($image) - 1, $rect_color);
     // Send the image to the browser
     header('Content-Type: image/png');
     imagePNG($image);
     imageDestroy($image);
 }
示例#7
0
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);
}
示例#8
0
 function create($text)
 {
     $img = imagecreatefrompng("skins/icon.png");
     $black = imageColorAllocate($img, 0, 0, 0);
     $white = imageColorAllocate($img, 255, 255, 255);
     imageString($img, 5, 20, 3, $text, $white);
     imagePNG($img);
 }
示例#9
0
function sendImage($img)
{
    if (!$img) {
        sendErrorImageAndDie("Invalid image object");
    } else {
        header("Content-type: image/png");
        imagePNG($img);
        imageDestroy($img);
    }
}
示例#10
0
 function Generate($imgName)
 {
     //        $this->GenStr();
     $this->img = imageCreate(200, 50);
     $this->GenColors();
     $this->PutLetters();
     $this->PutEllipses();
     $this->PutLines();
     imagePNG($this->img, $imgName);
     return $this->strCheck;
 }
 public function getRawPNG()
 {
     if ($this->avatar) {
         ob_start();
         imagePNG($this->avatar);
         $raw = ob_get_contents();
         ob_end_clean();
         return $raw;
     }
     return false;
 }
示例#12
0
文件: image.php 项目: Norvares/nemex
 public function write($path, $quality, $format = 'jpg')
 {
     if (!$this->image) {
         return false;
     }
     if ($format === 'png') {
         imagePNG($this->image, $path);
     } else {
         imageJPEG($this->image, $path, $quality);
     }
     return true;
 }
示例#13
0
function text2image($height, $text)
{
header("Content-type: image/png");
$width = $height * strlen($text)/ 5 * 2;
$font = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf";
$image = imageCreate($width, $height);
$backgroundColor = imageColorAllocate($image, 255, 255, 255);
$textColor = imageColorAllocate($image, 0, 0, 0);
imagefttext($image, $height/2, 0, 0, $height/10*9, $textColor, $font, $text); 
imageInterlace($image, 1);
imageColorTransparent($image, $backgroundColor);
imagePNG($image);
}
示例#14
0
 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);
 }
示例#15
0
 function save($save)
 {
     /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
     $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"], $this->img["tinggi_thumb"]);
     @imagecopyresized($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         imageJPEG($this->img["des"], "{$save}", $this->img["quality"]);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         imagePNG($this->img["des"], "{$save}");
     } elseif ($this->img["format"] == "GIF") {
         //GIF
         imageGIF($this->img["des"], "{$save}");
     } elseif ($this->img["format"] == "WBMP") {
         //WBMP
         imageWBMP($this->img["des"], "{$save}");
     }
 }
示例#16
0
 function save($save = "", $gd_version)
 {
     if ($gd_version == 2) {
         $this->img["des"] = imagecreatetruecolor($this->img["lebar_thumb"], $this->img["tinggi_thumb"]);
         @imagecopyresampled($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);
     }
     if ($gd_version == 1) {
         $this->img["des"] = imagecreate($this->img["lebar_thumb"], $this->img["tinggi_thumb"]);
         @imagecopyresized($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);
     }
     if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") {
         //JPEG
         imageJPEG($this->img["des"], "{$save}", $this->img["quality"]);
     } elseif ($this->img["format"] == "PNG") {
         //PNG
         imagePNG($this->img["des"], "{$save}");
     }
     // Memory cleanup
     @imageDestroy($this->img["des"]);
 }
示例#17
0
 public function sendImage($img)
 {
     if (!$img) {
         $this->sendErrorImageAndDie("Invalid image object");
     } else {
         if ($this->base64ImageOut) {
             ob_start();
             imagePNG($img);
             $image_data = ob_get_contents();
             ob_end_clean();
             // return the base64 encoded image,
             // this way it doesn't send an image/png header
             // and simply returns the string
             return $image_data_base64 = base64_encode($image_data);
         } else {
             // The entire page that instantiates the class becomes an image
             header("Content-type: image/png");
             imagePNG($img);
             imageDestroy($img);
         }
     }
 }
 /**
  * Create PNG of font name written with font TTF.
  */
 public function generate_image()
 {
     $width = $height = $font_size = $left_margin = $background_color = $font_color = false;
     extract($this->preview_attributes, EXTR_IF_EXISTS);
     // Text Mask
     $mask = imageCreate($width, $height);
     $background = imageColorAllocate($mask, $background_color[0], $background_color[1], $background_color[2]);
     $foreground = imageColorAllocate($mask, $font_color[0], $font_color[1], $font_color[2]);
     $ttf_path = $this->font->maybe_get_remote_ttf();
     if (!file_exists($ttf_path)) {
         wp_die('Could not load $ttf_path: ' . $ttf_path);
     }
     // Text
     $y = $this->get_centered_y_coordinate($font_size, $ttf_path, $this->font->family);
     imagettftext($mask, $font_size, 0, $left_margin, $y, $foreground, $ttf_path, $this->font->family);
     // White fill
     $white = imageCreate($width, $height);
     $background = imageColorAllocate($white, $background_color[0], $background_color[1], $background_color[2]);
     // Image
     $image = imagecreatetruecolor($width, $height);
     imagesavealpha($image, true);
     imagefill($image, 0, 0, imagecolorallocatealpha($image, 0, 0, 0, 127));
     // Apply Mask to Image
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $alpha = imagecolorsforindex($mask, imagecolorat($mask, $x, $y));
             $alpha = 127 - floor($alpha['red'] / 2);
             $color = imagecolorsforindex($white, imagecolorat($white, $x, $y));
             imagesetpixel($image, $x, $y, imagecolorallocatealpha($image, $color['red'], $color['green'], $color['blue'], $alpha));
         }
     }
     ob_start();
     imagePNG($image);
     $image = ob_get_clean();
     $this->save_image($image);
     // header("Content-type: image/png");
     // echo $image;
 }
示例#19
0
function drawRating()
{
    if (isset($_GET['rating'])) {
        $rating = $_GET['rating'];
    } else {
        $rating = 0;
    }
    if (isset($_GET['width'])) {
        $width = $_GET['width'];
    } else {
        $width = 170;
    }
    if (isset($_GET['height'])) {
        $height = $_GET['height'];
    } else {
        $height = 5;
    }
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height) or die("Cannot Create image");
    $fill = ImageColorAllocate($image, 0, 255, 0);
    if ($rating > 49) {
        $fill = ImageColorAllocate($image, 255, 255, 0);
    }
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 255, 128, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 255, 0, 0);
    }
    $back = ImageColorAllocate($image, 205, 205, 205);
    $border = ImageColorAllocate($image, 0, 0, 0);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
示例#20
0
        }
    }
    ($code = $plugins->load('images_rating_start')) ? eval($code) : null;
    $ratings = array();
    while ($row = $db->fetch_assoc($result)) {
        $ratings[] = $row['rating'];
    }
    $ratingcounter = count($ratings);
    if ($ratingcounter > 0) {
        $rating = round((array_sum($ratings) / $ratingcounter + 1) * ($width / 2));
        $avg = array_sum($ratings) / $ratingcounter;
    } else {
        $rating = $width / 2;
        $avg = 0;
    }
    $five = ceil(($avg + 1) * 2.5);
    header("Content-type: image/png");
    $image = imagecreate($width + 2, $height + 2);
    $back = ImageHexColorAllocate($image, 'ffffff');
    $fill = ImageHexColorAllocate($image, $colors[$five]);
    $border = ImageHexColorAllocate($image, '000000');
    ImageFilledRectangle($image, 1, 1, $width, $height, $back);
    ImageFilledRectangle($image, 1, 1, $rating, $height, $fill);
    ImageRectangle($image, 0, 0, $width + 1, $height + 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
($code = $plugins->load('images_end')) ? eval($code) : null;
$slog->updatelogged();
$zeitmessung = t2();
$db->close();
示例#21
0
 /**
  * Write the image after being processed
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __write(&$tmp)
 {
     // try to guess format from extension
     //
     if (!$tmp->save) {
         $p = pathinfo($tmp->target_filename);
         ($tmp->save = $this->__mime_metaphone[metaphone($p['extension'])]) || ($tmp->save = $this->__mime_soundex[soundex($p['extension'])]);
     }
     $result = false;
     $imgContent = null;
     switch ($tmp->save) {
         case 'image/gif':
             imageTrueColorToPalette($tmp->target, true, 256);
             ob_start();
             $result = @imageGIF($tmp->target);
             $imgContent = ob_get_clean();
             break;
         case 'image/jpeg':
             ob_start();
             $result = @imageJPEG($tmp->target, null, ASIDO_GD_JPEG_QUALITY);
             $imgContent = ob_get_clean();
             break;
         case 'image/wbmp':
             ob_start();
             $result = @imageWBMP($tmp->target);
             $imgContent = ob_get_clean();
             break;
         default:
         case 'image/png':
             imageSaveAlpha($tmp->target, true);
             imageAlphaBlending($tmp->target, false);
             ob_start();
             $result = @imagePNG($tmp->target, null, ASIDO_GD_PNG_QUALITY);
             $imgContent = ob_get_clean();
             break;
     }
     if ($result) {
         jimport('joomla.filesystem.file');
         JFile::write($tmp->target_filename, $imgContent);
     }
     @$this->__destroy_source($tmp);
     @$this->__destroy_target($tmp);
     return $result;
 }
示例#22
0
 /**
  * Creates a new image given an original path, a new path, a target width and height.
  * Optionally crops image to exactly match given width and height.
  * @params string $originalPath, string $newpath, int $width, int $height, bool $crop
  * @return void
  */
 public function create($originalPath, $newPath, $width, $height, $crop = false)
 {
     // first, we grab the original image. We shouldn't ever get to this function unless the image is valid
     $imageSize = @getimagesize($originalPath);
     $oWidth = $imageSize[0];
     $oHeight = $imageSize[1];
     $finalWidth = 0;
     //For cropping, this is really "scale to width before chopping extra height"
     $finalHeight = 0;
     //For cropping, this is really "scale to height before chopping extra width"
     $do_crop_x = false;
     $do_crop_y = false;
     $crop_src_x = 0;
     $crop_src_y = 0;
     // first, if what we're uploading is actually smaller than width and height, we do nothing
     if ($oWidth < $width && $oHeight < $height) {
         $finalWidth = $oWidth;
         $finalHeight = $oHeight;
         $width = $oWidth;
         $height = $oHeight;
     } else {
         if ($crop && ($height >= $oHeight && $width <= $oWidth)) {
             //crop to width only -- don't scale anything
             $finalWidth = $oWidth;
             $finalHeight = $oHeight;
             $height = $oHeight;
             $do_crop_x = true;
         } else {
             if ($crop && ($width >= $oWidth && $height <= $oHeight)) {
                 //crop to height only -- don't scale anything
                 $finalHeight = $oHeight;
                 $finalWidth = $oWidth;
                 $width = $oWidth;
                 $do_crop_y = true;
             } else {
                 // otherwise, we do some complicated stuff
                 // first, we divide original width and height by new width and height, and find which difference is greater
                 $wDiff = $oWidth / $width;
                 $hDiff = $oHeight / $height;
                 if (!$crop && $wDiff > $hDiff) {
                     //no cropping, just resize down based on target width
                     $finalWidth = $width;
                     $finalHeight = $oHeight / $wDiff;
                 } else {
                     if (!$crop) {
                         //no cropping, just resize down based on target height
                         $finalWidth = $oWidth / $hDiff;
                         $finalHeight = $height;
                     } else {
                         if ($crop && $wDiff > $hDiff) {
                             //resize down to target height, THEN crop off extra width
                             $finalWidth = $oWidth / $hDiff;
                             $finalHeight = $height;
                             $do_crop_x = true;
                         } else {
                             if ($crop) {
                                 //resize down to target width, THEN crop off extra height
                                 $finalWidth = $width;
                                 $finalHeight = $oHeight / $wDiff;
                                 $do_crop_y = true;
                             }
                         }
                     }
                 }
             }
         }
     }
     //Calculate cropping to center image
     if ($do_crop_x) {
         /*
         //Get half the difference between scaled width and target width,
         // and crop by starting the copy that many pixels over from the left side of the source (scaled) image.
         $nudge = ($width / 10); //I have *no* idea why the width isn't centering exactly -- this seems to fix it though.
         $crop_src_x = ($finalWidth / 2.00) - ($width / 2.00) + $nudge;
         */
         $crop_src_x = round(($oWidth - $width * $oHeight / $height) * 0.5);
     }
     if ($do_crop_y) {
         /*
         //Calculate cropping...
         //Get half the difference between scaled height and target height,
         // and crop by starting the copy that many pixels down from the top of the source (scaled) image.
         $crop_src_y = ($finalHeight / 2.00) - ($height / 2.00);
         */
         $crop_src_y = round(($oHeight - $height * $oWidth / $width) * 0.5);
     }
     //create "canvas" to put new resized and/or cropped image into
     if ($crop) {
         $image = @imageCreateTrueColor($width, $height);
     } else {
         $image = @imageCreateTrueColor($finalWidth, $finalHeight);
     }
     switch ($imageSize[2]) {
         case IMAGETYPE_GIF:
             $im = @imageCreateFromGIF($originalPath);
             break;
         case IMAGETYPE_JPEG:
             $im = @imageCreateFromJPEG($originalPath);
             break;
         case IMAGETYPE_PNG:
             $im = @imageCreateFromPNG($originalPath);
             break;
     }
     if ($im) {
         // Better transparency - thanks for the ideas and some code from mediumexposure.com
         if ($imageSize[2] == IMAGETYPE_GIF || $imageSize[2] == IMAGETYPE_PNG) {
             $trnprt_indx = imagecolortransparent($im);
             // If we have a specific transparent color
             if ($trnprt_indx >= 0) {
                 // Get the original image's transparent color's RGB values
                 $trnprt_color = imagecolorsforindex($im, $trnprt_indx);
                 // Allocate the same color in the new image resource
                 $trnprt_indx = imagecolorallocate($image, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                 // Completely fill the background of the new image with allocated color.
                 imagefill($image, 0, 0, $trnprt_indx);
                 // Set the background color for new image to transparent
                 imagecolortransparent($image, $trnprt_indx);
             } else {
                 if ($imageSize[2] == IMAGETYPE_PNG) {
                     // Turn off transparency blending (temporarily)
                     imagealphablending($image, false);
                     // Create a new transparent color for image
                     $color = imagecolorallocatealpha($image, 0, 0, 0, 127);
                     // Completely fill the background of the new image with allocated color.
                     imagefill($image, 0, 0, $color);
                     // Restore transparency blending
                     imagesavealpha($image, true);
                 }
             }
         }
         $res = @imageCopyResampled($image, $im, 0, 0, $crop_src_x, $crop_src_y, $finalWidth, $finalHeight, $oWidth, $oHeight);
         if ($res) {
             switch ($imageSize[2]) {
                 case IMAGETYPE_GIF:
                     $res2 = imageGIF($image, $newPath);
                     break;
                 case IMAGETYPE_JPEG:
                     $compression = defined('AL_THUMBNAIL_JPEG_COMPRESSION') ? AL_THUMBNAIL_JPEG_COMPRESSION : 80;
                     $res2 = imageJPEG($image, $newPath, $compression);
                     break;
                 case IMAGETYPE_PNG:
                     $res2 = imagePNG($image, $newPath);
                     break;
             }
         }
     }
 }
 function convertImage($type)
 {
     /* check the converted image type availability,
        if it is not available, it will be casted to jpeg :) */
     $validtype = $this->validateType($type);
     if ($this->output) {
         /* show the image  */
         switch ($validtype) {
             case 'jpeg':
             case 'jpg':
                 header("Content-type: image/jpeg");
                 if ($this->imtype == 'gif' or $this->imtype == 'png') {
                     $image = $this->replaceTransparentWhite($this->im);
                     imageJPEG($image);
                 } else {
                     imageJPEG($this->im);
                 }
                 break;
             case 'gif':
                 header("Content-type: image/gif");
                 imageGIF($this->im);
                 break;
             case 'png':
                 header("Content-type: image/png");
                 imagePNG($this->im);
                 break;
             case 'wbmp':
                 header("Content-type: image/vnd.wap.wbmp");
                 imageWBMP($this->im);
                 break;
             case 'swf':
                 header("Content-type: application/x-shockwave-flash");
                 $this->imageSWF($this->im);
                 break;
         }
         // Memory cleanup
         @imagedestroy($this->im);
     } else {
         /* save the image  */
         switch ($validtype) {
             case 'jpeg':
             case 'jpg':
                 if ($this->imtype == 'gif' or $this->imtype == 'png') {
                     /* replace transparent with white */
                     $image = $this->replaceTransparentWhite($this->im);
                     imageJPEG($image, $this->finalFilePath . $this->imname . ".jpg");
                 } else {
                     imageJPEG($this->im, $this->finalFilePath . $this->imname . ".jpg");
                 }
                 break;
             case 'gif':
                 imageGIF($this->im, $this->finalFilePath . $this->imname . ".gif");
                 break;
             case 'png':
                 imagePNG($this->im, $this->finalFilePath . $this->imname . ".png");
                 break;
             case 'wbmp':
                 imageWBMP($this->im, $this->finalFilePath . $this->imname . ".wbmp");
                 break;
             case 'swf':
                 $this->imageSWF($this->im, $this->finalFilePath . $this->imname . ".swf");
                 break;
         }
         // Memory cleanup
         @imagedestroy($this->im);
     }
 }
示例#24
0
 function watermark($target, $watermark_file, $ext, $watermarkstatus = 9, $watermarktrans = 50)
 {
     $gdsurporttype = array();
     if (function_exists('imageAlphaBlending') && function_exists('getimagesize')) {
         if (function_exists('imageGIF')) {
             $gdsurporttype[] = 'gif';
         }
         if (function_exists('imagePNG')) {
             $gdsurporttype[] = 'png';
         }
         if (function_exists('imageJPEG')) {
             $gdsurporttype[] = 'jpg';
             $gdsurporttype[] = 'jpeg';
         }
     }
     if ($gdsurporttype && in_array($ext, $gdsurporttype)) {
         $attachinfo = getimagesize($target);
         $watermark_logo = imageCreateFromGIF($watermark_file);
         $logo_w = imageSX($watermark_logo);
         $logo_h = imageSY($watermark_logo);
         $img_w = $attachinfo[0];
         $img_h = $attachinfo[1];
         $wmwidth = $img_w - $logo_w;
         $wmheight = $img_h - $logo_h;
         $animatedgif = 0;
         if ($attachinfo['mime'] == 'image/gif') {
             $fp = fopen($target, 'rb');
             $targetcontent = fread($fp, 9999999);
             fclose($fp);
             $animatedgif = strpos($targetcontent, 'NETSCAPE2.0') === FALSE ? 0 : 1;
         }
         if ($watermark_logo && $wmwidth > 10 && $wmheight > 10 && !$animatedgif) {
             switch ($attachinfo['mime']) {
                 case 'image/jpeg':
                     $dst_photo = imageCreateFromJPEG($target);
                     break;
                 case 'image/gif':
                     $dst_photo = imageCreateFromGIF($target);
                     break;
                 case 'image/png':
                     $dst_photo = imageCreateFromPNG($target);
                     break;
             }
             switch ($watermarkstatus) {
                 case 1:
                     $x = +5;
                     $y = +5;
                     break;
                 case 2:
                     $x = ($logo_w + $img_w) / 2;
                     $y = +5;
                     break;
                 case 3:
                     $x = $img_w - $logo_w - 5;
                     $y = +5;
                     break;
                 case 4:
                     $x = +5;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 5:
                     $x = ($logo_w + $img_w) / 2;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 6:
                     $x = $img_w - $logo_w;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 7:
                     $x = +5;
                     $y = $img_h - $logo_h - 5;
                     break;
                 case 8:
                     $x = ($logo_w + $img_w) / 2;
                     $y = $img_h - $logo_h;
                     break;
                 case 9:
                     $x = $img_w - $logo_w - 5;
                     $y = $img_h - $logo_h - 5;
                     break;
             }
             imageAlphaBlending($watermark_logo, FALSE);
             imagesavealpha($watermark_logo, TRUE);
             imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
             switch ($attachinfo['mime']) {
                 case 'image/jpeg':
                     imageJPEG($dst_photo, $target);
                     break;
                 case 'image/gif':
                     imageGIF($dst_photo, $target);
                     break;
                 case 'image/png':
                     imagePNG($dst_photo, $target);
                     break;
             }
         }
     }
 }
示例#25
0
<?php

include 'phprandom.php';
$img = imageCreateTrueColor(256, 256);
$colors = array();
for ($i = 0; $i < 256; $i++) {
    $colors[$i] = imageColorAllocate($img, $i, $i, $i);
}
for ($i = 0; $i < 256; $i++) {
    $random = PHPRandom::getBinary(256);
    for ($j = 0; $j < 256; $j++) {
        $value = ord(substr($random, $j, 1));
        imageSetPixel($img, $i, $j, $colors[$value]);
    }
}
header('Content-Type: image/png');
imagePNG($img);
imageDestroy($img);
 /**
  * Saves the image to a given filename, if no filename is given then a default is created.
  *
  * @param string $save The new image filename.
  */
 public function save($save = "")
 {
     //save thumb
     if (empty($save)) {
         $save = strtolower("./thumb." . $this->image["outputformat"]);
     } else {
         $this->image["outputformat"] = preg_replace("/.*\\.(.*)\$/", "\\1", $save);
         //$this->image["outputformat"] = preg_replace(".*\.(.*)$", "\\1", $save);
         $this->image["outputformat"] = strtoupper($this->image["outputformat"]);
     }
     $this->createResampledImage();
     if ($this->image["outputformat"] == "JPG" || $this->image["outputformat"] == "JPEG") {
         //JPEG
         imageJPEG($this->image["des"], $save, $this->image["quality"]);
     } elseif ($this->image["outputformat"] == "PNG") {
         //PNG
         imagePNG($this->image["des"], $save, 0);
     } elseif ($this->image["outputformat"] == "GIF") {
         //GIF
         imageGIF($this->image["des"], $save);
     } elseif ($this->image["outputformat"] == "WBMP") {
         //WBMP
         imageWBMP($this->image["des"], $save);
     }
 }
示例#27
0
        }
    }
}
foreach ($sky as $az => $x) {
    foreach ($sky[$az] as $el => $y) {
        $e = array(-1, $el, $az, $sky[$az][$el]['avg'], -1);
        if ($cellmode) {
            cellplot($im, $sz, $C, $cellsize, $e);
        } else {
            splot($im, $sz, $C, $radius, $filled, $e);
        }
    }
}
skygrid($im, $sz, $C);
# redraw grid over satellites
imagePNG($im, $argv[2]);
imageDestroy($im);
exit(0);
###########################################################################
function colorsetup($im)
{
    $C['white'] = imageColorAllocate($im, 255, 255, 255);
    $C['ltgray'] = imageColorAllocate($im, 191, 191, 191);
    $C['mdgray'] = imageColorAllocate($im, 127, 127, 127);
    $C['dkgray'] = imageColorAllocate($im, 63, 63, 63);
    $C['black'] = imageColorAllocate($im, 0, 0, 0);
    $C['red'] = imageColorAllocate($im, 255, 0, 0);
    $C['brightgreen'] = imageColorAllocate($im, 0, 255, 0);
    $C['darkgreen'] = imageColorAllocate($im, 0, 192, 0);
    $C['blue'] = imageColorAllocate($im, 0, 0, 255);
    $C['cyan'] = imageColorAllocate($im, 0, 255, 255);
示例#28
0
 function output()
 {
     if (ALLOC_GD_IMAGE_TYPE == "PNG") {
         header("Content-type: image/png");
         imagePNG($this->image);
     } else {
         header("Content-type: image/gif");
         imageGIF($this->image);
     }
 }
 function convertImage($type)
 {
     /* check the converted image type availability,
        if it is not available, it will be casted to jpeg :) */
     $validtype = $this->validateType($type);
     if ($this->output) {
         /* show the image  */
         switch ($validtype) {
             case 'jpeg':
                 // Added jpe
             // Added jpe
             case 'jpe':
             case 'jpg':
                 header("Content-type: image/jpeg");
                 if ($this->imtype == 'gif' or $this->imtype == 'png') {
                     $image = $this->replaceTransparentWhite($this->im);
                     @imageJPEG($image);
                 } else {
                     @imageJPEG($this->im);
                 }
                 break;
             case 'gif':
                 header("Content-type: image/gif");
                 @imageGIF($this->im);
                 break;
             case 'png':
                 header("Content-type: image/png");
                 @imagePNG($this->im);
                 break;
             case 'wbmp':
                 header("Content-type: image/vnd.wap.wbmp");
                 @imageWBMP($this->im);
                 break;
             case 'swf':
                 header("Content-type: application/x-shockwave-flash");
                 $this->imageSWF($this->im);
                 break;
         }
     } else {
         // Added Support vor different directory
         if (DEFINED('V_TEMP_DIR')) {
             $this->newimname = V_TEMP_DIR . $this->imname . '.' . $validtype;
         } else {
             $this->newimname = $this->imname . '.' . $validtype;
         }
         /* save the image  */
         switch ($validtype) {
             case 'jpeg':
                 // Added jpe
             // Added jpe
             case 'jpe':
             case 'jpg':
                 if ($this->imtype == 'gif' or $this->imtype == 'png') {
                     /* replace transparent with white */
                     $image = $this->replaceTransparentWhite($this->im);
                     @imageJPEG($image, $this->newimname);
                 } else {
                     @imageJPEG($this->im, $this->newimname);
                 }
                 break;
             case 'gif':
                 @imageGIF($this->im, $this->newimname);
                 break;
             case 'png':
                 @imagePNG($this->im, $this->newimname);
                 break;
             case 'wbmp':
                 @imageWBMP($this->im, $this->newimname);
                 break;
             case 'swf':
                 $this->imageSWF($this->im, $this->newimname);
                 break;
         }
     }
 }
示例#30
0
文件: captcha.php 项目: vcgato29/poff
        $offsetLeft = $imageOffset[2];
    } else {
        $offsetLeft = $imageOffset[4];
    }
    $charPosition = $offsetLeft - 2;
    $charOffset++;
}
$captchaResult = imageCreateTrueColor($charPosition + 7, $height);
imagecopy($captchaResult, $captcha, 0, 0, 0, 0, $charPosition + 7, $height);
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-disposition: inline; filename=captcha.png\n");
header('Content-type: image/png');
imagePNG($captchaResult);
function make_string($length = 5)
{
    $valid1 = "aeiouy12345";
    $valid2 = "bcdfghjklmnprstvwxz6789";
    for ($a = 0; $a < $length; $a++) {
        if ($a % 2) {
            $charList = $valid1;
        } else {
            $charList = $valid2;
        }
        $b = rand(0, strlen($charList) - 1);
        $rndstr .= $charList[$b];
    }
    return $rndstr;
}