本文整理汇总了PHP中imagecolorallocate函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorallocate函数的具体用法?PHP imagecolorallocate怎么用?PHP imagecolorallocate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorallocate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Génère l'avatar
*/
public function run()
{
//On créer l'image avec les dimentions données
$image = imagecreate($this->_size, $this->_size);
//On créer la couleur en fonction du hash de la chaine de caractères
$color = imagecolorallocate($image, hexdec(substr($this->_color, 0, 2)), hexdec(substr($this->_color, 2, 2)), hexdec(substr($this->_color, 4, 2)));
//on défini le fond de l'image (blanc)
$bg = imagecolorallocate($image, 255, 255, 255);
//nombre de blocs à placer dans l'image (taille de l'image/taille des blocs)
$c = $this->_size / $this->_blockSize;
for ($x = 0; $x < ceil($c / 2); $x++) {
for ($y = 0; $y < $c; $y++) {
// Si le nombre est pair $pixel vaut true sinon $pixel vaut false
$pixel = hexdec($this->_hash[(int) ($x * ceil($c / 2)) + $y]) % 2 == 0;
if ($pixel) {
$pixelColor = $color;
} else {
$pixelColor = $bg;
}
// On place chaque bloc de l'image
//imagefilledrectangle($image, $x*$this->_blockSize, $y*$this->_blockSize, ($x+1)*$this->_blockSize, ($y+1)*$this->_blockSize, $pixelColor);
//imagefilledrectangle($image, $this->_size-$x*$this->_blockSize, $y*$this->_blockSize, $this->_size-($x+1)*$this->_blockSize, ($y+1)*$this->_blockSize, $pixelColor);
imagefilledrectangle($image, $x * $this->_blockSize, $y * $this->_blockSize, ($x + 1) * $this->_blockSize, ($y + 1) * $this->_blockSize, $pixelColor);
imagefilledrectangle($image, $this->_size - $x * $this->_blockSize, $y * $this->_blockSize, $this->_size - ($x + 1) * $this->_blockSize, ($y + 1) * $this->_blockSize, $pixelColor);
}
}
ob_start();
imagepng($image);
//on place l'image en mémoire
$this->_image = ob_get_contents();
ob_clean();
}
示例2: 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;
}
示例3: load
static function load($filename)
{
$info = getimagesize($filename);
list($width, $height) = $info;
if (!$width || !$height) {
return null;
}
$image = null;
switch ($info['mime']) {
case 'image/gif':
$image = imagecreatefromgif($filename);
break;
case 'image/jpeg':
$image = imagecreatefromjpeg($filename);
break;
case 'image/png':
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);
$png = imagecreatefrompng($filename);
imagealphablending($png, true);
imagesavealpha($png, true);
imagecopy($image, $png, 0, 0, 0, 0, $width, $height);
imagedestroy($png);
break;
}
if ($image) {
return new image($image, $width, $height);
} else {
return null;
}
}
示例4: applyFilter
/**
* Applies the sepia filter to an image resource
*
* @param ImageResource $aResource
*/
public function applyFilter(ImageResource $aResource)
{
if ($this->degrees === 0) {
return;
}
$width = $aResource->getX();
$height = $aResource->getY();
// cache calculated colors in a map...
$colorMap = array();
for ($x = 0; $x < $width; ++$x) {
for ($y = 0; $y < $height; ++$y) {
$color = ColorUtil::getColorAt($aResource, Coordinate::create($x, $y));
if (!isset($colorMap[$color->getColorIndex()])) {
// calculate the new color
$hsl = ColorUtil::rgb2hsl($color->getRed(), $color->getGreen(), $color->getBlue());
$hsl[0] += $this->degrees;
$rgb = ColorUtil::hsl2rgb($hsl[0], $hsl[1], $hsl[2]);
$newcol = imagecolorallocate($aResource->getResource(), $rgb[0], $rgb[1], $rgb[2]);
$colorMap[$color->getColorIndex()] = $newcol;
} else {
$newcol = $colorMap[$color->getColorIndex()];
}
imagesetpixel($aResource->getResource(), $x, $y, $newcol);
}
}
$colorMap = null;
}
示例5: hacknrollify
function hacknrollify($picfilename)
{
$logofilename = "logo.png";
$logoPicPath = "logopics/" . $logofilename;
$originalPicPath = "originalpics/" . $picfilename;
$editedfilename = "hnr_" . $picfilename;
$editedPicPath = "editedpics/" . $editedfilename;
// read the original image from file
$profilepic = imagecreatefromjpeg($originalPicPath);
$profilepicWidth = imagesx($profilepic);
$profilepicHeight = imagesy($profilepic);
// create the black image overlay
$blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
imagecolorallocate($blackoverlay, 0, 0, 0);
// then merge the black and profilepic
imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
imagedestroy($blackoverlay);
// merge the resized logo
$logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
imageAlphaBlending($logo, false);
imageSaveAlpha($logo, true);
$logoWidth = imagesx($logo);
$logoHeight = imagesy($logo);
$verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
$horizontalOffset = 40;
imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
$mergeSuccess = imagejpeg($profilepic, $editedPicPath);
if (!$mergeSuccess) {
echo "Image merge failed!";
}
imagedestroy($profilepic);
imagedestroy($logo);
return $editedPicPath;
}
示例6: createImage
/**
* @param $text
* @return resource
*/
private function createImage($text)
{
if (!is_string($text) || trim($text) == '') {
$text = 'ERROR';
}
// Create an image from captchaBackground.png
$image = imagecreatefrompng(realpath('bundles/comun/images/captchaBackground.png'));
// Set the font colour
$colour = imagecolorallocate($image, 183, 178, 152);
// Set the font
//$font = '../fonts/Anorexia.ttf';
$font = realpath('bundles/comun/fonts/Anorexia.ttf');
// Set a random integer for the rotation between -15 and 15 degrees
$rotate = rand(-15, 15);
// Create an image using our original image and adding the detail
imagettftext($image, 14, $rotate, 18, 30, $colour, $font, $text);
// Output the image as a png
//imagepng($image);
/*return new Response(
$captchaText,
200,
array(
'Content-Type' => 'image/png',
'Cache-Control' => 'no-cache'
)
);*/
return $image;
}
示例7: prepareRowAsPng
/**
* Adds to the PNG image object, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS MULTILINESTRING object
* @param string $label Label for the GIS MULTILINESTRING object
* @param string $line_color Color for the GIS MULTILINESTRING object
* @param array $scale_data Array containing data related to scaling
* @param object $image Image object
*
* @return object the modified image object
* @access public
*/
public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image)
{
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(mb_substr($line_color, 1, 2));
$green = hexdec(mb_substr($line_color, 3, 2));
$blue = hexdec(mb_substr($line_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
$multilinestirng = mb_substr($spatial, 17, mb_strlen($spatial) - 19);
// Separate each linestring
$linestirngs = explode("),(", $multilinestirng);
$first_line = true;
foreach ($linestirngs as $linestring) {
$points_arr = $this->extractPoints($linestring, $scale_data);
foreach ($points_arr as $point) {
if (!isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section
imageline($image, $temp_point[0], $temp_point[1], $point[0], $point[1], $color);
$temp_point = $point;
}
}
unset($temp_point);
// print label if applicable
if (isset($label) && trim($label) != '' && $first_line) {
imagestring($image, 1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
}
$first_line = false;
}
return $image;
}
示例8: codeimage
static function codeimage()
{
$image = imagecreatetruecolor(100, 30);
$bgcolor = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $bgcolor);
$code = '';
for ($i = 0; $i < 4; $i++) {
$fontsize = 6;
$fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
$data = "abcdefghjkmnpqrstuvwxy3456789";
$fontcontent = substr($data, rand(1, strlen($data) - 1), 1);
$code .= $fontcontent;
$x = $i * 100 / 4 + rand(5, 10);
$y = rand(5, 10);
imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
}
for ($i = 0; $i < 200; $i++) {
$pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
imagesetpixel($image, rand(1, 99), rand(1, 29), $pointcolor);
}
for ($i = 0; $i < 2; $i++) {
$linecolor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220));
imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $linecolor);
}
$return['code'] = $code;
$return['image'] = $image;
return $return;
// header('content-type:image/png');
// imagepng($image);
}
示例9: render
/**
* Outputs the Captcha image.
*
* @param boolean html output
* @return mixed
*/
public function render($html)
{
// Creates a black image to start from
$this->image_create(Captcha::$config['background']);
// Add random white/gray arcs, amount depends on complexity setting
$count = (Captcha::$config['width'] + Captcha::$config['height']) / 2;
$count = $count / 5 * min(10, Captcha::$config['complexity']);
for ($i = 0; $i < $count; $i++) {
imagesetthickness($this->image, mt_rand(1, 2));
$color = imagecolorallocatealpha($this->image, 255, 255, 255, mt_rand(0, 120));
imagearc($this->image, mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(0, 360), mt_rand(0, 360), $color);
}
// Use different fonts if available
$font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
// Draw the character's white shadows
$size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / strlen($this->response));
$angle = mt_rand(-15 + strlen($this->response), 15 - strlen($this->response));
$x = mt_rand(1, Captcha::$config['width'] * 0.9 - $size * strlen($this->response));
$y = (Captcha::$config['height'] - $size) / 2 + $size;
$color = imagecolorallocate($this->image, 255, 255, 255);
imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, $font, $this->response);
// Add more shadows for lower complexities
Captcha::$config['complexity'] < 10 and imagefttext($this->image, $size, $angle, $x - 1, $y - 1, $color, $font, $this->response);
Captcha::$config['complexity'] < 8 and imagefttext($this->image, $size, $angle, $x - 2, $y + 2, $color, $font, $this->response);
Captcha::$config['complexity'] < 6 and imagefttext($this->image, $size, $angle, $x + 2, $y - 2, $color, $font, $this->response);
Captcha::$config['complexity'] < 4 and imagefttext($this->image, $size, $angle, $x + 3, $y + 3, $color, $font, $this->response);
Captcha::$config['complexity'] < 2 and imagefttext($this->image, $size, $angle, $x - 3, $y - 3, $color, $font, $this->response);
// Finally draw the foreground characters
$color = imagecolorallocate($this->image, 0, 0, 0);
imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response);
// Output
return $this->image_render($html);
}
示例10: resize
function resize($photo_src, $width, $name)
{
$parametr = getimagesize($photo_src);
list($width_orig, $height_orig) = getimagesize($photo_src);
$ratio_orig = $width_orig / $height_orig;
$new_width = $width;
$new_height = $width / $ratio_orig;
$newpic = imagecreatetruecolor($new_width, $new_height);
$col2 = imagecolorallocate($newpic, 255, 255, 255);
imagefilledrectangle($newpic, 0, 0, $new_width, $new_width, $col2);
switch ($parametr[2]) {
case 1:
$image = imagecreatefromgif($photo_src);
break;
case 2:
$image = imagecreatefromjpeg($photo_src);
break;
case 3:
$image = imagecreatefrompng($photo_src);
break;
}
imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
imagejpeg($newpic, $name, 100);
return true;
}
示例11: createMask
protected function createMask(sfImage $image, $w, $h)
{
// Create a mask png image of the area you want in the circle/ellipse (a 'magicpink' image with a black shape on it, with black set to the colour of alpha transparency) - $mask
$mask = $image->getAdapter()->getTransparentImage($w, $h);
// Set the masking colours
if (false === $this->getColor() || 'image/png' == $image->getMIMEType()) {
$mask_black = imagecolorallocate($mask, 0, 0, 0);
} else {
$mask_black = $image->getAdapter()->getColorByHex($mask, $this->getColor());
}
// Cannot use white as transparent mask if color is set to white
if ($this->getColor() === '#FFFFFF' || $this->getColor() === false) {
$mask_transparent = imagecolorallocate($mask, 255, 0, 0);
} else {
$mask_color = imagecolorsforindex($mask, imagecolorat($image->getAdapter()->getHolder(), 0, 0));
$mask_transparent = imagecolorallocate($mask, $mask_color['red'], $mask_color['green'], $mask_color['blue']);
}
imagecolortransparent($mask, $mask_transparent);
imagefill($mask, 0, 0, $mask_black);
// Draw the rounded rectangle for the mask
$this->imagefillroundedrect($mask, 0, 0, $w, $h, $this->getRadius(), $mask_transparent);
$mask_image = clone $image;
$mask_image->getAdapter()->setHolder($mask);
return $mask_image;
}
示例12: GetPartialImage
function GetPartialImage($url)
{
$W = 150;
$H = 130;
$F = 80;
$STEP = 1.0 / $F;
$im = imagecreatefromjpeg($url);
$dest = imagecreatetruecolor($W, $H);
imagecopy($dest, $im, 0, 0, 35, 40, $W, $H);
$a = 1;
for( $y = $H - $F; $y < $H; $y++ )
{
for ( $x = 0; $x < $W; $x++ )
{
$i = imagecolorat($dest, $x, $y);
$c = imagecolorsforindex($dest, $i);
$c = imagecolorallocate($dest,
a($c['red'], $a),
a($c['green'], $a),
a($c['blue'], $a)
);
imagesetpixel($dest, $x, $y, $c);
}
$a -= $STEP;
}
header('Content-type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($im);
}
示例13: testUploadFile
public function testUploadFile()
{
$album = $this->Album->init();
$tmp_file = "/tmp/111111111.jpg";
# Generate custom image to test upload
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagejpeg($im, $tmp_file);
# Generate path to save file
$file_path = $this->Picture->generateFilePath($album['Album']['id'], 'picturetests.jpg');
$file = new File($file_path);
# Get resize options
$resize_attrs = $this->Picture->getResizeToSize();
# Upload and save
$should_return_3 = $this->Picture->uploadFile($file_path, $album['Album']['id'], 'samplepicture.jpg', $tmp_file, $resize_attrs['width'], $resize_attrs['height'], $resize_attrs['action'], true);
# File was saved?
$this->assertEqual(3, $should_return_3);
# File was uploaded?
$this->assertTrue($file->exists());
# Should rise exception
try {
$this->Picture->uploadFile($file_path, null, 'samplepicture.jpg', $tmp_file, $resize_attrs['width'], $resize_attrs['height'], $resize_attrs['action'], true);
} catch (ForbiddenException $e) {
$this->assertEqual($e->getMessage(), "The album ID is required");
}
}
示例14: action_index
/**
* Processes incoming text
*/
public function action_index()
{
$this->request->headers['Content-type'] = 'image/png';
// Grab text and styles
$text = arr::get($_GET, 'text');
$styles = $_GET;
$hover = FALSE;
try {
// Create image
$img = new PNGText($text, $styles);
foreach ($styles as $key => $value) {
if (substr($key, 0, 6) == 'hover-') {
// Grab hover associated styles and override existing styles
$hover = TRUE;
$styles[substr($key, 6)] = $value;
}
}
if ($hover) {
// Create new hover image and stack it
$hover = new PNGText($text, $styles);
$img->stack($hover);
}
echo $img->draw();
} catch (Exception $e) {
if (Kohana::config('pngtext.debug')) {
// Dump error message in an image form
$img = imagecreatetruecolor(strlen($e->getMessage()) * 6, 16);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
imagestring($img, 2, 0, 0, $e->getMessage(), imagecolorallocate($img, 0, 0, 0));
echo imagepng($img);
}
}
}
示例15: graph_error
function graph_error($string)
{
global $vars, $config, $debug, $graphfile;
$vars['bg'] = 'FFBBBB';
include 'includes/graphs/common.inc.php';
$rrd_options .= ' HRULE:0#555555';
$rrd_options .= " --title='" . $string . "'";
rrdtool_graph($graphfile, $rrd_options);
if ($height > '99') {
shell_exec($rrd_cmd);
d_echo('<pre>' . $rrd_cmd . '</pre>');
if (is_file($graphfile) && !$debug) {
header('Content-type: image/png');
$fd = fopen($graphfile, 'r');
fpassthru($fd);
fclose($fd);
unlink($graphfile);
exit;
}
} else {
if (!$debug) {
header('Content-type: image/png');
}
$im = imagecreate($width, $height);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0));
imagepng($im);
imagedestroy($im);
exit;
}
}