International PHP Conference Munich 2025

Voting

: max(five, one)?
(Example: nine)

The Note You're Voting On

administrador(ensaimada)sphoera(punt)com
19 years ago
I've made a function to make full color gradients:

<?php

// The image must be in truecolor mode!!
function gradient_region($img, $x, $y, $width, $height,$src_color, $dest_color=0){
$src_alpha = ($src_color) >> 24;
$src_red = ($src_color & 0xFF0000) >> 16;
$src_green = ($src_color & 0x00FF00) >> 8;
$src_blue = ($src_color & 0x0000FF);

$dest_alpha = ($dest_color) >> 24;
$dest_red = ($dest_color & 0xFF0000) >> 16;
$dest_green = ($dest_color & 0x00FF00) >> 8;
$dest_blue = ($dest_color & 0x0000FF);


$inc_alpha = ($dest_alpha - $src_alpha) / $width;
$inc_red = ($dest_red - $src_red)/$width;
$inc_green = ($dest_green - $src_green)/$width;
$inc_blue = ($dest_blue - $src_blue)/$width;

// If you need more performance, the step can be increased
for ($i=0;$i<$width;$i++){
$src_alpha += $inc_alpha;
$src_blue += $inc_blue;
$src_green += $inc_green;
$src_red += $inc_red;
imagefilledrectangle($img,
$x+$i,$y,
$x+$i,$y+$height,
imagecolorallocatealpha($img,
$src_red,$src_green,$src_blue,$src_alpha));
}
}
?>

More functions at http://www.sphoera.com

<< Back to user notes page

To Top