GD library |Terms ||PHP
GD library used to working with images.Create new,modify etc
Palette Images. 8 bits ,256 colors
Grayscale: 16 bit
truecolor: 24bit
FUNCTIONS
<?php
//CREATE IMAGE
imagecreate(width, height); //create new image
$image=imagecreate(500, 600);
imagecreatetruecolor(width, height); //same as imagecreate but it will produce high quality images
$image=imagecreatetruecolor(500, 600);
//LOAD IMAGES
imagecreatefrompng('stamp.png'); //LOAD PNG IMAGE
imagecreatefromjpeg('uos.jpg'); //LOAD JPG IMAGE
//COLORS
imagecolorallocate(image, red, green, blue); //return color in rgb then we can use it
$bg=imagecolorallocate($image, 11, 22, 33);
imagefill($image, 0, 0, $bg);
imagecolorallocatealpha(image, red, green, blue, alpha); //draw transperent color alpha has (0-127) where 127 is complete transparent
imagecolorat(image, x, y);// return color pixel at x,y
$result=imagecolorclosest($image, 11, 22, 222);
$result = imagecolorsforindex($image, $result);
$result = "({$result['red']}, {$result['green']}, {$result['blue']})";
print_r($result);
//DRAW TEXT OR SHAPES
imagefill(image, x, y, color); //fill image with given color
imagefilledarc(image, x_cordinate_center, y_cordinate_center, width, height, start_in_degree, end_in_degree, color style); //filled arc create ,styles are IMG_ARC_PIE ;IMG_ARC_CHORD ;IMG_ARC_NOFILL ;IMG_ARC_EDGED
imagefilledarc($image, 100, 100, 200, 200, 0, 270, 0x12aa44, IMG_ARC_PIE);
imagearc(image, x_cordinate_center, y_cordinate_center, width, height, start_in_degree, end_in_degree, color); //used to create arc or circle line
imagedashedline(image, x1, y1, x2, y2, color); //draw a dashed line
imagefilledellipse(image, cx, cy, width, height, color);
imagefilledrectangle(image, x1, y1, x2, y2, color);
bool imagepolygon( $image, $points, $num_points>=3, $color ); //draw a polygon
$potints= array(
150, 50, // Point 1 (x, y)
50, 250, // Point 2 (x, y)
250, 250 // Point 3 (x, y)
);
imagechar(image, font (1-5 builtin), x-cordinate, y-cordinate, charter, color); //used to draw only one charter horizontly, use loop for string
imagecharup($image,5, 250, 150-10*$i, 'Q', 0x987878);
imagestring(image, font, x, y, string, color); // draw text horizontly
imagestringup(image, font, x, y, string, color); //draw font vertically
//UTILS
imagecopy(dst_im, src_im_that_is_fit_on_dest, dst_x, dst_y, src_x, src_y, src_w, src_h) //use to copy two or more images to 1
imagecopy($dest, $src, 0, 0, 0, 0, 500, 300);
imagecrop ( $image, $rect );
$img=imagecrop($im, ['x' => 0, 'y' => 0, 'width' => 250, 'height' => 150]);
bool imageflip( $image, $mode ); //IMG_FLIP_HORIZONTAL ;IMG_FLIP_VERTICAL ;IMG_FLIP_BOTH
bool imagegif( $image [,$to]) //create gif image $to is used for path if not given raw stream used
bool imagelayereffect( $image, $effect ) //IMG_EFFECT_REPLACE ; IMG_EFFECT_ALPHABLEND ;IMG_EFFECT_NORMAL ; IMG_EFFECT_OVERLAY; IMG_EFFECT_MULTIPLY
imagetruecolortopalette(image, dither:true_or_flase, maxNoOfColors); //convert true color image to pallete
bool imagesetthickness( $image, $thicknessInPixels ); //thickness for lines ie rectangle lines, polygon lines etc
imagesx(image); //size of image x axis
imagesy(image); //size of image y axis
imagepng($im,"saveme.png"); //save image
imagejpeg($img, "test.jpg", 100); //save image + quality 0-100
?>