18 require_once dirname(__FILE__).
'/../general/file_system.inc';
48 require_once dirname(__FILE__).
'/../colour/colour.inc';
51 trigger_error(
'Unable to open image for recolourizing: '.$input);
59 'r' => ($cb_array[
'r'] - $ca_array[
'r']),
60 'g' => ($cb_array[
'g'] - $ca_array[
'g']),
61 'b' => ($cb_array[
'b'] - $ca_array[
'b']),
65 $palette_size = imageColorsTotal($image);
67 for ($i = 0; $i < $palette_size; $i++) {
70 $colour = imageColorsForIndex ($image, $i);
71 $fraction = (double) ($colour[
'red'] / 256);
73 $r = (int) (255 * ($ca_array[
'r'] + $diff[
'r'] * $fraction));
74 $g = (int) (255 * ($ca_array[
'g'] + $diff[
'g'] * $fraction));
75 $b = (int) (255 * ($ca_array[
'b'] + $diff[
'b'] * $fraction));
76 imageColorSet($image,$i, $r, $g, $b);
99 public static function remapColour($input, $output, $colour_map, $tolerance=0.2)
101 require_once dirname(__FILE__).
'/../colour/colour.inc';
104 trigger_error(
'Unable to open image for recolourizing: '.$input);
109 $palette_size = imageColorsTotal($image);
112 for ($i = 0; $i < $palette_size; $i++) {
113 $colour = imageColorsForIndex($image, $i);
117 $r = $rgb[
'r'] * 255;
118 $g = $rgb[
'g'] * 255;
119 $b = $rgb[
'b'] * 255;
120 imagecolorset($image,$i, $r, $g, $b);
125 imageDestroy($image);
141 public static function resize($input, $output, $w, $h)
147 switch (get_file_type($output)) {
149 $d_img = imageCreate($w, $h);
151 $colorTransparent = imagecolortransparent($s_img);
152 if ($colorTransparent > -1) {
153 imagepalettecopy($d_img,$s_img);
154 imagefill($d_img,0,0,$colorTransparent);
155 imagecolortransparent($d_img, $colorTransparent);
160 $d_img = imageCreateTrueColor($w, $h);
161 imagealphablending( $d_img,
false );
162 imagesavealpha( $d_img,
true );
165 $d_img = imageCreateTrueColor($w, $h);
170 $ret_val = ImageCopyResampled($d_img, $s_img, 0, 0, 0, 0, $w, $h, imageSx($s_img), imageSy($s_img));
171 imageDestroy($s_img);
178 imageDestroy($d_img);
194 switch (get_file_type($input)) {
196 if ($image = imageCreateFromGif ($input)) {
199 trigger_error(
'Unable to open GIF : '.$input);
203 if ($image = imageCreateFromPNG($input)) {
206 trigger_error(
'Unable to open PNG : '.$input);
211 if ($image = imageCreateFromJPEG($input)) {
214 trigger_error(
'Unable to open JPEG : '.$input);
218 trigger_error(
'Unable to open unknown image type : '.$input);
235 public static function toFile($image, $output, $jpeg_quality=80)
238 switch (get_file_type($output)) {
240 if (imageGif($image, $output))
return true;
244 if (imagePNG($image, $output))
return true;
249 if (imageJPEG($image, $output, $jpeg_quality)) {
255 trigger_error(
'Unable to write unknown image type : '.$output, E_USER_WARNING);
259 trigger_error(
'Unable to output image : '.$output, E_USER_WARNING);