spacer
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

gd_infospacer spacer Using imagecopymerge to create a translucent watermark
[edit] Last updated: Fri, 22 Mar 2013

view this page in

GD and Image Functions

Table of Contents

  • gd_info — Retrieve information about the currently installed GD library
  • getimagesize — Get the size of an image
  • getimagesizefromstring — Get the size of an image from a string
  • image_type_to_extension — Get file extension for image type
  • image_type_to_mime_type — Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype
  • image2wbmp — Output image to browser or file
  • imagealphablending — Set the blending mode for an image
  • imageantialias — Should antialias functions be used or not
  • imagearc — Draws an arc
  • imagechar — Draw a character horizontally
  • imagecharup — Draw a character vertically
  • imagecolorallocate — Allocate a color for an image
  • imagecolorallocatealpha — Allocate a color for an image
  • imagecolorat — Get the index of the color of a pixel
  • imagecolorclosest — Get the index of the closest color to the specified color
  • imagecolorclosestalpha — Get the index of the closest color to the specified color + alpha
  • imagecolorclosesthwb — Get the index of the color which has the hue, white and blackness
  • imagecolordeallocate — De-allocate a color for an image
  • imagecolorexact — Get the index of the specified color
  • imagecolorexactalpha — Get the index of the specified color + alpha
  • imagecolormatch — Makes the colors of the palette version of an image more closely match the true color version
  • imagecolorresolve — Get the index of the specified color or its closest possible alternative
  • imagecolorresolvealpha — Get the index of the specified color + alpha or its closest possible alternative
  • imagecolorset — Set the color for the specified palette index
  • imagecolorsforindex — Get the colors for an index
  • imagecolorstotal — Find out the number of colors in an image's palette
  • imagecolortransparent — Define a color as transparent
  • imageconvolution — Apply a 3x3 convolution matrix, using coefficient and offset
  • imagecopy — Copy part of an image
  • imagecopymerge — Copy and merge part of an image
  • imagecopymergegray — Copy and merge part of an image with gray scale
  • imagecopyresampled — Copy and resize part of an image with resampling
  • imagecopyresized — Copy and resize part of an image
  • imagecreate — Create a new palette based image
  • imagecreatefromgd2 — Create a new image from GD2 file or URL
  • imagecreatefromgd2part — Create a new image from a given part of GD2 file or URL
  • imagecreatefromgd — Create a new image from GD file or URL
  • imagecreatefromgif — Create a new image from file or URL
  • imagecreatefromjpeg — Create a new image from file or URL
  • imagecreatefrompng — Create a new image from file or URL
  • imagecreatefromstring — Create a new image from the image stream in the string
  • imagecreatefromwbmp — Create a new image from file or URL
  • imagecreatefromxbm — Create a new image from file or URL
  • imagecreatefromxpm — Create a new image from file or URL
  • imagecreatetruecolor — Create a new true color image
  • imagedashedline — Draw a dashed line
  • imagedestroy — Destroy an image
  • imageellipse — Draw an ellipse
  • imagefill — Flood fill
  • imagefilledarc — Draw a partial arc and fill it
  • imagefilledellipse — Draw a filled ellipse
  • imagefilledpolygon — Draw a filled polygon
  • imagefilledrectangle — Draw a filled rectangle
  • imagefilltoborder — Flood fill to specific color
  • imagefilter — Applies a filter to an image
  • imagefontheight — Get font height
  • imagefontwidth — Get font width
  • imageftbbox — Give the bounding box of a text using fonts via freetype2
  • imagefttext — Write text to the image using fonts using FreeType 2
  • imagegammacorrect — Apply a gamma correction to a GD image
  • imagegd2 — Output GD2 image to browser or file
  • imagegd — Output GD image to browser or file
  • imagegif — Output image to browser or file
  • imagegrabscreen — Captures the whole screen
  • imagegrabwindow — Captures a window
  • imageinterlace — Enable or disable interlace
  • imageistruecolor — Finds whether an image is a truecolor image
  • imagejpeg — Output image to browser or file
  • imagelayereffect — Set the alpha blending flag to use the bundled libgd layering effects
  • imageline — Draw a line
  • imageloadfont — Load a new font
  • imagepalettecopy — Copy the palette from one image to another
  • imagepng — Output a PNG image to either the browser or a file
  • imagepolygon — Draws a polygon
  • imagepsbbox — Give the bounding box of a text rectangle using PostScript Type1 fonts
  • imagepsencodefont — Change the character encoding vector of a font
  • imagepsextendfont — Extend or condense a font
  • imagepsfreefont — Free memory used by a PostScript Type 1 font
  • imagepsloadfont — Load a PostScript Type 1 font from file
  • imagepsslantfont — Slant a font
  • imagepstext — Draws a text over an image using PostScript Type1 fonts
  • imagerectangle — Draw a rectangle
  • imagerotate — Rotate an image with a given angle
  • imagesavealpha — Set the flag to save full alpha channel information (as opposed to single-color transparency) when saving PNG images
  • imagesetbrush — Set the brush image for line drawing
  • imagesetpixel — Set a single pixel
  • imagesetstyle — Set the style for line drawing
  • imagesetthickness — Set the thickness for line drawing
  • imagesettile — Set the tile image for filling
  • imagestring — Draw a string horizontally
  • imagestringup — Draw a string vertically
  • imagesx — Get image width
  • imagesy — Get image height
  • imagetruecolortopalette — Convert a true color image to a palette image
  • imagettfbbox — Give the bounding box of a text using TrueType fonts
  • imagettftext — Write text to the image using TrueType fonts
  • imagetypes — Return the image types supported by this PHP build
  • imagewbmp — Output image to browser or file
  • imagexbm — Output XBM image to browser or file
  • iptcembed — Embeds binary IPTC data into a JPEG image
  • iptcparse — Parse a binary IPTC block into single tags.
  • jpeg2wbmp — Convert JPEG image file to WBMP image file
  • png2wbmp — Convert PNG image file to WBMP image file


