function canvas ($width,$height,$alpha=false) { $this->processed = ImageCreateTrueColor($width,$height); if ($alpha) { ImageAlphaBlending($this->processed, false); $transparent = ImageColorAllocateAlpha($this->processed, 0, 0, 0, 127); ImageFill($this->processed, 0, 0, $transparent); ImageSaveAlpha($this->processed, true); $this->alpha = true; } }
function __construct() { header('Pragma: public'); header('Cache-Control: max-age=86400'); header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 86400)); header('Content-Type: image/png'); $this->image = ImageCreateTrueColor(96, 96); ImageSaveAlpha($this->image, true); ImageFill($this->image, 0, 0, ImageColorAllocateAlpha($this->image, 0, 0, 0, 127)); }
function imageConvolution($src, $filter, $filter_div, $offset) { if ($src == NULL) { return 0; } $sx = imagesx($src); $sy = imagesy($src); $srcback = ImageCreateTrueColor($sx, $sy); ImageAlphaBlending($srcback, false); ImageAlphaBlending($src, false); ImageCopy($srcback, $src, 0, 0, 0, 0, $sx, $sy); if ($srcback == NULL) { return 0; } for ($y = 0; $y < $sy; ++$y) { for ($x = 0; $x < $sx; ++$x) { $new_r = $new_g = $new_b = 0; $alpha = imagecolorat($srcback, @$pxl[0], @$pxl[1]); $new_a = $alpha >> 24; for ($j = 0; $j < 3; ++$j) { $yv = min(max($y - 1 + $j, 0), $sy - 1); for ($i = 0; $i < 3; ++$i) { $pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv); $rgb = imagecolorat($srcback, $pxl[0], $pxl[1]); $new_r += ($rgb >> 16 & 0xff) * $filter[$j][$i]; $new_g += ($rgb >> 8 & 0xff) * $filter[$j][$i]; $new_b += ($rgb & 0xff) * $filter[$j][$i]; $new_a += ((0x7f000000 & $rgb) >> 24) * $filter[$j][$i]; } } $new_r = $new_r / $filter_div + $offset; $new_g = $new_g / $filter_div + $offset; $new_b = $new_b / $filter_div + $offset; $new_a = $new_a / $filter_div + $offset; $new_r = $new_r > 255 ? 255 : ($new_r < 0 ? 0 : $new_r); $new_g = $new_g > 255 ? 255 : ($new_g < 0 ? 0 : $new_g); $new_b = $new_b > 255 ? 255 : ($new_b < 0 ? 0 : $new_b); $new_a = $new_a > 127 ? 127 : ($new_a < 0 ? 0 : $new_a); $new_pxl = ImageColorAllocateAlpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a); if ($new_pxl == -1) { $new_pxl = ImageColorClosestAlpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a); } if ($y >= 0 && $y < $sy) { imagesetpixel($src, $x, $y, $new_pxl); } } } imagedestroy($srcback); return 1; }
public function show_image($width = 88, $height = 31) { if (isSet($this->tt_font)) { if (!file_exists($this->tt_font)) exit('The path to the true type font is incorrect.'); } if ($this->chars_number < 3) exit('The captcha code must have at least 3 characters'); $string = $this->generate_string(); $im = ImageCreate($width, $height); /* Set a White & Transparent Background Color */ $bg = ImageColorAllocateAlpha($im, 255, 255, 255, 127); // (PHP 4 >= 4.3.2, PHP 5) ImageFill($im, 0, 0, $bg); /* Border Color */ if ($this->border_color) { list($red, $green, $blue) = explode(',', $this->border_color); $border = ImageColorAllocate($im, $red, $green, $blue); ImageRectangle($im, 0, 0, $width - 1, $height - 1, $border); } $textcolor = ImageColorAllocate($im, 191, 120, 120); $y = 24; for ($i = 0; $i < $this->chars_number; $i++) { $char = $string[$i]; $factor = 15; $x = ($factor * ($i + 1)) - 6; $angle = rand(1, 15); imagettftext($im, $this->font_size, $angle, $x, $y, $textcolor, $this->tt_font, $char); } $_SESSION['security_code'] = md5($string); /* Output the verification image */ header("Content-type: image/png"); ImagePNG($im); exit; }
$yi = ImageSY($image); // find the size of the text $box = ImageFTBBox($size, $angle, $font, $text, $extrainfo); $xr = abs(max($box[2], $box[4])); $yr = abs(max($box[5], $box[7])); // compute centering $x = intval(($xi - $xr) / 2); $y = intval(($yi + $yr) / 2); return array($x, $y); } $_GET['text'] = 'I <3 PHP!'; // Configuration settings $image = ImageCreateFromPNG(__DIR__ . '/button.png'); $text = $_GET['text']; $font = '/Library/Fonts/Hei.ttf'; $size = 24; $color = 0x0; $angle = 0; // Print-centered text list($x, $y) = ImageFTCenter($image, $size, $angle, $font, $text); ImageFTText($image, $size, $angle, $x, $y, $color, $font, $text); // Preserve Transparency ImageColorTransparent($image, ImageColorAllocateAlpha($image, 0, 0, 0, 127)); ImageAlphaBlending($image, false); ImageSaveAlpha($image, true); // Send image header('Content-type: image/png'); ImagePNG($image); // Clean up ImagePSFreeFont($font); ImageDestroy($image);
<?php $p = floatval($_REQUEST['p']); header("Content-type: image/png"); $im = imagecreatetruecolor(320, 240); imagealphablending($im, false); imagesavealpha($im, true); $bg = ImageColorAllocateAlpha($im, 255, 255, 255, 127); // (PHP 4 >= 4.3.2, PHP 5) ImageFill($im, 0, 0, $bg); $ink = imagecolorallocate($im, 255, 216, 132); imagefilledellipse($im, 160, 120, 200, 150, $ink); $ink = imagecolorallocate($im, 224, 144, 0); imagefilledarc($im, 160, 120, 200, 150, 0, 360 * $p, $ink, IMG_ARC_PIE); $ink = imagecolorallocate($im, 255, 255, 255); // imagestring($im, 5, 160, 120, strval(intval($p * 100)) . "%", $ink); imagepng($im); imagedestroy($im);
/** * Generer un histrogramme des couleurs RVB de l'image * * @param object $im * @return string */ function image_histogramme($im) { include_spip("inc/filtres_images"); $fonction = array('image_histo', func_get_args()); $image = image_valeurs_trans($im, "histo", "png", $fonction); if (!$image) { return ""; } $x_i = $image["largeur"]; $y_i = $image["hauteur"]; $surface = $x_i * $y_i; if (!test_traiter_image($image["fichier"], $x_i, $y_i)) { return; } $im = $image["fichier"]; $dest = $image["fichier_dest"]; $creer = $image["creer"]; if ($creer) { $im = $image["fonction_imagecreatefrom"]($im); $im_ = imagecreatetruecolor(258, 130); @imagealphablending($im_, false); @imagesavealpha($im_, true); $color_t = ImageColorAllocateAlpha($im_, 255, 255, 255, 50); imagefill($im_, 0, 0, $color_t); $col_poly = imagecolorallocate($im_, 60, 60, 60); imagepolygon($im_, array(0, 0, 257, 0, 257, 129, 0, 129), 4, $col_poly); $val_gris = $val_r = $val_g = $val_b = array(); for ($x = 0; $x < $x_i; $x++) { for ($y = 0; $y < $y_i; $y++) { $rgb = ImageColorAt($im, $x, $y); $a = $rgb >> 24 & 0xff; $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; $a = (127 - $a) / 127; $a = 1; $gris = round($a * ($r + $g + $b) / 3); $r = round($a * $r); $g = round($a * $g); $b = round($a * $b); $val_gris[$gris]++; $val_r[$r]++; $val_g[$g]++; $val_b[$b]++; } } $max = max(max($val_gris), max($val_r), max($val_g), max($val_b)); // Limiter Max si trop concentr'e $max = min($max, round($surface * 0.03)); $rapport = 127 / $max; $gris_50 = imagecolorallocate($im_, 170, 170, 170); $gris_70 = imagecolorallocate($im_, 60, 60, 60); for ($i = 0; $i < 256; $i++) { $val = 127 - round(max(0, $val_gris[$i]) * $rapport); imageline($im_, $i + 1, 128, $i + 1, $val + 1, $gris_50); imagesetpixel($im_, $i + 1, $val + 1, $gris_70); } $bleu = imagecolorallocate($im_, 0, 0, 255); for ($i = 0; $i < 256; $i++) { $val = 127 - round(max(0, $val_b[$i]) * $rapport); if ($i == 0) { imagesetpixel($im_, $i + 1, $val + 1, $bleu); } else { imageline($im_, $i, $val_old + 1, $i + 1, $val + 1, $bleu); } $val_old = $val; } $green = imagecolorallocate($im_, 0, 255, 0); for ($i = 0; $i < 256; $i++) { $val = 127 - round(max(0, $val_g[$i]) * $rapport); if ($i == 0) { imagesetpixel($im_, $i + 1, $val + 1, $green); } else { imageline($im_, $i, $val_old + 1, $i + 1, $val + 1, $green); } $val_old = $val; } $rouge = imagecolorallocate($im_, 255, 0, 0); for ($i = 0; $i < 256; $i++) { $val = 127 - round(max(0, $val_r[$i]) * $rapport); if ($i == 0) { imagesetpixel($im_, $i + 1, $val + 1, $rouge); } else { imageline($im_, $i, $val_old + 1, $i + 1, $val + 1, $rouge); } $val_old = $val; } $image["fonction_image"]($im_, "{$dest}"); imagedestroy($im_); imagedestroy($im); } return _image_ecrire_tag($image, array('src' => $dest, 'width' => 258, 'height' => 130)); }
public function text($text, $x = 0, $y = 0, $font = '', $font_size = 18) { $box = ImageTTFBbox($font_size, 0, $font, $text); $text_width = abs($box[4] - $box[0]); $text_height = abs($box[5] - $box[1]); $wm = @ImageCreateTrueColor($text_width, $text_height); ImageAlphaBlending($wm, FALSE); if ($this->background_color) { $bgcolor = $this->background_color; } else { $bgcolor = ImageColorAllocateAlpha($wm, 0, 0, 0, 127); } ImageFilledRectangle($wm, 0, 0, $text_width, $text_height, $bgcolor); ImageAlphaBlending($wm, TRUE); if ($this->text_color) { $color = $this->text_color; } else { $color = ImageColorAllocateAlpha($wm, 0, 0, 0, 0); } ImageTTFText($wm, $font_size, 0, 0, $text_height - 2, $color, $font, $text); ImageAlphaBlending($this->im, TRUE); ImageCopy($this->im, $wm, $x, $y, 0, 0, $text_width, $text_height); }
public static function GenerateCaptcha() { if (isset($_SESSION['generated_captcha'])) { Session::UnsetKeys(array('generated_captcha')); } $InitialString = str_shuffle("abcdefghijklmnopqrstuvwxyz1234567890"); $RandomString = substr($InitialString, 0, 9); $CreateBlankImage = ImageCreate(200, 70) or die("Cannot Initialize new GD image stream"); $BackgroundColor = ImageColorAllocateAlpha($CreateBlankImage, 255, 255, 255, 127); imagefill($CreateBlankImage, 0, 0, 0x7fff0000); $BackgroundColor = ImageColorAllocate($CreateBlankImage, 204, 255, 51); $TextColor = ImageColorAllocate($CreateBlankImage, 51, 51, 255); ImageString($CreateBlankImage, 5, 50, 25, $RandomString, $TextColor); ImagePng($CreateBlankImage); $_SESSION['generated_captcha'] = $RandomString; Session::UpdateSession($_SESSION); }
function ImageColorAllocateAlphaSafe(&$gdimg_hexcolorallocate, $R, $G, $B, $alpha = false) { if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=') && $alpha !== false) { return ImageColorAllocateAlpha($gdimg_hexcolorallocate, $R, $G, $B, intval($alpha)); } else { return ImageColorAllocate($gdimg_hexcolorallocate, $R, $G, $B); } }
$image = ImageCreateTrueColor(400, 300); ImageAlphaBlending($image, true); // allocate some colors $black = ImageColorAllocate($image, 0, 0, 0); $red = ImageColorAllocate($image, 0xff, 0, 0); $green = ImageColorAllocate($image, 0, 0xff, 0); $blue = ImageColorAllocate($image, 0, 0, 0xff); $white = ImageColorAllocate($image, 0xff, 0xff, 0xff); // create a frame ImageFilledRectangle($image, 0, 0, 399, 299, $white); ImageRectangle($image, 0, 0, 399, 299, $black); // draw some lines ImageLine($image, 200, 50, 350, 150, $red); ImageLine($image, 200, 60, 350, 160, $green); ImageLine($image, 200, 70, 350, 170, $blue); // draw some overlapping alpha blended boxes $redAlpha = ImageColorAllocateAlpha($image, 0xff, 0, 0, 75); $blueAlpha = ImageColorAllocateAlpha($image, 0, 0xff, 0, 75); $greenAlpha = ImageColorAllocateAlpha($image, 0, 0, 0xff, 75); ImageFilledRectangle($image, 50, 50, 90, 90, $redAlpha); ImageFilledRectangle($image, 60, 80, 100, 120, $greenAlpha); ImageFilledRectangle($image, 80, 60, 120, 100, $blueAlpha); // write some _default_ text for ($font = 1; $font <= 5; $font++) { ImageString($image, $font, 50, 150 + $font * 20, 'Testing GD output', $black); } ImageString($image, 3, 51, 21, 'Congratulations! The GD2 installation works', $black); ImageString($image, 3, 50, 20, 'Congratulations! The GD2 installation works', $red); // output the test image header('Content-Type: image/png'); ImagePNG($image);
function init($w, $h, $d) { $this->im = ImageCreate($w, $h); imagesavealpha($this->im, true); $this->width = $w; $this->height = $h; $this->data = $d; $this->da_width = $this->width - $this->left - $this->right; $this->da_height = $this->height - $this->top - $this->bottom; $this->center_x = intval($this->left + $this->da_width / 2); $this->center_y = intval($this->top + $this->da_height / 2); /* font sizes */ $this->fx = array(0, 5, 6, 7, 8, 9); $this->fy = array(0, 7, 8, 10, 14, 11); /* decide the diameter of the pie */ if ($this->da_height > $this->da_width) { $this->diameter = $this->da_width; } else { $this->diameter = $this->da_height; } $this->white = ImageColorAllocateAlpha($this->im, 0, 0, 0, 127); imagefill($this->im, 0, 0, $this->white); $this->black = ImageColorAllocate($this->im, 0, 0, 0); $n = count($this->data); for ($i = 0; $i < $n; $i++) { $this->colors[$i] = ImageColorAllocate($this->im, $this->data[$i][2], $this->data[$i][3], $this->data[$i][4]); $this->sum += $this->data[$i][0]; } $from = 0; $to = 0; for ($i = 0; $i < $n; $i++) { $this->angles[$i] = $this->roundoff($this->data[$i][0] * 360 / doubleval($this->sum)); } $this->draw_slices($this->center_x, $this->center_y, $this->angles, $this->colors); }
<?php // Rectangle Version $filename = __DIR__ . '/php.png'; // Thumbnail Dimentions $w = 50; $h = 20; // Images $original = ImageCreateFromPNG($filename); $thumbnail = ImageCreateTrueColor($w, $h); // Preserve Transparency ImageColorTransparent($thumbnail, ImageColorAllocateAlpha($thumbnail, 0, 0, 0, 127)); ImageAlphaBlending($thumbnail, false); ImageSaveAlpha($thumbnail, true); // Scale & Copy $x = ImageSX($original); $y = ImageSY($original); $scale = min($x / $w, $y / $h); ImageCopyResampled($thumbnail, $original, 0, 0, ($x - $w * $scale) / 2, ($y - $h * $scale) / 2, $w, $h, $w * $scale, $h * $scale); // Send header('Content-type: image/png'); ImagePNG($thumbnail); ImageDestroy($original); ImageDestroy($thumbnail);
for ($i = 1; $i <= 3; $i++) { if (isset($profs[$i - 1]) > 0) { $prof = $profs[$i - 1]; $name = $prof['name']; $v = $prof['value']; $txt = "{$v} {$name}"; $textLeft += 100; ImageTTFText($img, 8, 0, $textLeft, 90, $textcolor, $plainFont, win2uni($txt)); } } $lineWidth = 495 - $new_width - 45 - 45; $midWidth = $lineWidth; $y = 43; ImageLine($img, $new_width + 45, $y, 445, $y, $textcolor); for ($i = 0; $i < 40; $i++) { $c = ImageColorAllocateAlpha($img, $text_r, $text_g, $text_b, floor(87 / 40 * $i) + 40); ImageLine($img, $new_width + 45 + 1 - $i, $y, $new_width + 45 - $i, $y, $c); ImageLine($img, 445 + $i, $y, 446 + $i, $y, $c); ImageColorDeallocate($img, $c); } ImageTTFText($img, 10, 0, $new_width + 5, 59, $textcolor, $mainFont, win2uni($row['race']) . " " . win2uni($row['clevel']) . " ур. - WWW.RPG.SU"); if ($row['clan_id'] > 0) { $clan_name = mysql_result(myquery("SELECT nazv FROM game_clans WHERE clan_id=" . $row['clan_id'] . ""), 0, 0); ImageTTFText($img, 9, 0, $new_width + 5, 72, $textcolor, $mainFont, "<" . $clan_name . "> " . ""); } else { ImageTTFText($img, 9, 0, $new_width + 5, 72, $textcolor, $mainFont, "Средиземье :: Эпоха Сражений" . ""); } ImageTTFText($img, 8, 0, $new_width + 25, 10, $textcolor, $mainFont, $reason); for ($n = 1; $n <= 6; $n++) { $w = $sta[$n]; $texu = "{$w}";
/** * Implements the "BOX" GIFBUILDER object * * @param resource $im GDlib image pointer * @param array $conf TypoScript array with configuration for the GIFBUILDER object. * @param array $workArea The current working area coordinates. * @return void * @see \TYPO3\CMS\Frontend\Imaging\GifBuilder::make() */ public function makeBox(&$im, $conf, $workArea) { $cords = GeneralUtility::intExplode(',', $conf['dimensions'] . ',,,'); $conf['offset'] = $cords[0] . ',' . $cords[1]; $cords = $this->objPosition($conf, $workArea, array($cords[2], $cords[3])); $cols = $this->convertColor($conf['color']); $opacity = 0; if (isset($conf['opacity'])) { // conversion: // PHP 0 = opaque, 127 = transparent // TYPO3 100 = opaque, 0 = transparent $opacity = MathUtility::forceIntegerInRange((int) $conf['opacity'], 1, 100, 1); $opacity = abs($opacity - 100); $opacity = round(127 * $opacity / 100); } $tmpColor = ImageColorAllocateAlpha($im, $cols[0], $cols[1], $cols[2], $opacity); imagefilledrectangle($im, $cords[0], $cords[1], $cords[0] + $cords[2] - 1, $cords[1] + $cords[3] - 1, $tmpColor); }
list($dest_r, $dest_g, $dest_b) = getHexColors($color_on); // цвет фона $text_color_2 = $text_color['title_online']; } elseif (!$statusWorld && $online[0] > 0) { // оффлайн/краш $bg_color = ImageColorAllocate($img, 255, 255, 255); // цвет окантовки всей рамки $bg_colorAlpha = ImageColorAllocateAlpha($img, 255, 255, 255, 80); // цвет окантовки блоков //list($dest_r, $dest_g, $dest_b) = getHexColors($color_crash); // цвет фона $text_color_2 = $text_color['title_crash']; } else { // оффлайн/shutdown $bg_color = ImageColorAllocate($img, 255, 0, 0); // цвет окантовки всей рамки $bg_colorAlpha = ImageColorAllocateAlpha($img, 255, 0, 0, 80); // цвет окантовки блоков list($dest_r, $dest_g, $dest_b) = getHexColors($color_off); // цвет фона $text_color_2 = $text_color['title_offline']; } $base_r = 0; $base_g = 0; $base_b = 0; for ($i = 0; $i < ImageSY($img); $i++) { $r = min($base_r + $dest_r / ImageSY($img) * $i, 255); $g = min($base_g + $dest_g / ImageSY($img) * $i, 255); $b = min($base_b + $dest_b / ImageSY($img) * $i, 255); $c = ImageColorAllocate($img, $r, $g, $b); ImageLine($img, 0, $i, ImageSX($img), $i, $c); ImageColorDeallocate($img, $c);
public function userbar($name) { if ($f = $this->checkCache(strtolower($name), false)) { $this->getCache($f); return; } $this->init($name, 'default'); // -> $data - массив данных global $config; $this->img = ImageCreateTrueColor($this->b_width, $this->b_height); $black = ImageColorAllocate($this->img, 0, 0, 0); ImageFill($this->img, 0, 0, $black); $text_r = 255; $text_g = 210; $text_b = 0; $s_text_r = 255; $s_text_g = 255; $s_text_b = 255; list($text_r, $text_g, $text_b) = $this->getHexColors($this->text_color[0]); list($s_text_r, $s_text_g, $s_text_b) = $this->getHexColors($this->text_color[1]); $textcolor = ImageColorAllocate($this->img, $text_r, $text_g, $text_b); $secondaryTextColor = ImageColorAllocate($this->img, $s_text_r, $s_text_g, $s_text_b); list($base_r, $base_g, $base_b) = $this->getHexColors($this->color[0]); list($dest_r, $dest_g, $dest_b) = $this->getHexColors($this->getFonBase()); for ($i = 0; $i < ImageSY($this->img); $i++) { $r = min($base_r + ($dest_r - $base_r) / ImageSY($this->img) * $i, 255); $g = min($base_g + ($dest_g - $base_g) / ImageSY($this->img) * $i, 255); $b = min($base_b + ($dest_b - $base_b) / ImageSY($this->img) * $i, 255); $c = ImageColorAllocate($this->img, $r, $g, $b); ImageLine($this->img, 0, $i, ImageSX($this->img), $i, $c); ImageColorDeallocate($this->img, $c); } $gender = $this->data['gender']; $race = $this->data['race']; $class = $this->data['class']; $lvl = $this->data['level']; $ramka = ImageCreateFromGIF(ICON_BORDER_PORTRAIT); $realm = ImageCreateFromGIF(ICON_REALM); $gm = ImageCreateFromGIF(ICON_GM); $r_bar = ImageCreateFromGIF(ICON_RIGHT_BAR); $achieve = ImageCreateFromPNG(ICON_ACHIEVE); $guildmaster = ImageCreateFromGIF(ICON_GUILDMASTER); $active = ImageCreateFromGIF("static/icon-active.gif"); //определяем вид иконки рассы на баре в зависимости от уровня персонажа $portrait = $lvl < 60 ? ImageCreateFromGIF("static/portraits/np/{$gender}-{$race}-{$class}.gif") : $lvl < 70 ? ImageCreateFromGIF("static/portraits/60/{$gender}-{$race}-{$class}.gif") : $lvl < 80 ? ImageCreateFromGIF("static/portraits/70/{$gender}-{$race}-{$class}.gif") : ImageCreateFromGIF("static/portraits/80/{$gender}-{$race}-{$class}.gif"); $imgclass = ImageCreateFromGIF(DIR_ICONS_CLASS . $class . ".gif"); $imgrace = ImageCreateFromGIF(DIR_ICONS_RACE . $race . "-" . $gender . ".gif"); if ($this->data['honor_rank']) { $imgpvp = ImageCreateFromPNG(DIR_ICONS_PVPRANK . "PvPRank" . $this->data['honor_rank'] . ".png"); } $imgfraction = $this->data['fraction'] == 1 ? ImageCreateFromPNG(ICON_FRACTION_HORDE) : ImageCreateFromPNG(ICON_FRACTION_ALLIANCE); $imghonor = $this->data['fraction'] == 1 ? ImageCreateFromPNG(ICON_HONOR_HORDE) : ImageCreateFromPNG(ICON_HONOR_ALLIANCE); $offset = 0; $blacka = ImageColorAllocateAlpha($this->img, 0, 0, 0, 100); ImageFilledRectangle($this->img, 0, 0, ImageSX($this->img) - 1, ImageSY($this->img) - 1, $blacka); ImageCopyResampled($this->img, $portrait, 8, 8, 0, 0, 64, 64, ImageSX($portrait), ImageSY($portrait)); ImageCopyResampled($this->img, $ramka, 0, 0, 0, 0, 83, 83, ImageSX($ramka), ImageSY($ramka)); // $ramka ImageCopyResampled($this->img, $r_bar, 83, 4, 0, 0, 28, 76, ImageSX($r_bar), ImageSY($r_bar)); // $r_bar $this->set_expansion(); if ($this->is_gm) { ImageCopyResampled($this->img, $gm, 57, 60, 0, 0, 20, 13, ImageSX($gm), ImageSY($gm)); } else { $diff_x = $this->data['level'] >= 10 ? 61 : 64; ImageTTFText($this->img, 8, 0, $diff_x, 70, $textcolor, $this->font['wow'], $this->data['level']); } //Класс, раса, ранг ПвП ImageCopyResampled($this->img, $imgrace, 85, 12, 0, 0, 18, 18, ImageSX($imgrace), ImageSY($imgrace)); ImageCopyResampled($this->img, $imgclass, 85, 33, 0, 0, 18, 18, ImageSX($imgclass), ImageSY($imgclass)); ImageCopyResampled($this->img, $active, 85, 33, 0, 0, 18, 18, ImageSX($active), ImageSY($active)); if ($this->data['honor_rank'] > 0) { ImageCopyResampled($this->img, $imgpvp, 85, 54, 0, 0, 18, 18, ImageSX($imgpvp), ImageSY($imgpvp)); } else { ImageCopyResampled($this->img, $imgfraction, 84, 54, 0, 1, 19, 19, ImageSX($imgfraction), ImageSY($imgfraction)); } // цвет линии опыта основан на цвете градиента юзербара $xplinecolor = ImageColorAllocate($this->img, $dest_r, $dest_g, $dest_b); $lineWidth = 220; $y0 = 38; $x0 = 111; ImageLine($this->img, $x0, $y0, $x0 + $lineWidth, $y0, $textcolor); if ($lvl < $this->data['maxlvl']) { ImageLine($this->img, $x0, $y0, $x0 + $lineWidth * $this->data['xp'] / $this->data['xp_next'], $y0, $xplinecolor); } $this->fontSize = strlen($this->pl->name) >= 10 ? 18 : 21; $this->font_name = $this->is_cyrillic($this->pl->name) ? $this->font['friztrus'] : $this->font['wow']; if ($this->pl->inGuild()) { ImageTTFText($this->img, 9, 0, 114, 52, $textcolor, $this->font['friztrus'], $this->pl->guildNmae); if ($this->pl->isGuildLeader()) { ImageCopyResampled($this->img, $guildmaster, 115, 16, 0, 0, 18, 18, ImageSX($guildmaster), ImageSY($guildmaster)); ImageTTFText($this->img, $this->fontSize, 0, 136, 35, $textcolor, $this->font_name, $this->pl->name); } else { ImageTTFText($this->img, $this->fontSize, 0, 116, 35, $textcolor, $this->font_name, $this->pl->name); } } else { ImageTTFText($this->img, $this->fontSize, 0, 116, 35, $textcolor, $this->font_name, $this->pl->name); } $this->pl->acctid = $this->pl->getAccountId(); $realm_name = $this->pl->getRealmName($config['realmid'], false); ImageCopyResampled($this->img, $realm, 115, 64, 0, 0, 16, 16, ImageSX($realm), ImageSY($realm)); ImageTTFText($this->img, 9, 0, 133, 77, $textcolor, $this->font['friztrus'], $realm_name); $honor = $this->data['totalHonorPoints']; if ($honor > 0) { // show honor ImageCopyResampled($this->img, $imghonor, 265, -3, 0, 0, 26, 26, ImageSX($imghonor), ImageSY($imghonor)); ImageTTFText($this->img, 8, 0, 287, 13, $textcolor, $this->font['wow'], $honor); } if ($this->data['achievement'] > 0) { // show achievement ImageCopyResampled($this->img, $achieve, 266, 16, 0, 0, 23, 23, ImageSX($achieve), ImageSY($achieve)); ImageTTFText($this->img, 8, 0, 289, 32, $textcolor, $this->font['wow'], $this->data['achievement']); } if (!is_null($this->data['profs'])) { $count = count($this->data['profs']); if ($count > 2) { $count = 2; } $textLeft = 270; for ($i = 0; $i < $count; $i++) { $value = $this->data['profs'][$i]['value']; $skill = $this->data['profs'][$i]['skill']; $imgproff = ImageCreateFromGIF(DIR_ICONS_PROFESSION . $skill . '.gif'); $diff = $value < 10 ? 9 : ($value > 10 && $value < 20 ? 7 : ($value > 20 && $value < 100 ? 4 : 3)); ImageCopyResampled($this->img, $imgproff, $textLeft + 28 * $i, 41, 0, 0, 27, 27, ImageSX($imgproff), ImageSY($imgproff)); ImageTTFText($this->img, 8, 0, $textLeft + 30 * $i + $diff, 75, $textcolor, $this->font['wow'], $value); } } $this->output(strtolower($this->pl->name), false); }
function AddBox($foot = true, $r = 0, $g = 0, $b = 0, $bh, $text_box = '', $rt = 255, $gt = 255, $bt = 255, $text_size = 25) { $box_x1 = '0'; $box_xi1 = 0; $box_x2 = strval($this->GetWidth()); $img_height = $this->GetHeight(); $display_text = ' ' . utf8_decode($text_box); if ($foot) { $box_y1 = strval($img_height - $bh); } else { $box_y1 = '0'; } $box_yi1 = intval($box_y1); if ($foot) { $box_y2 = strval($img_height); } else { $box_y2 = strval($bh); } $colour = ImageColorAllocateAlpha($this->img, $r, $g, $b, 80); Imagefilledrectangle($this->img, $box_x1, $box_y1, $box_x2, $box_y2, $colour); if ($display_text != '') { $col[0] = $rt; $col[1] = $gt; $col[2] = $bt; $this->addText($display_text, $box_xi1, $box_yi1, $col, $text_size); } }
function Resize_Image($src, $width = 0, $height = 0, $dst) { if ($height <= 0 && $width <= 0) { return false; } // Setting defaults and meta $image = ''; $final_width = 0; $final_height = 0; list($width_old, $height_old, $image_type) = GetImageSize($src); // Calculating proportionality if ($width == 0) { $factor = $height / $height_old; } elseif ($height == 0) { $factor = $width / $width_old; } else { $factor = Min($width / $width_old, $height / $height_old); } $final_width = Round($width_old * $factor); $final_height = Round($height_old * $factor); // Loading image to memory according to type switch ($image_type) { case IMAGETYPE_GIF: $image = imagecreatefromgif($src); break; case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($src); break; case IMAGETYPE_PNG: $image = imagecreatefrompng($src); break; default: return false; } // This is the resizing/resampling/transparency-preserving magic $image_resized = ImageCreateTrueColor($final_width, $final_height); if ($image_type == IMAGETYPE_GIF || $image_type == IMAGETYPE_PNG) { $transparency = ImageColorTransparent($image); if ($image_type == IMAGETYPE_GIF && $transparency >= 0) { list($r, $g, $b) = Array_Values(ImageColorsForIndex($image, $transparency)); $transparency = ImageColorAllocate($image_resized, $r, $g, $b); Imagefill($image_resized, 0, 0, $transparency); ImageColorTransparent($image_resized, $transparency); } elseif ($image_type == IMAGETYPE_PNG) { ImageAlphaBlending($image_resized, false); $color = ImageColorAllocateAlpha($image_resized, 0, 0, 0, 127); ImageFill($image_resized, 0, 0, $color); ImageSaveAlpha($image_resized, true); } } ImageCopyResampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old); // Writing image switch ($image_type) { case IMAGETYPE_GIF: imagegif($image_resized, $dst); break; case IMAGETYPE_JPEG: imagejpeg($image_resized, $dst, 85); break; case IMAGETYPE_PNG: imagepng($image_resized, $dst); break; default: return false; } }
/** * Generates a resized version of an image and saves it in the image cache folder. * * @param string $source_file The original image to be resized. * @param string $cache_file The target file where the resized version will be cached. * @param int $resolution The resolution breakpoint at which the given image is to be resized. * @param int $jpg_quality The JPEG quality that will be used for resizing the images. * @param bool $sharpen Whether to sharpen the resized images or not. * * @return array Associative array( bool: success, string: message) with the result of the image cache generation. */ function adaptive_images_script_generate_image($source_file, $cache_file, $resolution, $jpg_quality, $sharpen) { // Get original image dimensions. $dimensions = @GetImageSize($source_file); $width = $dimensions[0]; $height = $dimensions[1]; // Calculate resized image dimensions. $ratio = $height / $width; $new_width = $resolution; $new_height = ceil($new_width * $ratio); // Start creating the resized image with a blank true color canvas. $destination = @ImageCreateTrueColor($new_width, $new_height); $extension = adaptive_images_script_get_file_extension($source_file); switch ($extension) { case 'png': $source = @ImageCreateFromPng($source_file); break; case 'gif': $source = @ImageCreateFromGif($source_file); break; default: $source = @ImageCreateFromJpeg($source_file); break; } // PNG images generation. if ($extension == 'png') { // Create a transparent color and fill the blank canvas with it. $rbga_color = @ImageColorAllocateAlpha($destination, 0, 0, 0, 127); @ImageColorTransparent($destination, $rbga_color); @ImageFill($destination, 0, 0, $rbga_color); // Copy source image to destination image with interpolation. @ImageCopyResampled($destination, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Convert true colour image to pallette image to achieve PNG-8 compression. $dither = TRUE; @ImageTrueColorToPalette($destination, $dither, 255); // Save alpha (transparency) of destination image. $save_alpha = TRUE; @ImageSaveAlpha($destination, $save_alpha); // Disable blending of destination image to allow for alpha (transparency) above. $enable_alpha_blending = FALSE; @ImageAlphaBlending($destination, $enable_alpha_blending); } // GIF images generation. if ($extension == 'gif') { // Create a transparent color and fill the blank canvas with it. $rbga_color = @ImageColorAllocateAlpha($destination, 0, 0, 0, 127); @ImageColorTransparent($destination, $rbga_color); @ImageFill($destination, 0, 0, $rbga_color); // Copy source image to destination image with interpolation. @ImageCopyResampled($destination, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Convert true colour image to pallette image to achieve PNG8 compression. $dither = TRUE; @ImageTrueColorToPalette($destination, $dither, 255); // Enable alpha blending of destination image. $enable_alpha_blending = TRUE; @ImageAlphaBlending($destination, $enable_alpha_blending); } // JPEG images generation. if ($extension == 'jpg' || $extension == 'jpeg') { // Enable JPEG interlacing. ImageInterlace($destination, TRUE); // Interpolates source image to destination image to make it more clear for JPGs. @ImageCopyResampled($destination, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); } // Cleanup source image from memory. @ImageDestroy($source); // Do sharpening if requested. if ($sharpen && function_exists('imageconvolution')) { $sharpness_factor = adaptive_images_script_sharpness_factor($width, $new_width); $sharpness_transformation_matrix = array(array(-1, -2, -1), array(-2, $sharpness_factor + 12, -2), array(-1, -2, -1)); // OR // $sharpenMatrix = array // ( // array(-1.2, -1, -1.2), // array(-1, 20, -1), // array(-1.2, -1, -1.2) // ); // $divisor = array_sum(array_map('array_sum', $sharpenMatrix)); // OR // $sharpen = array( // array(0.0, -1.0, 0.0), // array(-1.0, 5.0, -1.0), // array(0.0, -1.0, 0.0) // ); // $divisor = array_sum(array_map('array_sum', $sharpen)); // OR // $matrix = array( // array(-1, -1, -1), // array(-1, 16, -1), // array(-1, -1, -1), // ); // $divisor = array_sum(array_map('array_sum', $matrix)); @ImageConvolution($destination, $sharpness_transformation_matrix, $sharpness_factor, 0); } // Check and ensure that cache directory is setup OK. $cache_path = dirname($cache_file); if (!adaptive_images_script_ensure_cache_directory_ready($cache_path)) { return array('success' => false, 'message' => 'Cache directory for image not accessible or writeable.'); } // Save resized image in cache. switch ($extension) { case 'png': $png_compression_level = 6; $image_saved = @ImagePng($destination, $cache_file, $png_compression_level, PNG_FILTER_NONE); break; case 'gif': $image_saved = @ImageGif($destination, $cache_file); break; default: $image_saved = @ImageJpeg($destination, $cache_file, $jpg_quality); break; } // Cleanup destination image from memory. @ImageDestroy($destination); // Check if all OK. if (!$image_saved && !file_exists($cache_file)) { return array('success' => false, 'message' => 'Resized image could not be created.'); } // Return file of resized and cached image. return array('success' => true, 'message' => $cache_file); }
/** * Transforme la couleur de fond de l'image en transparence * Le filtre ne gere pas la notion de contiguite aux bords, et affectera tous les pixels de l'image dans la couleur visee * $background_color : couleur cible * $tolerance : distance L1 dans l'espace RGB des couleur autour de la couleur $background_color pour lequel la transparence sera appliquee * $alpha : transparence a appliquer pour les pixels de la couleur cibles avec la tolerance ci-dessus * $coeff_lissage : coeff applique a la tolerance pour determiner la decroissance de la transparence fonction de la distance L1 entre la couleur du pixel et la couleur cible * * @param string $im * @param string $background_color * @param int $tolerance * @param int $alpha * alpha = 0: aucune transparence * alpha = 127: completement transparent * @param int $coeff_lissage * @return mixed|null|string */ function image_fond_transparent($im, $background_color, $tolerance = 12, $alpha = 127, $coeff_lissage = 7) { $fonction = array('image_fond_transparent', func_get_args()); $image = _image_valeurs_trans($im, "fond_transparent-{$background_color}-{$tolerance}-{$coeff_lissage}-{$alpha}", "png", $fonction); if (!$image) { return ""; } $x_i = $image["largeur"]; $y_i = $image["hauteur"]; $im = $image["fichier"]; $dest = $image["fichier_dest"]; $creer = $image["creer"]; if ($creer) { $bg = _couleur_hex_to_dec($background_color); $bg_r = $bg['red']; $bg_g = $bg['green']; $bg_b = $bg['blue']; // Creation de l'image en deux temps // de facon a conserver les GIF transparents $im = $image["fonction_imagecreatefrom"]($im); imagepalettetotruecolor($im); $im2 = imagecreatetruecolor($x_i, $y_i); @imagealphablending($im2, false); @imagesavealpha($im2, true); $color_t = ImageColorAllocateAlpha($im2, 255, 255, 255, 127); imagefill($im2, 0, 0, $color_t); imagecopy($im2, $im, 0, 0, 0, 0, $x_i, $y_i); $im_ = imagecreatetruecolor($x_i, $y_i); imagealphablending($im_, false); imagesavealpha($im_, true); $color_f = ImageColorAllocateAlpha($im_, 255, 255, 255, $alpha); for ($x = 0; $x < $x_i; $x++) { for ($y = 0; $y < $y_i; $y++) { $rgb = ImageColorAt($im2, $x, $y); $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; if (($d = abs($r - $bg_r) + abs($g - $bg_g) + abs($b - $bg_b)) <= $tolerance) { imagesetpixel($im_, $x, $y, $color_f); } elseif ($tolerance and $d <= ($coeff_lissage + 1) * $tolerance) { $transp = round($alpha * (1 - ($d - $tolerance) / ($coeff_lissage * $tolerance))); $color_p = ImageColorAllocateAlpha($im_, $r, $g, $b, $transp); imagesetpixel($im_, $x, $y, $color_p); } else { imagesetpixel($im_, $x, $y, $rgb); } } } _image_gd_output($im_, $image); imagedestroy($im_); imagedestroy($im); imagedestroy($im2); } return _image_ecrire_tag($image, array('src' => $dest)); }
/** * Function: flipImage * * Flips the given image horizontally and/or vertically and returns a new * image instance. */ static function flipImage($img, $flipH, $flipV) { $w = imagesx($img); $h = imagesy($img); $sx = 0; $sy = 0; $sw = $w; $sh = $h; if ($flipH) { $sx = $w - 1; $sw = -$w; } if ($flipV) { $sy = $h - 1; $sh = -$h; } $dst = imagecreatetruecolor($w, $h); // Fills the background with transparent white $bg = ImageColorAllocateAlpha($dst, 255, 255, 255, 127); ImageFill($dst, 0, 0, $bg); if (imagecopyresampled($dst, $img, 0, 0, $sx, $sy, $w, $h, $sw, $sh)) { return $dst; } return $img; }
/** * Make the image greyscale * $rv = red value, defaults to 38 * $gv = green value, defaults to 36 * $bv = blue value, defaults to 26 * Based (more or less entirely, with changes for readability) on code from * http://www.teckis.com/scriptix/thumbnails/teck.html */ public function greyscale($rv = 38, $gv = 36, $bv = 26) { if (!$this->gd) { return null; } $width = $this->width; $height = $this->height; $newGD = imagecreatetruecolor($this->width, $this->height); // Preserves transparency between images imagealphablending($newGD, false); imagesavealpha($newGD, true); $rt = $rv + $bv + $gv; $rr = $rv == 0 ? 0 : 1 / ($rt / $rv); $br = $bv == 0 ? 0 : 1 / ($rt / $bv); $gr = $gv == 0 ? 0 : 1 / ($rt / $gv); for ($dy = 0; $dy < $height; $dy++) { for ($dx = 0; $dx < $width; $dx++) { $pxrgb = imagecolorat($this->gd, $dx, $dy); $heightgb = ImageColorsforIndex($this->gd, $pxrgb); $newcol = $rr * $heightgb['red'] + $br * $heightgb['blue'] + $gr * $heightgb['green']; $setcol = ImageColorAllocateAlpha($newGD, $newcol, $newcol, $newcol, $heightgb['alpha']); imagesetpixel($newGD, $dx, $dy, $setcol); } } $output = clone $this; $output->setImageResource($newGD); return $output; }
/** * Implements the "BOX" GIFBUILDER object * * @param pointer GDlib image pointer * @param array TypoScript array with configuration for the GIFBUILDER object. * @param array The current working area coordinates. * @return void * @see tslib_gifBuilder::make() */ function makeBox(&$im, $conf, $workArea) { $cords = t3lib_div::intExplode(',', $conf['dimensions'] . ',,,'); $conf['offset'] = $cords[0] . ',' . $cords[1]; $cords = $this->objPosition($conf, $workArea, array($cords[2], $cords[3])); $cols = $this->convertColor($conf['color']); if (!$this->truecolor) { $reduce = t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256); $this->reduceColors($im, $reduce - 1, $reduce - 2); // If "reduce-1" colors (or more) are used reduce them to "reduce-2" } $opacity = 0; if (isset($conf['opacity'])) { // conversion: // PHP 0 = opaque, 127 = transparent // TYPO3 100 = opaque, 0 = transparent $opacity = t3lib_div::intInRange(intval($conf['opacity']), 1, 100, 1); $opacity = abs($opacity - 100); $opacity = round(127 * $opacity / 100); } $tmpColor = ImageColorAllocateAlpha($im, $cols[0], $cols[1], $cols[2], $opacity); imagefilledrectangle($im, $cords[0], $cords[1], $cords[0] + $cords[2] - 1, $cords[1] + $cords[3] - 1, $tmpColor); }
function ImageHTMLColor($image, $color, $paras = array()){ if ($color[0] == "#"){ $color = substr($color, 1); } if (strlen($color) == 6){ list($r, $g, $b) = array( $color[0] . $color[1], $color[2].$color[3], $color[4].$color[5] ); }elseif(strlen($color) == 3){ list($r, $g, $b) = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); }else{ throw new Exception("Invalid HTML-color-string length."); } if ($paras["alpha"]){ return ImageColorAllocateAlpha($image, hexdec($r), hexdec($g), hexdec($b), 127); } return ImageColorAllocate($image, hexdec($r), hexdec($g), hexdec($b)); }
$inImg = ImageCreateFromJPEG($rootPath ."/". $arResult["SOURCE_IMAGE"]["SRC"]); if ($hasColor) { $color = ImageColorAllocate($outImg, $R, $G, $B); } break; case "PNG": $inImg = ImageCreateFromPNG($rootPath ."/". $arResult["SOURCE_IMAGE"]["SRC"]); ImageAlphaBlending($outImg, false); ImageSaveAlpha($outImg, true); if ($hasColor) { if ($arParams["JPEG_OUTPUT"] == "CONV_PNG_DIFF_Q" || $arParams["JPEG_OUTPUT"] == "CONV_PNG_SET_Q") { $color = ImageColorAllocate($outImg, $R, $G, $B); } else { $color = ImageColorAllocateAlpha($outImg, $R, $G, $B, $A); } } break; } if( $hasColor && ($arParams["FILL_ALWAYS"] == "Y" || ($arParams["RESIZE_TYPE"] == "CROP" && $arParams["KEEP_SIZE"] == "FILL") ) ) { ImageFill($outImg, 0, 0, $color); } ImageCopyResampled( $outImg, $inImg, $offsetX, $offsetY, 0, 0, $newWidth, $newHeight, $arResult["SOURCE_IMAGE"]["WIDTH"], $arResult["SOURCE_IMAGE"]["HEIGHT"] );
public function rotate($value = 90, $bgColor = 'transparent') { if ($this->imageResized) { if (is_integer($value)) { $degrees = $value; } // *** Convert color $rgbArray = $this->formatColor($bgColor); $r = $rgbArray['r']; $g = $rgbArray['g']; $b = $rgbArray['b']; if (isset($rgbArray['a'])) { $a = $rgbArray['a']; } if (is_string($value)) { $value = fix_strtolower($value); switch ($value) { case 'left': $degrees = 90; break; case 'right': $degrees = 270; break; case 'upside': $degrees = 180; break; default: break; } } // *** The default direction of imageRotate() is counter clockwise // * This makes it clockwise $degrees = 360 - $degrees; // *** Create background color $bg = ImageColorAllocateAlpha($this->imageResized, $r, $g, $b, $a); // *** Fill with background ImageFill($this->imageResized, 0, 0, $bg); // *** Rotate $this->imageResized = imagerotate($this->imageResized, $degrees, $bg); // Rotate 45 degrees and allocated the transparent colour as the one to make transparent (obviously) // Ensure alpha transparency ImageSaveAlpha($this->imageResized, true); } }
/** * Make the image greyscale. * Default color weights are based on standard BT.601 (those used in PAL, NTSC and many software packages, also see * https://en.wikipedia.org/wiki/Grayscale#Luma_coding_in_video_systems ) * * $R = red weight, defaults to 299 * $G = green weight, defaults to 587 * $B = blue weight, defaults to 114 * $brightness = brightness in percentage, defaults to 100 */ public function greyscale($R = 299, $G = 587, $B = 114, $brightness = 100) { $width = $this->width; $height = $this->height; $newGD = imagecreatetruecolor($this->width, $this->height); // Preserves transparency between images imagealphablending($newGD, false); imagesavealpha($newGD, true); $rt = $R + $G + $B; // if $rt is 0, bad parameters are provided, so result will be a black image $rr = $rt ? $R / $rt : 0; $gr = $rt ? $G / $rt : 0; $br = $rt ? $B / $rt : 0; // iterate over all pixels and make them grey for ($dy = 0; $dy < $height; $dy++) { for ($dx = 0; $dx < $width; $dx++) { $pxrgb = imagecolorat($this->gd, $dx, $dy); $heightgb = ImageColorsforIndex($this->gd, $pxrgb); $newcol = $rr * $heightgb['red'] + $br * $heightgb['blue'] + $gr * $heightgb['green']; $newcol = min(255, $newcol * $brightness / 100); $setcol = ImageColorAllocateAlpha($newGD, $newcol, $newcol, $newcol, $heightgb['alpha']); imagesetpixel($newGD, $dx, $dy, $setcol); } } $output = clone $this; $output->setImageResource($newGD); return $output; }
/** * Creates Apple-style reflection under image, optionally adding a border to main image * * @param int $percent * @param int $reflection * @param int $white * @param bool $border * @param string $borderColor */ function createReflection($percent, $reflection, $white, $border = true, $borderColor = '#a4a4a4') { $width = $this->currentDimensions['width']; $height = $this->currentDimensions['height']; $reflectionHeight = intval($height * ($reflection / 100)); $newHeight = $height + $reflectionHeight; $reflectedPart = $height * ($percent / 100); $this->workingImage = ImageCreateTrueColor($width, $newHeight); ImageAlphaBlending($this->workingImage, true); $colorToPaint = ImageColorAllocateAlpha($this->workingImage, 255, 255, 255, 0); ImageFilledRectangle($this->workingImage, 0, 0, $width, $newHeight, $colorToPaint); imagecopyresampled($this->workingImage, $this->newImage, 0, 0, 0, $reflectedPart, $width, $reflectionHeight, $width, $height - $reflectedPart); $this->imageFlipVertical(); imagecopy($this->workingImage, $this->newImage, 0, 0, 0, 0, $width, $height); imagealphablending($this->workingImage, true); for ($i = 0; $i < $reflectionHeight; $i++) { $colorToPaint = imagecolorallocatealpha($this->workingImage, 255, 255, 255, ($i / $reflectionHeight * -1 + 1) * $white); imagefilledrectangle($this->workingImage, 0, $height + $i, $width, $height + $i, $colorToPaint); } if ($border == true) { $rgb = $this->hex2rgb($borderColor, false); $colorToPaint = imagecolorallocate($this->workingImage, $rgb[0], $rgb[1], $rgb[2]); imageline($this->workingImage, 0, 0, $width, 0, $colorToPaint); //top line imageline($this->workingImage, 0, $height, $width, $height, $colorToPaint); //bottom line imageline($this->workingImage, 0, 0, 0, $height, $colorToPaint); //left line imageline($this->workingImage, $width - 1, 0, $width - 1, $height, $colorToPaint); //right line } $this->oldImage = $this->workingImage; $this->newImage = $this->workingImage; $this->currentDimensions['width'] = $width; $this->currentDimensions['height'] = $newHeight; }
protected function imageconvolution($src, $filter, $filter_div, $offset) { if ($src == NULL) { return 0; } $sx = imagesx($src); $sy = imagesy($src); $srcback = ImageCreateTrueColor($sx, $sy); ImageCopy($srcback, $src, 0, 0, 0, 0, $sx, $sy); if ($srcback == NULL) { return 0; } #FIX HERE #$pxl array was the problem so simply set it with very low values $pxl = array(1, 1); #this little fix worked for me as the undefined array threw out errors for ($y = 0; $y < $sy; ++$y) { for ($x = 0; $x < $sx; ++$x) { $new_r = $new_g = $new_b = 0; $alpha = imagecolorat($srcback, $pxl[0], $pxl[1]); $new_a = $alpha >> 24; for ($j = 0; $j < 3; ++$j) { $yv = min(max($y - 1 + $j, 0), $sy - 1); for ($i = 0; $i < 3; ++$i) { $pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv); $rgb = imagecolorat($srcback, $pxl[0], $pxl[1]); $new_r += ($rgb >> 16 & 0xff) * $filter[$j][$i]; $new_g += ($rgb >> 8 & 0xff) * $filter[$j][$i]; $new_b += ($rgb & 0xff) * $filter[$j][$i]; } } $new_r = $new_r / $filter_div + $offset; $new_g = $new_g / $filter_div + $offset; $new_b = $new_b / $filter_div + $offset; $new_r = $new_r > 255 ? 255 : ($new_r < 0 ? 0 : $new_r); $new_g = $new_g > 255 ? 255 : ($new_g < 0 ? 0 : $new_g); $new_b = $new_b > 255 ? 255 : ($new_b < 0 ? 0 : $new_b); $new_pxl = ImageColorAllocateAlpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a); if ($new_pxl == -1) { $new_pxl = ImageColorClosestAlpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a); } if ($y >= 0 && $y < $sy) { imagesetpixel($src, $x, $y, $new_pxl); } } } imagedestroy($srcback); return 1; }