Creating images with GD in php

Hi,

GD is a php extension that let you create images using code.between the images format are jpg, gif, pnf, swf,tiff and jpeg200. GD let you create images from 0, you can grab a image (from a full path or from a url) and edit them, draw things in it or mix it with other images, also you can write strings in different colors and fonts (it support ttf fonts).

i will share some examples manipulating images using GD:

1 color image:

 $im  = imagecreate (150, 30); // create a blank image
 $bgc = imagecolorallocate ($im, 255, 255, 255); // create a background color
 imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); // draw a rectangle of the size of the image with the background color

resize image:

// Load the images
$thumb = imagecreate($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize the images
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Showing the resized image
imagejpeg($thumb);

Mix 2 images:

// Create image instances
$dest = imagecreatefromgif('php.gif');
$src = imagecreatefromgif('php.gif');
// Copy and merge
imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);

i hope this help you in some way :D

Regards,

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Post

Still quiet here.sas

Leave a Response