Source Code for GD library image function

gd.thumbnail

Hello my php friends,

I have written a class library using gb for a lot of image functions:

  • Resize
  • Round Edge
  • Rotate
  • Watermark

Click details for Souce code:

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Class Thump
{
public function Resize($image,$new_width,$new_height=0)
{
$old_width = imagesx($image);
$old_height= imagesy($image);
if($new_height==0) // if the height is not specified....calculate the relative height
$new_height= $new_width * $old_height / $old_width ;
$new_image= imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
return $new_image;
}
public function RoundImage($image,$corner_radius=20,$topleft=true,$topright=true,$bottomleft=true,$bottomright=true)
{
$corner_source = imagecreatefrompng(sfConfig::get('sf_root_dir').'/web/images/rounded_corner.png');
$corner_width = imagesx($corner_source);
$corner_height = imagesy($corner_source);
$corner_resized = ImageCreateTrueColor($corner_radius, $corner_radius);
ImageCopyResampled($corner_resized, $corner_source, 0, 0, 0, 0, $corner_radius, $corner_radius, $corner_width, $corner_height);
$corner_width = imagesx($corner_resized);
$corner_height = imagesy($corner_resized);
$width = imagesx($image);
$height= imagesy($image);
$white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0);
// Top-left corner
if ($topleft == true) {
$dest_x = 0;
$dest_y = 0;
imagecolortransparent($corner_resized, $black);
imagecopymerge($image, $corner_resized, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
}
// Bottom-left corner
if ($bottomleft == true) {
$dest_x = 0;
$dest_y = $height - $corner_height;
$rotated = imagerotate($corner_resized, 90, 0);
imagecolortransparent($rotated, $black);
imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
}
// Bottom-right corner
if ($bottomright == true) {
$dest_x = $width - $corner_width;
$dest_y = $height - $corner_height;
$rotated = imagerotate($corner_resized, 180, 0);
imagecolortransparent($rotated, $black);
imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
}
// Top-right corner
if ($topright == true) {
$dest_x = $width - $corner_width;
$dest_y = 0;
$rotated = imagerotate($corner_resized, 270, 0);
imagecolortransparent($rotated, $black);
imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
}
return $image;
}
public function RotateImage($image,$angle=15)
{
$white = ImageColorAllocate($image,255,255,255);
$image = imagerotate($image, $angle, $white);
return $image;
}
public function AddWaterMark($image,$logo)
{
$WM=new transparentWatermark($logo);
$WM->setStampPosition ( 400, 400);
$image = $WM->markImageFile ( $image) ;
return $image;
}
}
?>
2 Comments

2 Responses to “Source Code for GD library image function”

  1. divakar April 23, 2008 at 11:04 am #

    how to install ffmpeg or ffmpeg-php in windows.I want step by step instructions. please tell me. and where to get ffmpeg source code.

Leave a Reply

More in Downloads, php, php source code (118 of 122 articles)


I think you people know the importance of gd library in Php. A lot of image functions are there with ...