本文整理汇总了PHP中imagecolordeallocate函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolordeallocate函数的具体用法?PHP imagecolordeallocate怎么用?PHP imagecolordeallocate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolordeallocate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getAvatar
public function getAvatar($string, $widthHeight = 12, $theme = 'default')
{
$widthHeight = max($widthHeight, 12);
$md5 = md5($string);
$fileName = _TMP_DIR_ . '/' . $md5 . '.png';
if ($this->tmpFileExists($fileName)) {
return $fileName;
}
// Create seed.
$seed = intval(substr($md5, 0, 6), 16);
mt_srand($seed);
$body = array('legs' => mt_rand(0, count($this->availableParts[$theme]['legs']) - 1), 'hair' => mt_rand(0, count($this->availableParts[$theme]['hair']) - 1), 'arms' => mt_rand(0, count($this->availableParts[$theme]['arms']) - 1), 'body' => mt_rand(0, count($this->availableParts[$theme]['body']) - 1), 'eyes' => mt_rand(0, count($this->availableParts[$theme]['eyes']) - 1), 'mouth' => mt_rand(0, count($this->availableParts[$theme]['mouth']) - 1));
// Avatar random parts.
$parts = array('legs' => $this->availableParts[$theme]['legs'][$body['legs']], 'hair' => $this->availableParts[$theme]['hair'][$body['hair']], 'arms' => $this->availableParts[$theme]['arms'][$body['arms']], 'body' => $this->availableParts[$theme]['body'][$body['body']], 'eyes' => $this->availableParts[$theme]['eyes'][$body['eyes']], 'mouth' => $this->availableParts[$theme]['mouth'][$body['mouth']]);
$avatar = imagecreate($widthHeight, $widthHeight);
imagesavealpha($avatar, true);
imagealphablending($avatar, false);
$background = imagecolorallocate($avatar, 0, 0, 0);
$line_colour = imagecolorallocate($avatar, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55);
imagecolortransparent($avatar, $background);
imagefilledrectangle($avatar, 0, 0, $widthHeight, $widthHeight, $background);
// Fill avatar with random parts.
foreach ($parts as &$part) {
$this->drawPart($part, $avatar, $widthHeight, $line_colour, $background);
}
imagepng($avatar, $fileName);
imagecolordeallocate($avatar, $line_colour);
imagecolordeallocate($avatar, $background);
imagedestroy($avatar);
return $fileName;
}
开发者ID:recallfx,项目名称:monsterid.php,代码行数:31,代码来源:MonsterId.php
示例2: color
static function color(&$imgage, $color = 'ffffff', $delete = false)
{
$cd = str_split($color, strlen($color) > 4 ? 2 : 1);
$color = imagecolorallocate($imgage, hexdec($cd[0]), hexdec($cd[1]), hexdec($cd[2]));
$delete && imagecolordeallocate($imgage, $color);
return $color;
}
开发者ID:mjiong,项目名称:framework,代码行数:7,代码来源:image.php
示例3: free
/**
* Free resources used for this color
*/
function free()
{
if ($this->resource !== NULL) {
@imagecolordeallocate($this->resource, $this->color);
$this->resource = NULL;
}
}
开发者ID:ber5ien,项目名称:www.jade-palace.co.uk,代码行数:10,代码来源:Color.class.php
示例4: renderImage
/**
* Renders the CAPTCHA image based on the code.
* @param string the verification code
* @return string image content
*/
protected function renderImage($code)
{
$image = imagecreatetruecolor($this->width, $this->height);
$backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100);
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor);
imagecolordeallocate($image, $backColor);
$foreColor = imagecolorallocate($image, (int) ($this->foreColor % 0x1000000 / 0x10000), (int) ($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100);
if ($this->fontFile === null) {
$this->fontFile = dirname(__FILE__) . '/Duality.ttf';
}
$len = strlen($code);
$fontSize = $this->height - $this->padding * 2;
for ($i = 0; $i < $len; $i++) {
$foreColor = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$angle = mt_rand(-20, 20);
$x = 5 + $fontSize * $i;
$y = 20;
imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $code[$i]);
imageline($image, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $foreColor);
}
imagecolordeallocate($image, $foreColor);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Transfer-Encoding: binary');
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
}
开发者ID:jackycgq,项目名称:24beta,代码行数:34,代码来源:CdCaptchaAction.php
示例5: color
static function color($res, $color = 'ffffff', $del = false)
{
$cr = str_split($color, strlen($color) > 4 ? 2 : 1);
$color = imagecolorallocate($res, hexdec($cr[0]), hexdec($cr[1]), hexdec($cr[2]));
if ($del) {
imagecolordeallocate($res, $color);
}
return $color;
}
开发者ID:art-youth,项目名称:framework,代码行数:9,代码来源:img.php
示例6: render
/**
* render module icon.
*
* @param string $fpath base image file
* @param string $dirname
* @param string $trustDirname
*/
public static function render($fpath, $dirname, $trustDirname)
{
self::_prepare();
if (!file_exists($fpath)) {
self::_error404();
}
$im = @imagecreatefrompng($fpath);
if ($im === false) {
self::_error404();
}
$mw = 79;
// maximum width of drawing area
$ox = 47;
// offset X
$oy = 12;
// offset Y (if same directory name)
$oy_d = 8;
// offset Y for $dirname
$oy_t = 19;
// offset Y for $trustDirname
$isSameDirname = $dirname == $trustDirname;
imagealphablending($im, true);
$color_d = imagecolorallocate($im, 0, 0, 0);
$color_t = imagecolorallocate($im, 0xa0, 0xa0, 0xa0);
// write dirname
$cw = self::_getStringWidth($dirname);
while ($cw > $mw) {
// trim string if over length
$dirname = substr($dirname, 0, -1);
$cw = self::_getStringWidth($dirname);
}
$x = $ox + ($mw - $cw) / 2;
$y = $isSameDirname ? $oy : $oy_d;
self::_writeString($im, $x, $y, $dirname, $color_d);
if (!$isSameDirname) {
// write trust dirname if different
$cw = self::_getStringWidth($trustDirname);
while ($cw > $mw) {
// trim string if over length
$dirname = substr($trustDirname, 0, -1);
$cw = self::_getStringWidth($dirname);
}
$x = $ox + ($mw - $cw) / 2;
$y = $oy_t;
self::_writeString($im, $x, $y, $trustDirname, $color_t);
}
self::_showImage($im);
imagecolordeallocate($im, $color_d);
imagecolordeallocate($im, $color_t);
imagedestroy($im);
self::_cleanup();
}
开发者ID:neuroinformatics,项目名称:xcl-module-cosmoapi,代码行数:59,代码来源:ModuleIcon.class.php
示例7: imagecopymerge_alpha
private function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct, $trans = NULL){
$dst_w = imagesx($dst_im);
$dst_h = imagesy($dst_im);
// bounds checking
$src_x = max($src_x, 0);
$src_y = max($src_y, 0);
$dst_x = max($dst_x, 0);
$dst_y = max($dst_y, 0);
if ($dst_x + $src_w > $dst_w){
$src_w = $dst_w - $dst_x;
}
if ($dst_y + $src_h > $dst_h){
$src_h = $dst_h - $dst_y;
}
for($x_offset = 0; $x_offset < $src_w; $x_offset++){
for($y_offset = 0; $y_offset < $src_h; $y_offset++){
// get source & dest color
$srccolor = imagecolorsforindex($src_im, imagecolorat($src_im, $src_x + $x_offset, $src_y + $y_offset));
$dstcolor = imagecolorsforindex($dst_im, imagecolorat($dst_im, $dst_x + $x_offset, $dst_y + $y_offset));
// apply transparency
if (is_null($trans) || ($srccolor !== $trans)){
$src_a = $srccolor['alpha'] * $pct / 100;
// blend
$src_a = 127 - $src_a;
$dst_a = 127 - $dstcolor['alpha'];
$dst_r = ($srccolor['red'] * $src_a + $dstcolor['red'] * $dst_a * (127 - $src_a) / 127) / 127;
$dst_g = ($srccolor['green'] * $src_a + $dstcolor['green'] * $dst_a * (127 - $src_a) / 127) / 127;
$dst_b = ($srccolor['blue'] * $src_a + $dstcolor['blue'] * $dst_a * (127 - $src_a) / 127) / 127;
$dst_a = 127 - ($src_a + $dst_a * (127 - $src_a) / 127);
$color = imagecolorallocatealpha($dst_im, $dst_r, $dst_g, $dst_b, $dst_a);
// paint
if (!imagesetpixel($dst_im, $dst_x + $x_offset, $dst_y + $y_offset, $color)){
return false;
}
imagecolordeallocate($dst_im, $color);
}
}
}
return true;
}
开发者ID:rockerest,项目名称:vertebrox,代码行数:44,代码来源:ImageCombine.php
示例8: showImage
function showImage()
{
$image = imagecreatetruecolor($this->width, $this->height);
$backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100);
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor);
imagecolordeallocate($image, $backColor);
imagecolortransparent($image, $backColor);
$text_color = imagecolorallocate($image, $this->text_color[0], $this->text_color[1], $this->text_color[2]);
$fontFile = dirname(__FILE__) . '/fonts/Duality.ttf';
$length = strlen($this->code);
$box = imagettfbbox(30, 0, $fontFile, $this->code);
$w = $box[4] - $box[0] + $this->offset * ($length - 1);
$h = $box[1] - $box[5];
$scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h);
$x = 10;
$y = round($this->height * 27 / 33);
for ($i = 0; $i < $length; ++$i) {
$fontSize = (int) (rand(26, 35) * $scale * 0.8);
$angle = rand(-20, 30);
$letter = $this->code[$i];
$o = rand(-2, 2);
$box = imagettftext($image, $fontSize, $angle, $x, $y, $text_color, $fontFile, $letter);
$x = $box[2] + $o;
}
if ($this->showLine) {
$line_color = imagecolorallocate($image, $this->line_color[0], $this->line_color[1], $this->line_color[2]);
for ($i = 0; $i < rand(4, 8); $i++) {
imageline($image, 1, rand(1, 50), rand(150, 180), rand(1, 50), $line_color);
}
}
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Transfer-Encoding: binary');
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
}
开发者ID:SwayWebStudio,项目名称:night.com,代码行数:38,代码来源:class.captcha.php
示例9: renderImageByGD
/**
* Renders the CAPTCHA image based on the code using GD library.
* @param string $code the verification code
* @return string image contents in PNG format.
*/
protected function renderImageByGD($code)
{
$image = imagecreatetruecolor($this->width, $this->height);
$backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100);
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor);
imagecolordeallocate($image, $backColor);
if ($this->transparent) {
imagecolortransparent($image, $backColor);
}
$foreColor = imagecolorallocate($image, (int) ($this->foreColor % 0x1000000 / 0x10000), (int) ($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100);
$length = strlen($code);
$box = imagettfbbox(30, 0, $this->fontFile, $code);
$w = $box[4] - $box[0] + $this->offset * ($length - 1);
$h = $box[1] - $box[5];
$scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h);
$x = 10;
$y = round($this->height * 27 / 40);
for ($i = 0; $i < $length; ++$i) {
$fontSize = (int) (rand(26, 32) * $scale * 0.8);
$angle = rand(-10, 10);
$letter = $code[$i];
$box = imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $letter);
$x = $box[2] + $this->offset;
}
imagecolordeallocate($image, $foreColor);
ob_start();
imagepng($image);
imagedestroy($image);
return ob_get_clean();
}
开发者ID:uxff,项目名称:yii2-advanced,代码行数:35,代码来源:CaptchaAction.php
示例10: renderImage
/**
* muestra la imagen CAPTCHA basada en el codigo.
* @param string el código de verificación
* @return string contenido imagen
*/
protected function renderImage($code)
{
$image = imagecreatetruecolor($this->width, $this->height);
$backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100);
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor);
imagecolordeallocate($image, $backColor);
$foreColor = imagecolorallocate($image, (int) ($this->foreColor % 0x1000000 / 0x10000), (int) ($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100);
if ($this->fontFile === null) {
$this->fontFile = CAPTCHA_VENDOR_DIR . 'Duality.ttf';
}
$offset = 2;
$length = strlen($code);
$box = imagettfbbox(30, 0, $this->fontFile, $code);
$w = $box[4] - $box[0] - $offset * ($length - 1);
$h = $box[1] - $box[5];
$scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h);
$x = 10;
$y = round($this->height * 27 / 40);
for ($i = 0; $i < $length; ++$i) {
$fontSize = (int) (rand(26, 32) * $scale * 0.8);
$angle = rand(-10, 10);
$letter = $code[$i];
$box = imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $letter);
$x = $box[2] - $offset;
}
imagecolordeallocate($image, $foreColor);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Transfer-Encoding: binary');
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
}
开发者ID:al3jandro,项目名称:Tellus,代码行数:39,代码来源:captcha.php
示例11: round
if ($type == 'date') {
$process[$country . '(' . $quantity . ' click)'] = $quantity;
} else {
$process[$country . '(' . round(intval($quantity) * 100 / $total, 2) . '%)'] = round(intval($quantity) * 100 / $total, 2);
}
}
# google chart intergrated :|
$imagechart = 'http://chart.apis.google.com/chart?chs=700x350&cht=p3&chco=7777CC|76A4FB|3399CC|3366CC|000000|7D5F5F|A94A4A|13E9E9|526767|DBD6D6&chd=t:';
$imagechart .= implode(',', array_values($process));
$imagechart .= '&chl=';
$imagechart .= implode('|', array_keys($process));
$imagechart .= '&chtt=Banner Stats';
$imagechart = str_replace(' ', '%20', $imagechart);
header("Content-type: image/png");
echo $geturl->get($imagechart);
} else {
$my_img = imagecreate(700, 80);
$background = imagecolorallocate($my_img, 255, 255, 255);
$text_colour = imagecolorallocate($my_img, 0, 0, 0);
$line_colour = imagecolorallocate($my_img, 128, 255, 0);
imagestring($my_img, 4, 30, 25, "no data", $text_colour);
imagesetthickness($my_img, 5);
imageline($my_img, 30, 45, 165, 45, $line_colour);
header("Content-type: image/png");
imagepng($my_img);
imagecolordeallocate($line_color);
imagecolordeallocate($text_color);
imagecolordeallocate($background);
imagedestroy($my_img);
}
}
开发者ID:anhtunguyen,项目名称:vietnamguide,代码行数:31,代码来源:viewmap.php
示例12: Create
//.........这里部分代码省略.........
$thumb_img = imagecreatetruecolor($resize_width, $resize_height);
if (!imagecopyresampled($thumb_img, $this->img, 0, 0, 0, 0, $resize_width, $resize_height, $width, $height)) {
return $this->ShowError("Error: Could not resize image!");
}
// fix these
$height = $resize_height;
$width = $resize_width;
// destroy original object
imagedestroy($this->img);
$this->img = $thumb_img;
}
// allocate colors for text
if ($text_color === -1) {
$text_color = imagecolorallocate($this->img, 255, 255, 255);
} else {
$text_color = imagecolorallocate($this->img, $text_color[0], $text_color[1], $text_color[2]);
}
// allocate colors for text shadow
if ($shadow_color === -1) {
$shadow_color = imagecolorallocate($this->img, 0, 0, 0);
} else {
$shadow_color = imagecolorallocate($this->img, $shadow_color[0], $shadow_color[1], $shadow_color[2]);
}
// next, we should try to create the text.. hopefully it wraps nicely
putenv('GDFONTPATH=' . realpath('.'));
// hack, just in case
// grab the font height, M is supposed to be big, with any random chars lying around
$font_height = $this->img_height(imagettfbbox($fontsize, 0, $font, 'Mjg'));
$row_spacing = intval($font_height * 0.2);
// purely arbitrary value
$space_width = $this->img_width(imagettfbbox($fontsize, 0, $font, ' '));
// try and do our best imitation of wordwrapping
$text_elements = explode(' ', str_replace("\n", '', str_replace("\r\n", '', $text)));
// adjust this depending on alignment
$top = $padding + $font_height;
$left = $padding;
// initialize
$line_width = 0;
$line_beginning = 0;
// index of beginning of line
$inc = 1;
$c = count($text_elements);
$i = 0;
if ($align[0] == 'b') {
$top = $height - $padding;
$font_height = $font_height * -1;
$row_spacing = $row_spacing * -1;
$inc = -1;
$i = $c - 1;
}
$dbg = get_get_var('dbg');
$line_beginning = $i;
// draw text elements starting from alignment position..
for (; $i >= 0 && $i < $c; $i += $inc) {
$lf_width = $this->img_width(imagettfbbox($fontsize, 0, $font, $text_elements[$i]));
// add a space
if ($i != $line_beginning) {
$lf_width += $space_width;
}
// see if we've exceeded the max width
if ($lf_width + $line_width + $padding * 2 > $width) {
// draw it out then!
if ($align[1] == 'r') {
$left = $width - $padding - $line_width;
}
if ($align[0] == 'b') {
$text = implode(' ', array_slice($text_elements, $i + 1, $line_beginning - $i));
} else {
$text = implode(' ', array_slice($text_elements, $line_beginning, $i - $line_beginning));
}
// draw the text
imagettftext($this->img, $fontsize, 0, $left - 1, $top + 1, $shadow_color, $font, $text);
imagettftext($this->img, $fontsize, 0, $left, $top, $text_color, $font, $text);
// keep moving, reset params
$top += $font_height + $row_spacing;
$line_beginning = $i;
$line_width = $lf_width;
} else {
// keep trucking
$line_width += $lf_width;
}
}
// get the last line too
if ($line_width != 0) {
if ($align[1] == 'r') {
$left = $width - $padding - $line_width;
}
if ($align[0] == 'b') {
$text = implode(' ', array_slice($text_elements, $i + 1, $line_beginning - $i));
} else {
$text = implode(' ', array_slice($text_elements, $line_beginning, $i - $line_beginning));
}
imagettftext($this->img, $fontsize, 0, $left - 1, $top + 1, $shadow_color, $font, $text);
imagettftext($this->img, $fontsize, 0, $left, $top, $text_color, $font, $text);
}
imagecolordeallocate($this->img, $shadow_color);
imagecolordeallocate($this->img, $text_color);
restore_error_handler();
return true;
}
开发者ID:GerryG,项目名称:newz,代码行数:101,代码来源:lolcats.inc.php
示例13: GenerateLegend
function GenerateLegend()
{
global $sessionID, $mapName, $width, $height, $offsetX, $offsetY, $xPad, $yPad, $iconWidth, $iconHeight, $xIndent, $groupIcon, $fontIndex, $textColor;
$userInfo = new MgUserInformation($sessionID);
$siteConnection = new MgSiteConnection();
$siteConnection->Open($userInfo);
$resourceService = $siteConnection->CreateService(MgServiceType::ResourceService);
$mappingService = $siteConnection->CreateService(MgServiceType::MappingService);
$map = new MgMap();
$map->Open($resourceService, $mapName);
$scale = $map->GetViewScale();
CompileVisibleLayerCount($map);
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
$textColor = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $width, $height, $white);
//Uncomment regions marked with BEGIN DEBUG / END DEBUG and comment out regions marked with
//BEGIN COMMENT OUT IF DEBUGGING / END COMMENT OUT IF DEBUGGING to see what PHP-isms get spewed out
//that may be tripping up rendering
//
//Also replace instances of "////print_r" with "//print_r" to insta-uncomment all debugging calls
//==BEGIN DEBUG==
//header("Content-type: text/html", true);
//==END DEBUG==
ProcessGroupsForLegend($mappingService, $resourceService, $map, $scale, NULL, $image);
//==BEGIN COMMENT OUT IF DEBUGGING==
header("Content-type: image/png");
imagepng($image);
//==END COMMENT OUT IF DEBUGGING==
//==BEGIN DEBUG==
/*
ob_start();
imagepng($image);
$im = base64_encode(ob_get_contents());
ob_end_clean();
echo "<img src='data:image/png;base64,".$im."' alt='legend image'></img>";
*/
//==END DEBUG==
imagecolordeallocate($image, $white);
imagecolordeallocate($image, $textColor);
imagedestroy($image);
}
开发者ID:kanbang,项目名称:Colt,代码行数:42,代码来源:GenerateLegend.php
示例14: update_media
function update_media($media)
{
parent::update_media($media);
/**
* Here we use a small hack; media height and width (in millimetres) match
* the size of screenshot (in pixels), so we take them as-is
*/
$this->_heightPixels = $media->height();
$this->_widthPixels = $media->width();
$this->_image = imagecreatetruecolor($this->_widthPixels, $this->_heightPixels);
/**
* Render white background
*/
$white = imagecolorallocate($this->_image, 255, 255, 255);
imagefill($this->_image, 0, 0, $white);
imagecolordeallocate($this->_image, $white);
$this->_color[0] = array('rgb' => array(0, 0, 0), 'object' => imagecolorallocate($this->_image, 0, 0, 0));
/**
* Setup initial clipping region
*/
$this->_clipping = array();
$this->_saveClip(new Rectangle(new Point(0, 0), new Point($this->_widthPixels - 1, $this->_heightPixels - 1)));
$this->_transform = new AffineTransform($this->_heightPixels, $this->_widthPixels / mm2pt($this->media->width()), $this->_heightPixels / mm2pt($this->media->height()));
}
开发者ID:VUW-SIM-FIS,项目名称:emiemi,代码行数:24,代码来源:output.png.class.php
示例15: CenterSquarify
/**
* Crops the image to the biggest fitting, centered square
*
*/
function CenterSquarify(ArgbColor $backgroundColor = null)
{
$width = $this->Width();
$height = $this->Height();
$squareSize = min($width, $height);
$xOrigin = 0;
$yOrigin = 0;
if ($width > $squareSize) {
$xOrigin = round(($width - $squareSize) / 2);
} else {
if ($height > $squareSize) {
$yOrigin = round(($height - $squareSize) / 2);
}
}
$destRes = \imagecreatetruecolor($squareSize, $squareSize);
if ($backgroundColor) {
$colRes = \imagecolorallocate($destRes, $backgroundColor->GetRed(), $backgroundColor->GetGreen(), $backgroundColor->GetBlue());
\imagefill($destRes, 0, 0, $colRes);
\imagecolordeallocate($destRes, $colRes);
}
\imagecopy($destRes, $this->resource, 0, 0, $xOrigin, $yOrigin, $squareSize, $squareSize);
$this->AssignResource($destRes);
}
开发者ID:agentmedia,项目名称:phine-framework,代码行数:27,代码来源:Image.php
示例16: complexImg
function complexImg()
{
if (isset(FileGen::$cliOpts['help'])) {
echo "\n";
echo "available options for subScript 'complexImg':\n";
// modeMask
echo "--talentbgs (backgrounds for talent calculator)\n";
// 0x01
echo "--maps (generates worldmaps)\n";
// 0x02
echo "--spawn-maps (creates alphaMasks of each zone to check spawns against)\n";
// 0x04
echo "--artwork (optional: imagery from /glues/credits (not used, skipped by default))\n";
// 0x08
echo "--area-maps (optional: renders maps with highlighted subZones for each area)\n";
// 0x10
return true;
}
$mapWidth = 1002;
$mapHeight = 668;
$threshold = 95;
// alpha threshold to define subZones: set it too low and you have unspawnable areas inside a zone; set it too high and the border regions overlap
$runTime = ini_get('max_execution_time');
$locStr = null;
$dbcPath = CLISetup::$srcDir . '%sDBFilesClient/';
$imgPath = CLISetup::$srcDir . '%sInterface/';
$destDir = 'static/images/wow/';
$success = true;
$paths = ['WorldMap/', 'TalentFrame/', 'Glues/Credits/'];
$modeMask = 0x7;
// talentBGs, regular maps, spawn-related alphaMaps
$createAlphaImage = function ($w, $h) {
$img = imagecreatetruecolor($w, $h);
imagesavealpha($img, true);
imagealphablending($img, false);
$bgColor = imagecolorallocatealpha($img, 0, 0, 0, 127);
imagefilledrectangle($img, 0, 0, imagesx($img) - 1, imagesy($img) - 1, $bgColor);
imagecolortransparent($img, $bgColor);
imagealphablending($img, true);
imagecolordeallocate($img, $bgColor);
return $img;
};
// prefer manually converted PNG files (as the imagecreatefromblp-script has issues with some formats)
// alpha channel issues observed with locale deDE Hilsbrad and Elwynn - maps
// see: https://github.com/Kanma/BLPConverter
$loadImageFile = function ($path) {
$result = null;
$file = $path . '.png';
if (CLISetup::fileExists($file)) {
CLISetup::log('manually converted png file present for ' . $path . '.', CLISetup::LOG_WARN);
$result = imagecreatefrompng($file);
}
if (!$result) {
$file = $path . '.blp';
if (CLISetup::fileExists($file)) {
$result = imagecreatefromblp($file);
}
}
return $result;
};
$assembleImage = function ($baseName, $order, $w, $h) use($loadImageFile) {
$dest = imagecreatetruecolor($w, $h);
imagesavealpha($dest, true);
imagealphablending($dest, false);
$_h = $h;
foreach ($order as $y => $row) {
$_w = $w;
foreach ($row as $x => $suffix) {
$src = $loadImageFile($baseName . $suffix);
if (!$src) {
CLISetup::log(' - complexImg: tile ' . $baseName . $suffix . '.blp missing.', CLISetup::LOG_ERROR);
unset($dest);
return null;
}
imagecopyresampled($dest, $src, 256 * $x, 256 * $y, 0, 0, min($_w, 256), min($_h, 256), min($_w, 256), min($_h, 256));
$_w -= 256;
unset($src);
}
$_h -= 256;
}
return $dest;
};
$writeImage = function ($name, $ext, $src, $w, $h, $done) {
$ok = false;
$dest = imagecreatetruecolor($w, $h);
imagesavealpha($dest, true);
imagealphablending($dest, false);
imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, imagesx($src), imagesy($src));
switch ($ext) {
case 'jpg':
$ok = imagejpeg($dest, $name . '.' . $ext, 85);
break;
case 'png':
$ok = imagepng($dest, $name . '.' . $ext);
break;
default:
CLISetup::log($done . ' - unsupported file fromat: ' . $ext, CLISetup::LOG_WARN);
}
imagedestroy($dest);
if ($ok) {
//.........这里部分代码省略.........
开发者ID:Carbenium,项目名称:aowow,代码行数:101,代码来源:complexImg.func.php
示例17: renderImage
protected function renderImage($code)
{
if ($this->mode == self::MODE_MATH_ADVANCED) {
$code = $this->showCode($code);
}
$image = imagecreatetruecolor($this->width, $this->height);
$backColor = imagecolorallocate($image, (int) ($this->backColor % 0x1000000 / 0x10000), (int) ($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100);
imagefilledrectangle($image, 0, 0, $this->width, $this->height, $backColor);
imagecolordeallocate($image, $backColor);
if ($this->transparent) {
imagecolortransparent($image, $backColor);
}
$foreColor = imagecolorallocate($image, (int) ($this->foreColor % 0x1000000 / 0x10000), (int) ($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100);
if ($this->fontFile === null) {
$this->fontFile = dirname(__FILE__) . '/fonts/Duality.ttf';
}
$length = strlen($code);
$box = imagettfbbox(30, 0, $this->fontFile, $code);
$w = $box[4] - $box[0] + $this->offset * ($length - 1);
$h = $box[1] - $box[5];
$scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h);
$x = 10;
$y = round($this->height * 27 / 40);
if ($this->useAdvanced) {
// random font color
$r = (int) ($this->foreColor % 0x1000000 / 0x10000);
$g = (int) ($this->foreColor % 0x10000 / 0x100);
$b = $this->foreColor % 0x100;
$foreColor = imagecolorallocate($image, mt_rand($r - 50, $r + 50), mt_rand($g - 50, $g + 50), mt_rand($b - 50, $b + 50));
}
for ($i = 0; $i < $length; ++$i) {
$fontSize = (int) (rand(26, 32) * $scale * 0.8);
$angle = rand(-10, 10);
$letter = $code[$i];
if ($this->useAdvanced) {
// random font color
if (mt_rand(0, 10) > 7) {
$foreColor = imagecolorallocate($image, mt_rand($r - 50, $r + 50), mt_rand($g - 50, $g + 50), mt_rand($b - 50, $b + 50));
}
}
$box = imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $letter);
$x = $box[2] + $this->offset;
}
if ($this->useAdvanced) {
// add density dots
$this->density = (int) $this->density;
if ($this->density > 0) {
$length = intval($this->width * $this->height / 100 * $this->density);
$c = imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
for ($i = 0; $i < $length; ++$i) {
$x = mt_rand(0, $this->width);
$y = mt_rand(0, $this->height);
imagesetpixel($image, $x, $y, $c);
}
}
// add lines
$this->lines = (int) $this->lines;
if ($this->lines > 0) {
for ($i = 0; $i < $this->lines; ++$i) {
imagesetthickness($image, mt_rand(1, 2));
// gray lines only to save human eyes:-)
$c = imagecolorallocate($image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255));
$x = mt_rand(0, $this->width);
$y = mt_rand(0, $this->width);
imageline($image, $x, 0, $y, $this->height, $c);
}
}
// filled flood section
$this->fillSections = (int) $this->fillSections;
if ($this->fillSections > 0) {
for ($i = 0; $i < $this->fillSections; ++$i) {
$c = imagecolorallocate($image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255));
$x = mt_rand(0, $this->width);
$y = mt_rand(0, $this->width);
imagefill($image, $x, $y, $c);
}
}
}
imagecolordeallocate($image, $foreColor);
if (ob_get_contents()) {
ob_clean();
}
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Transfer-Encoding: binary');
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
}
开发者ID:barricade86,项目名称:raui,代码行数:90,代码来源:MathCCaptchaAction.php
示例18: _drawRadar
//.........这里部分代码省略.........
// Draw the axes value text
//-----------------------------------------
$numticks = $this->options['numticks'] > $maxvalue ? floor($maxvalue) : $this->options['numticks'];
$tick = $maxvalue / $numticks;
for ($j = 0; $j < $this->options['numticks']; $j++) {
$value = ($j + 1) * $tick;
if ($this->use_ttf) {
$textsize = imagettfbbox(10, 0, $this->options['font'], $value);
$textheight = $textsize[1] - $textsize[5];
imagettftext($this->image, "10", 0, $webtickxy[$j][0] + 6, $webtickxy[$j][1] + floor($textheight / 2) + 1, $shadowcolor, $this->options['font'], $value);
imagettftext($this->image, "10", 0, $webtickxy[$j][0] + 5, $webtickxy[$j][1] + floor($textheight / 2), $textcolor, $this->options['font'], $value);
} else {
imagestring($this->image, $this->fontsize, $webtickxy[$j][0] + 6, $webtickxy[$j][1] - floor(imagefontheight($this->fontsize) / 2) + 1, $value, $shadowcolor);
imagestring($this->image, $this->fontsize, $webtickxy[$j][0] + 5, $webtickxy[$j][1] - floor(imagefontheight($this->fontsize) / 2), $value, $textcolor);
}
}
//-----------------------------------------
// Draw the series
//-----------------------------------------
$numseries = count($this->data['yaxis']);
for ($ci = 0; $ci < $numseries; $ci++) {
if (!isset($this->color[$ci])) {
$this->color[$ci] = explode(",", $this->_getSliceColor($this->data['yaxis'][$ci]['color']));
}
$linecolor = ImageColorAllocate($this->image, $this->color[$ci][0], $this->color[$ci][1], $this->color[$ci][2]);
$dotcolor = imagecolorallocate($this->image, $this->color[$ci][0], $this->color[$ci][1], $this->color[$ci][2]);
$dotshadowcolor = imagecolorallocate($this->image, $this->color[$ci][0] - 50 < 0 ? 0 : $this->color[$ci][0] - 50, $this->color[$ci][1] - 50 < 0 ? 0 : $this->color[$ci][1] - 50, $this->color[$ci][2] - 50 < 0 ? 0 : $this->color[$ci][2] - 50);
//-----------------------------------------
// Get the x and y's for the lines
//-----------------------------------------
$linesxy = array();
$lineshadowxy = array();
$textxy = array();
for ($i = 0; $i < $numaxes; $i++) {
$value = $this->data['yaxis'][$ci]['data'][$i];
$rotation = -90 + round($i * 360 / $numaxes, 0);
$linesxy[$i * 2] = $xmid + cos(deg2rad($rotation)) * floor($value / $maxvalue * $armlength);
$linesxy[$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * floor($value / $maxvalue * $armlength);
$lineshadowxy[$i * 2] = $linesxy[$i * 2] + 1;
$lineshadowxy[$i * 2 + 1] = $linesxy[$i * 2 + 1] + 1;
if ($this->options['showdatalabels']) {
// Calculate the datalabel positions
$textxy[$i * 2] = $xmid + cos(deg2rad($rotation)) * floor($value / $maxvalue * $armlength + 5);
$textxy[$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * floor($value / $maxvalue * $armlength + 5);
if ($this->use_ttf) {
$textsize = imagettfbbox(10, 0, $this->options['font'], $value);
$textwidth = $textsize[4] - $textsize[0];
$textheight = $textsize[1] - $textsize[5];
} else {
$textwidth = imagefontwidth($this->fontsize) * strlen($value);
$textheight = imagefontheight($this->fontsize);
}
if ($rotation > -90 && $rotation < 90) {
$textxy[$i * 2] = $textxy[$i * 2] + 5;
$textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + floor($textheight / 2);
} elseif ($rotation == -90) {
$textxy[$i * 2] = $textxy[$i * 2] - floor($textwidth / 2);
$textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] - 5;
} elseif ($rotation == 90) {
$textxy[$i * 2] = $textxy[$i * 2] - floor($textwidth / 2);
$textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + 5 + $textheight;
} else {
$textxy[$i * 2] = $textxy[$i * 2] - 5 - $textwidth;
$textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + floor($textheight / 2);
}
}
}
//-----------------------------------------
// Draw the lines, dots and text
//-----------------------------------------
imagepolygon($this->image, $linesxy, $numaxes, $linecolor);
imagepolygon($this->image, $lineshadowxy, $numaxes, $dotshadowcolor);
$valuecolor = ImageColorAllocate($this->image, hexdec(substr($this->options['textcolor'], 1, 2)), hexdec(substr($this->options['textcolor'], 3, 2)), hexdec(substr($this->options['textcolor'], 5, 2)));
$valshadecolor = imagecolorallocate($this->image, $this->color[$ci][0] - 50 < 0 ? 0 : $this->color[$ci][0] - 50, $this->color[$ci][1] - 50 < 0 ? 0 : $this->color[$ci][1] - 50, $this->color[$ci][2] - 50 < 0 ? 0 : $this->color[$ci][2] - 50);
for ($i = 0; $i < $numaxes; $i++) {
imagefilledellipse($this->image, $linesxy[$i * 2] + 1, $linesxy[$i * 2 + 1] + 1, 7, 7, $dotshadowcolor);
imagefilledellipse($this->image, $linesxy[$i * 2], $linesxy[$i * 2 + 1], 7, 7, $dotcolor);
if ($this->options['showdatalabels']) {
$value = $this->data['yaxis'][$ci]['data'][$i];
if ($this->use_ttf) {
imagettftext($this->image, "10", 0, $textxy[$i * 2] - 1, $textxy[$i * 2 + 1] - 1, $valshadecolor, $this->options['font'], $value);
imagettftext($this->image, "10", 0, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1, $valshadecolor, $this->options['font'], $value);
imagettftext($this->image, "10", 0, $textxy[$i * 2] + 2, $textxy[$i * 2 + 1] + 2, $valshadecolor, $this->options['font'], $value);
imagettftext($this->image, "10", 0, $textxy[$i * 2], $textxy[$i * 2 + 1], $valuecolor, $this->options['font'], $value);
} else {
imagestring($this->image, $this->fontsize, $textxy[$i * 2] - 1, $textxy[$i * 2 + 1] - 1 - imagefontheight($this->fontsize), $label, $valshadecolor);
imagestring($this->image, $this->fontsize, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1 - imagefontheight($this->fontsize), $label, $valshadecolor);
imagestring($this->image, $this->fontsize, $textxy[$i * 2] + 2, $textxy[$i * 2 + 1] + 2 - imagefontheight($this->fontsize), $label, $valshadecolor);
|
请发表评论