本文整理汇总了PHP中imagePNG函数的典型用法代码示例。如果您正苦于以下问题:PHP imagePNG函数的具体用法?PHP imagePNG怎么用?PHP imagePNG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagePNG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: drawRating
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: drawRating
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: saveImage
function saveImage($filename)
{
$image =& $this->image;
if ($this->getStatus()) {
imagePNG($image, $filename);
}
}
示例4: drawRating
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: save_img
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: createImage
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: TextToImage
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: create
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: sendImage
function sendImage($img)
{
if (!$img) {
sendErrorImageAndDie("Invalid image object");
} else {
header("Content-type: image/png");
imagePNG($img);
imageDestroy($img);
}
}
示例10: Generate
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;
}
示例11: getRawPNG
public function getRawPNG()
{
if ($this->avatar) {
ob_start();
imagePNG($this->avatar);
$raw = ob_get_contents();
ob_end_clean();
return $raw;
}
return false;
}
示例12: write
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: text2image
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: draw
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: save
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}");
}
}