gd_infospacer spacer Using imagecopymerge to create a translucent watermark
[edit] Last updated: Fri, 22 Mar 2013
 
spacer add a note User Contributed Notes GD and Image Functions - [12 notes]
up
down
1
felipensp at gmail dot com
7 years ago
Representation decimal of a color in hexadecimal for use on functions of library GD.

<?php

   
// Representation hexadecimal
   
$var = '#FFFFFF';

    function
getRgbFromGd($color_hex) {

        return
array_map('hexdec', explode('|', wordwrap(substr($color_hex, 1), 2, '|', 1)));

    }
   
   
print_r(getRgbFromGd($var));

   
// Output: Array ( [0] => 255 [1] => 255 [2] => 255 )

?>
up
down
0
chuckstudios at gmail dot com
4 years ago
I wrote a simple function to convert an image resource to PGM (portable graymap) in order to feed it to an OCR program. It works just like the rest of the image output functions, and will convert to grayscale for you:

<?php
   
function imagepgm($image, $filename = null)
    {
       
$pgm = "P5 ".imagesx($image)." ".imagesy($image)." 255\n";
        for(
$y = 0; $y < imagesy($image); $y++)
        {
            for(
$x = 0; $x < imagesx($image); $x++)
            {
               
$colors = imagecolorsforindex($image, imagecolorat($image, $x, $y));
               
$pgm .= chr(0.3 * $colors["red"] + 0.59 * $colors["green"] + 0.11 * $colors["blue"]);
            }
        }
        if(
$filename != null)
        {
           
$fp = fopen($filename, "w");
           
fwrite($fp, $pgm);
           
fclose($fp);
        }
        else
        {
            return
$pgm;
        }
    }
