示例#1
0
$bg_color = $bg_color[0];
if (!$bg_color) {
    $bg_color = ccc;
    //defaults to gray if no background color is set.
}
$background = new color();
$background->set_hex($bg_color);
//Find the foreground color which is always after the 3rd slash in the url.
$fg_color = explode('.', $x_pieces[2]);
$fg_color = $fg_color[0];
if (!$fg_color) {
    $fg_color = 00;
    //defaults to black if no foreground color is set.
}
$foreground = new color();
$foreground->set_hex($fg_color);
//Determine the file format. This can be anywhere in the URL.
$file_format = 'gif';
preg_match_all('/(png|jpg|jpeg)/', $x, $result);
if ($result[0][0]) {
    $file_format = $result[0][0];
}
//Find the image dimensions
if (substr_count($x_pieces[0], ':') > 1) {
    die('Too many colons in the dimension paramter! There should be 1 at most.');
}
if (strstr($x_pieces[0], ':') && !strstr($x_pieces[0], 'x')) {
    die('To calculate a ratio you need to provide a height!');
}
$dimensions = explode('x', $x_pieces[0]);
//dimensions are always the first paramter in the URL.
示例#2
0
function addBorderpng($im, $border = 1, $color = 'eee')
{
    $width = imagesx($im);
    $height = imagesy($im);
    $img_adj_width = $width - 2 * $border;
    $img_adj_height = $height - 2 * $border;
    $newimage = imagecreatetruecolor($width, $height);
    $bg_color = new color();
    $bg_color->set_hex($color);
    $background = imageColorAllocate($newimage, $bg_color->get_rgb('r'), $bg_color->get_rgb('g'), $bg_color->get_rgb('b'));
    imagefilledrectangle($newimage, 0, 0, $width, $height, $background);
    imagecopyresampled($newimage, $im, $border, $border, 0, 0, $img_adj_width, $img_adj_height, $width, $height);
    imagedestroy($im);
    return $newimage;
}