| 1 |
<?php |
<?php |
| 2 |
// $Id: transparency.inc,v 1.3.2.3 2009/03/28 05:10:28 dman Exp $ |
// $Id: transparency.inc,v 1.3.2.4 2009/08/31 04:12:20 dman Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file Helper functions for the alpha action for imagecache |
* @file Helper functions for the alpha action for imagecache |
| 5 |
* |
* |
| 144 |
* To save a partially transparent image, the image resource must be switched to PNG. |
* To save a partially transparent image, the image resource must be switched to PNG. |
| 145 |
* ... or maybe not. Just flatten it yourself, or switch the format yourself. |
* ... or maybe not. Just flatten it yourself, or switch the format yourself. |
| 146 |
* This hack would produce side effects otherwise. |
* This hack would produce side effects otherwise. |
| 147 |
|
* |
| 148 |
|
* This algorithm runs maths per-pixel, and therefore is incredibly much more |
| 149 |
|
* inefficient than any native routine. Will kill the server on large images. |
| 150 |
*/ |
*/ |
| 151 |
function png_color2alpha(&$image, $color) { |
function png_color2alpha(&$image, $color) { |
| 152 |
#$image->info['extension'] = 'png'; |
#$image->info['extension'] = 'png'; |
| 153 |
#$image->info['mime_type'] = 'image/png'; |
#$image->info['mime_type'] = 'image/png'; |
| 154 |
$info = $image->info; |
$info = $image->info; |
| 155 |
if (!$info) return FALSE; |
if (!$info) return FALSE; |
|
|
|
| 156 |
$im1 = $image->resource; |
$im1 = $image->resource; |
| 157 |
|
|
| 158 |
imagesavealpha($im1, TRUE); |
imagesavealpha($im1, TRUE); |
| 161 |
if ($color) $background = hex_to_rgb($color); |
if ($color) $background = hex_to_rgb($color); |
| 162 |
$width = imagesx($im1); |
$width = imagesx($im1); |
| 163 |
$height = imagesy($im1); |
$height = imagesy($im1); |
| 164 |
|
|
| 165 |
|
if (($width*$height) > (600*600)) { |
| 166 |
|
watchdog('imagecache_actions', __FUNCTION__ . " on {$image->source}. Image is TOO BIG to run the per-pixel algorithm. Aborting."); |
| 167 |
|
return TRUE; |
| 168 |
|
} |
| 169 |
|
|
| 170 |
for ($i = 0; $i < $height; $i++) { //this loop traverses each row in the image |
for ($i = 0; $i < $height; $i++) { //this loop traverses each row in the image |
| 171 |
for ($j = 0; $j < $width; $j++) { //this loop traverses each pixel of each row |
for ($j = 0; $j < $width; $j++) { //this loop traverses each pixel of each row |
| 172 |
|
|