?>
up
down
0
dev at kingthief dot com
4 years ago
I've developed a well-documented, fairly rock-solid API for creating on the fly, anti-aliased, rounded corner images, including full alpha transparency support for all you PNG lovers.

go here to download the package:
sourceforge.net/projects/roundedphp/

go here for a live demo:
dev.kingthief.com/demos/roundedphp/

Installation is similar to PEAR.

Enjoy!
up
down
0
ph_corp at yahoo dot fr
5 years ago
<?php

/**
HSL/RGB conversion functions
very useful for a lot of applications
**/

function RBGtoHSL ( $R, $G, $B )
{

   
$var_R = ( $R / 255 );
   
$var_G = ( $G / 255 );
   
$var_B = ( $B / 255 );

   
$var_Min = min( $var_R, $var_G, $var_B )
   
$var_Max = max( $var_R, $var_G, $var_B )
   
$del_Max = $var_Max - $var_Min

    $L
= ( $var_Max + $var_Min ) / 2;

    if (
$del_Max == 0 )
    {
      
$H = 0
       $S
= 0
   
}
    else
    {
        if (
$L < 0.5 )
        {
           
$S = $del_Max / ( $var_Max + $var_Min );
        }
        else
        {
           
$S = $del_Max / ( 2 - $var_Max - $var_Min );
        }

       
$del_R = ( ( ( $var_Max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
       
$del_G = ( ( ( $var_Max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
       
$del_B = ( ( ( $var_Max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;

        if (
$var_R == $var_Max )
        {
           
$H = $del_B - $del_G;
        }
        else if (
$var_G == $var_Max )
        {
           
$H = ( 1 / 3 ) + $del_R - $del_B;
        }
        else if (
$var_B == $var_Max )
        {
           
$H = ( 2 / 3 ) + $del_G - $del_R;
        }

        if (
$H < 0 )
        {
           
$H += 1;
        }
        if (
$H > 1 )
        {
           
$H -= 1
       
}

    }

    return array(
$H, $S, $L );

}

function
HuetoRGB( $v1, $v2, $vH )
{
    if (
$vH < 0 )
    {
       
$vH += 1;
    }
    if (
$vH > 1 )
    {
       
$vH -= 1;
    }
    if ( (
6 * $vH ) < 1 )
    {
        return (
$v1 + ( $v2 - $v1 ) * 6 * $vH );
    }
    if ( (
2 * $vH ) < 1 )
    {
        return (
$v2 );
    }
    if ( (
3 * $vH ) < 2 )
    {
        return (
$v1 + ( $v2 - $v1 ) * ( ( 2 / 3 ) - $vH ) * 6 );
    }
    return (
$v1 )
}

function
HSLtoRGB ( $H, $S, $L )
{

    if (
$S == 0 )
    {
       
$R = $L * 255;
       
$G = $L * 255;
       
$B = $L * 255;
    }
    else
    {
        if (
$L < 0.5 )
        {
           
$var_2 = $L * ( 1 + $S );
        }
        else
        {
           
$var_2 = ( $L + $S ) - ( $S * $L );
        }

       
$var_1 = 2 * $L - $var_2;

       
$R = 255 * HuetoRGB( $var_1, $var_2, $H + ( 1 / 3 ) );
       
$G = 255 * HuetoRGB( $var_1, $var_2, $H );
       
$B = 255 * HuetoRGB( $var_1, $var_2, $H - ( 1 / 3 ) );
    }

    return array(
$R, $G, $B );

}

function
distance ( $R1, $G1, $B1, $R2, $G2, $B2 )
{
   
$result = sqrt ( ( $R1 - $R2 )*( $R1 - $R2 ) + ( $G1 - $G2 )*( $G1 - $G2 ) + ( $B1 - $B2 )*( $B1 - $B2 ) );
    return (
$result );
}

?>
up
down
0
shd at earthling dot net
6 years ago
If you happen to need a way to output a Windows BMP file (e.g. when using the PEAR ExcelWriter), feel free to use the following code:

<?php
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.