LEPTON CMS 7.0.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.make_thumb.php
Go to the documentation of this file.
1<?php
2
18// include secure.php to protect this file and the whole CMS!
19if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
20if (defined('LEPTON_PATH')) {
21 include LEPTON_PATH.SEC_FILE;
22} else {
23 $oneback = "../";
24 $root = $oneback;
25 $level = 1;
26 while (($level < 10) && (!file_exists($root.SEC_FILE))) {
27 $root .= $oneback;
28 $level += 1;
29 }
30 if (file_exists($root.SEC_FILE)) {
31 include $root.SEC_FILE;
32 } else {
33 trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
34 }
35}
36// end include secure file
37
38
43function make_thumb( $source, $destination, $size )
44{
45 // Check if GD is installed
46 if(extension_loaded('gd') && function_exists('imageCreateFromJpeg') && function_exists('imageCreateFromPng'))
47 {
48 // Get the type
49 $aTemp = explode(".", $source);
50 $sMimeType = strtolower( array_pop($aTemp) );
51
52 // First figure out the size of the thumbnail
53 list($original_x, $original_y) = getimagesize($source);
54 if ($original_x > $original_y)
55 {
56 $thumb_w = $size;
57 $thumb_h = $original_y*($size/$original_x);
58 }
59 if ($original_x < $original_y)
60 {
61 $thumb_w = $original_x*($size/$original_y);
62 $thumb_h = $size;
63 }
64 if ($original_x == $original_y)
65 {
66 $thumb_w = $size;
67 $thumb_h = $size;
68 }
69
70 $thumb_w = intval($thumb_w);
71 $thumb_h = intval($thumb_h);
72
73 // Now make the thumbnail
74 switch( $sMimeType )
75 {
76 case "jpeg":
77 case "jpg":
78
79 $source = imageCreateFromJpeg($source);
80 $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
81 imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
82 imagejpeg($dst_img, $destination, 90);
83
84 break;
85
86 case "png":
87
88 $source = imagecreatefrompng ($source);
89 $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
90
91 imagealphablending( $dst_img, false );
92 imagesavealpha( $dst_img, true );
93
94 imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
95 imagepng($dst_img, $destination);
96
97 break;
98
99 case "gif":
100
101 $source = imagecreatefromgif ($source);
102 $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
103 imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
104 imagegif($dst_img, $destination);
105 break;
106
107 default:
108 return false;
109 }
110
111 // Clear memory
112 imagedestroy($dst_img);
113 imagedestroy($source);
114
115 return true;
116 }
117 else
118 {
119 return false;
120 }
121}
make_thumb( $source, $destination, $size)