{"flag":true,"single":true,"pageTitle":"GD library |Terms ||PHP","post":{"id":331,"user_id":"1","slug":"gd-library-terms-php-fadr","title":"GD library |Terms ||PHP","body":"<p>GD library used to working with images.Create new,modify etc<\/p>\r\n<p><strong>Palette Images. <\/strong>8 bits ,256 colors<\/p>\r\n<p><strong>Grayscale: <\/strong>16 bit<\/p>\r\n<p><strong>truecolor: <\/strong>24bit<\/p>\r\n<p><strong>FUNCTIONS<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>&lt;?php\r\n\/\/CREATE IMAGE\r\n\r\nimagecreate(width, height);\t\/\/create new image\r\n\t$image=imagecreate(500, 600);\r\nimagecreatetruecolor(width, height);\t\/\/same as imagecreate but it will produce high quality images\r\n\t$image=imagecreatetruecolor(500, 600);\r\n\r\n\/\/LOAD IMAGES\r\n\r\nimagecreatefrompng('stamp.png'); \/\/LOAD PNG IMAGE\r\nimagecreatefromjpeg('uos.jpg'); \/\/LOAD JPG IMAGE\r\n\r\n\/\/COLORS \r\n\r\nimagecolorallocate(image, red, green, blue); \/\/return color in rgb then we can use it\r\n\t$bg=imagecolorallocate($image, 11, 22, 33);\r\n\timagefill($image, 0, 0, $bg);  \r\n\r\nimagecolorallocatealpha(image, red, green, blue, alpha);  \/\/draw transperent color alpha has (0-127) where 127 is complete transparent\r\n\r\nimagecolorat(image, x, y);\/\/ return color pixel at x,y\r\n\t\r\n\r\n$result=imagecolorclosest($image, 11, 22, 222);\r\n\t$result = imagecolorsforindex($image, $result); \r\n\t$result = \"({$result['red']}, {$result['green']}, {$result['blue']})\";\r\n  \tprint_r($result);\r\n\r\n\/\/DRAW TEXT OR SHAPES \r\n\r\nimagefill(image, x, y, color);\t\/\/fill image with given color\r\n\r\nimagefilledarc(image, x_cordinate_center, y_cordinate_center, width, height, start_in_degree, end_in_degree, color style);\t\/\/filled arc create ,styles are IMG_ARC_PIE ;IMG_ARC_CHORD ;IMG_ARC_NOFILL ;IMG_ARC_EDGED\r\n\timagefilledarc($image, 100, 100, 200, 200, 0, 270, 0x12aa44, IMG_ARC_PIE);\r\n\r\nimagearc(image, x_cordinate_center, y_cordinate_center, width, height, start_in_degree, end_in_degree, color);\t\/\/used to create arc or circle line\r\n\r\nimagedashedline(image, x1, y1, x2, y2, color);\t\/\/draw a dashed line\r\n\r\nimagefilledellipse(image, cx, cy, width, height, color);\r\n\r\nimagefilledrectangle(image, x1, y1, x2, y2, color);\r\n\r\nbool imagepolygon( $image, $points, $num_points&gt;=3, $color ); \/\/draw a polygon\r\n\t$potints= array( \r\n            150,  50, \/\/ Point 1 (x, y) \r\n            50, 250,  \/\/ Point 2 (x, y) \r\n            250,  250 \/\/ Point 3 (x, y) \r\n        ); \r\n\r\nimagechar(image, font (1-5 builtin), x-cordinate, y-cordinate, charter, color); \/\/used to draw only one charter horizontly, use loop for string\r\n\timagecharup($image,5, 250, 150-10*$i, 'Q', 0x987878);  \r\n\r\nimagestring(image, font, x, y, string, color); \/\/ draw text horizontly\r\n\r\nimagestringup(image, font, x, y, string, color);\t\/\/draw font vertically\r\n\r\n\/\/UTILS\r\n\r\nimagecopy(dst_im, src_im_that_is_fit_on_dest, dst_x, dst_y, src_x, src_y, src_w, src_h)\t\/\/use to copy two or more images to 1\r\n\t imagecopy($dest, $src, 0, 0, 0, 0, 500, 300); \r\n\r\nimagecrop ( $image, $rect );\r\n\t$img=imagecrop($im, ['x' =&gt; 0, 'y' =&gt; 0, 'width' =&gt; 250, 'height' =&gt; 150]);\r\n\r\n\r\nbool imageflip( $image, $mode );\t\/\/IMG_FLIP_HORIZONTAL ;IMG_FLIP_VERTICAL ;IMG_FLIP_BOTH \r\n\r\nbool imagegif( $image [,$to])\t\/\/create gif image  $to is used for path if not given raw stream used\r\n\r\nbool imagelayereffect( $image, $effect ) \/\/IMG_EFFECT_REPLACE ; IMG_EFFECT_ALPHABLEND ;IMG_EFFECT_NORMAL ; IMG_EFFECT_OVERLAY; IMG_EFFECT_MULTIPLY\r\n\r\nimagetruecolortopalette(image, dither:true_or_flase, maxNoOfColors);\t\/\/convert true color image to pallete\r\n\r\nbool imagesetthickness( $image, $thicknessInPixels );\t\/\/thickness for lines ie rectangle lines, polygon lines etc\r\n\r\nimagesx(image);\t\/\/size of image x axis\r\n\r\nimagesy(image);\t\/\/size of image y axis\r\n\r\nimagepng($im,\"saveme.png\"); \/\/save image\r\n imagejpeg($img, \"test.jpg\", 100); \/\/save image + quality 0-100\r\n?&gt;<\/code><\/pre>\r\n<p>&nbsp;<\/p>","category_id":"1","is_private":"0","created_at":"2026-01-07T11:29:54.000000Z","updated_at":"2026-01-07T11:29:54.000000Z","category":{"id":1,"user_id":"1","name":"PHP","slug":"php-3ius","parent_id":null,"created_at":"2023-03-14T03:58:19.000000Z","updated_at":"2023-03-14T03:58:19.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"GD library used to working with images.Create new,modify etc Palette Images. 8 bits ,256 colors Grayscale: 16 bit truecolor: 24bit FUNCTIONS - GD library |Terms ||PHP (Updated: January 7, 2026) - Read more about GD library |Terms ||PHP at my programming site [SITE]","categories":[]}