本文整理汇总了PHP中imagefilledrectangle函数的典型用法代码示例。如果您正苦于以下问题:PHP imagefilledrectangle函数的具体用法?PHP imagefilledrectangle怎么用?PHP imagefilledrectangle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagefilledrectangle函数的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: Resize
public function Resize($image, $newWidth, $targetName)
{
if (!file_exists(PUBLIC_ROOT . $image)) {
$image = '/assets/images/not-found.gif';
}
$imgInfo = getimagesize(PUBLIC_ROOT . $image);
$oldWidth = $imgInfo[0];
$oldHeight = $imgInfo[1];
$changeRatio = $oldWidth / $newWidth;
$newHeight = round($oldHeight / $changeRatio);
$newImage = imagecreatetruecolor($newWidth, $newHeight);
$source = $this->load(PUBLIC_ROOT . $image);
if ($this->imageType == IMAGETYPE_PNG) {
imagealphablending($newImage, false);
imagesavealpha($newImage, true);
$transparent = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
imagefilledrectangle($newImage, 0, 0, $newWidth, $newHeight, $transparent);
}
imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight);
header('Content-Type: image/jpeg');
imagejpeg($newImage, $targetName, 100);
Debugger::debug($targetName, 'TARGET');
//$this->save($targetName);
$this->image = $newImage;
imagedestroy($newImage);
}
示例3: getImage
/**
* Return label image for product
* @param <type> $productId
*/
public function getImage($productId)
{
$product = Mage::getModel('catalog/product')->load($productId);
//create base image
$labelSize = Mage::helper('BarcodeLabel')->getlabelSize();
$height = $labelSize['height'] * $this->_coef;
$width = $labelSize['width'] * $this->_coef;
$im = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, $width, $height, $white);
//add barcode
$this->addBarcode($im, $product);
//add product name
$this->addName($im, $product);
//add product attributes
$this->addProductAttributes($im, $product);
//add manufacturer
$this->addManufacturer($im, $product);
//add logo
$this->addLogo($im);
// add product image
$this->addProductPicture($im, $product);
//add product sku
$this->addSku($im, $product);
//add price
$this->addPrice($im, $product);
//add price
$this->addCustoms($im, $product);
//return image
return $im;
}
示例4: getCode
function getCode($num, $w, $h)
{
// 去掉了 0 1 O l 等
$str = "23456789abcdefghijkmnpqrstuvwxyz";
$code = '';
for ($i = 0; $i < $num; $i++) {
$code .= $str[mt_rand(0, strlen($str) - 1)];
}
//将生成的验证码写入session,备验证页面使用
$_SESSION["my_checkcode"] = $code;
//创建图片,定义颜色值
Header("Content-type: image/PNG");
$im = imagecreate($w, $h);
$black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
$gray = imagecolorallocate($im, 118, 151, 199);
$bgcolor = imagecolorallocate($im, 235, 236, 237);
//画背景
imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
//画边框
imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray);
//imagefill($im, 0, 0, $bgcolor);
//在画布上随机生成大量点,起干扰作用;
for ($i = 0; $i < 80; $i++) {
imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
}
//将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx = rand(5, 10);
for ($i = 0; $i < $num; $i++) {
$strpos = rand(1, 6);
imagestring($im, 20, $strx, $strpos, substr($code, $i, 1), $black);
$strx += $w / 5;
}
imagepng($im);
imagedestroy($im);
}
示例5: fill_color
/**
* Background fill an image using the provided color
*
* @param int $width The desired width of the new image
* @param int $height The desired height of the new image
* @param Array the desired pad colors in RGB format, array should be array( 'top' => '', 'right' => '', 'bottom' => '', 'left' => '' );
*/
private function fill_color(array $colors)
{
$current_size = $this->editor->get_size();
$size = array('width' => $this->args['width'], 'height' => $this->args['height']);
$offsetLeft = ($size['width'] - $current_size['width']) / 2;
$offsetTop = ($size['height'] - $current_size['height']) / 2;
$new_image = imagecreatetruecolor($size['width'], $size['height']);
// This is needed to support alpha
imagesavealpha($new_image, true);
imagealphablending($new_image, false);
// Check if we are padding vertically or horizontally
if ($current_size['width'] != $size['width']) {
$colorToPaint = imagecolorallocatealpha($new_image, substr($colors['left'], 0, 3), substr($colors['left'], 3, 3), substr($colors['left'], 6, 3), substr($colors['left'], 9, 3));
// Fill left color
imagefilledrectangle($new_image, 0, 0, $offsetLeft + 5, $size['height'], $colorToPaint);
$colorToPaint = imagecolorallocatealpha($new_image, substr($colors['right'], 0, 3), substr($colors['right'], 3, 3), substr($colors['right'], 6, 3), substr($colors['left'], 9, 3));
// Fill right color
imagefilledrectangle($new_image, $offsetLeft + $current_size['width'] - 5, 0, $size['width'], $size['height'], $colorToPaint);
} elseif ($current_size['height'] != $size['height']) {
$colorToPaint = imagecolorallocatealpha($new_image, substr($colors['top'], 0, 3), substr($colors['top'], 3, 3), substr($colors['top'], 6, 3), substr($colors['left'], 9, 3));
// Fill top color
imagefilledrectangle($new_image, 0, 0, $size['width'], $offsetTop + 5, $colorToPaint);
$colorToPaint = imagecolorallocatealpha($new_image, substr($colors['bottom'], 0, 3), substr($colors['bottom'], 3, 3), substr($colors['bottom'], 6, 3), substr($colors['left'], 9, 3));
// Fill bottom color
imagefilledrectangle($new_image, 0, $offsetTop - 5 + $current_size['height'], $size['width'], $size['height'], $colorToPaint);
}
imagecopy($new_image, $this->editor->get_image(), $offsetLeft, $offsetTop, 0, 0, $current_size['width'], $current_size['height']);
$this->editor->update_image($new_image);
$this->editor->update_size();
}
示例6: 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;
}
示例7: init
/**
* Init Image and color background
*/
private function init()
{
if ($this->im === null) {
$this->im = imagecreatetruecolor($this->w, $this->h) or die('Can\'t Initialize the GD Libraty');
imagefilledrectangle($this->im, 0, 0, $this->w - 1, $this->h - 1, $this->color->allocate($this->im));
}
}
示例8: createThumb
/**
* Create thumbnail image by php using the GD Library
*
* @since 1.0.0
*/
public static function createThumb($source_image, $destination_image_url, $width, $height, $quality, $crop = null, $prefix = null, $checksize = null)
{
//Set image ratio
list($w, $h) = getimagesize($source_image);
// resize
if ($crop === true) {
if ($checksize && ($w < $width or $h < $height)) {
$width = $w + 1;
$height = $h + 1;
$x = 0;
} else {
$ratio = max($width / $w, $height / $h);
$h = $height / $ratio;
$x = ($w - $width / $ratio) / 2;
$w = $width / $ratio;
}
} else {
if ($checksize && ($w < $width or $h < $height)) {
$width = $w;
$height = $h;
$x = 0;
} else {
$ratio = min($width / $w, $height / $h);
$width = $w * $ratio;
$height = $h * $ratio;
$x = 0;
}
}
if (preg_match("/.jpg/i", "{$source_image}") or preg_match("/.jpeg/i", "{$source_image}")) {
//JPEG type thumbnail
$destImage = imagecreatetruecolor($width, $height);
$sourceImage = imagecreatefromjpeg($source_image);
imagecopyresampled($destImage, $sourceImage, 0, 0, $x, 0, $width, $height, $w, $h);
imagejpeg($destImage, $destination_image_url, $quality);
imagedestroy($destImage);
} elseif (preg_match("/.png/i", "{$source_image}")) {
//PNG type thumbnail
$destImage = imagecreatetruecolor($width, $height);
$sourceImage = imagecreatefrompng($source_image);
imagealphablending($destImage, false);
imagecopyresampled($destImage, $sourceImage, 0, 0, $x, 0, $width, $height, $w, $h);
imagesavealpha($destImage, true);
imagepng($destImage, $destination_image_url);
} elseif (preg_match("/.gif/i", "{$source_image}")) {
//GIF type thumbnail
$destImage = imagecreatetruecolor($width, $height);
$sourceImage = imagecreatefromgif($source_image);
$bgc = imagecolorallocate($destImage, 255, 255, 255);
imagefilledrectangle($destImage, 0, 0, $width, $height, $bgc);
imagecopyresampled($destImage, $sourceImage, 0, 0, $x, 0, $width, $height, $w, $h);
if (function_exists('imagegif')) {
// Pour GIF
header('Content-Type: image/gif');
imagegif($destImage, $destination_image_url, $quality);
}
imagedestroy($destImage);
} else {
echo 'unable to load image source';
}
}
示例9: create_image
function create_image()
{
$image = imagecreatetruecolor(200, 50);
$background_color = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, 200, 50, $background_color);
$line_color = imagecolorallocate($image, 255, 0, 255);
for ($i = 0; $i < 10; $i++) {
imageline($image, 0, rand() % 50, 200, rand() % 25, $line_color);
}
$pixel_color = imagecolorallocate($image, 255, 0, 255);
for ($i = 0; $i < 1000; $i++) {
imagesetpixel($image, rand() % 200, rand() % 50, $pixel_color);
}
$letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$len = strlen($letters);
$letter = $letters[rand(0, $len - 1)];
$text_color = imagecolorallocate($image, 0, 0, 0);
$word = "";
for ($i = 0; $i < 6; $i++) {
$letter = $letters[rand(0, $len - 1)];
imagestring($image, 5, 5 + $i * 30, 20, $letter, $text_color);
$word .= $letter;
}
$_SESSION['security_key'] = $word;
imagepng($image);
}
示例10: refresh
/**
* @param Thumbnail $thumbnail
* @return void
* @throws Exception\NoThumbnailAvailableException
*/
public function refresh(Thumbnail $thumbnail)
{
$temporaryPathAndFilename = null;
try {
$filename = pathinfo($thumbnail->getOriginalAsset()->getResource()->getFilename(), PATHINFO_FILENAME);
$temporaryLocalCopyFilename = $thumbnail->getOriginalAsset()->getResource()->createTemporaryLocalCopy();
$temporaryPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('ProcessedFontThumbnail-') . '.' . $filename . '.jpg';
$width = 1000;
$height = 1000;
$im = imagecreate($width, $height);
$red = imagecolorallocate($im, 0xff, 0xff, 0xff);
$black = imagecolorallocate($im, 0x0, 0x0, 0x0);
imagefilledrectangle($im, 0, 0, 1000, 1000, $red);
imagefttext($im, 48, 0, 80, 150, $black, $temporaryLocalCopyFilename, 'Neos Font Preview');
imagefttext($im, 32, 0, 80, 280, $black, $temporaryLocalCopyFilename, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
imagefttext($im, 32, 0, 80, 360, $black, $temporaryLocalCopyFilename, 'abcdefghijklmopqrstuvwxyz');
imagefttext($im, 32, 0, 80, 440, $black, $temporaryLocalCopyFilename, '1234567890');
imagefttext($im, 32, 0, 80, 560, $black, $temporaryLocalCopyFilename, '+ " * ç % & / ( ) = ? @ €');
imagejpeg($im, $temporaryPathAndFilename);
$resource = $this->resourceManager->importResource($temporaryPathAndFilename);
$processedImageInfo = $this->resize($thumbnail, $resource);
$thumbnail->setResource($processedImageInfo['resource']);
$thumbnail->setWidth($processedImageInfo['width']);
$thumbnail->setHeight($processedImageInfo['height']);
Files::unlink($temporaryPathAndFilename);
} catch (\Exception $exception) {
Files::unlink($temporaryPathAndFilename);
$filename = $thumbnail->getOriginalAsset()->getResource()->getFilename();
$sha1 = $thumbnail->getOriginalAsset()->getResource()->getSha1();
$message = sprintf('Unable to generate thumbnail for the given font (filename: %s, SHA1: %s)', $filename, $sha1);
throw new Exception\NoThumbnailAvailableException($message, 1433109653, $exception);
}
}
示例11: generateImage
private function generateImage()
{
// prepare image
$this->generatedImage = imagecreatetruecolor($this->getPixelRatio() * 5, $this->getPixelRatio() * 5);
$rgbBackgroundColor = $this->getBackgroundColor();
if (null === $rgbBackgroundColor) {
$background = imagecolorallocate($this->generatedImage, 0, 0, 0);
imagecolortransparent($this->generatedImage, $background);
} else {
$background = imagecolorallocate($this->generatedImage, $rgbBackgroundColor[0], $rgbBackgroundColor[1], $rgbBackgroundColor[2]);
imagefill($this->generatedImage, 0, 0, $background);
}
// prepage color
$rgbColor = $this->getColor();
$gdColor = imagecolorallocate($this->generatedImage, $rgbColor[0], $rgbColor[1], $rgbColor[2]);
// draw content
foreach ($this->getArrayOfSquare() as $lineKey => $lineValue) {
foreach ($lineValue as $colKey => $colValue) {
if (true === $colValue) {
imagefilledrectangle($this->generatedImage, $colKey * $this->getPixelRatio(), $lineKey * $this->getPixelRatio(), ($colKey + 1) * $this->getPixelRatio(), ($lineKey + 1) * $this->getPixelRatio(), $gdColor);
}
}
}
return $this;
}
示例12: create_captcha
function create_captcha($time)
{
@session_start();
$image;
global $image;
$word_1 = '';
$word_2 = "";
for ($i = 0; $i < 4; $i++) {
$word_1 .= chr(rand(97, 122));
}
for ($i = 0; $i < 4; $i++) {
$word_2 .= chr(rand(97, 122));
}
$_SESSION['random_number'] = $word_1 . ' ' . $word_2;
$dir = './fonts/';
$image = imagecreatetruecolor(165, 50);
$font = "recaptchaFont.ttf";
// font style
$color = imagecolorallocate($image, 0, 0, 0);
// color
$white = imagecolorallocate($image, 255, 255, 255);
// background color white
imagefilledrectangle($image, 0, 0, 709, 99, $white);
imagettftext($image, 22, 0, 5, 30, $color, $dir . $font, $_SESSION['random_number']);
$_SESSION['count'] = $_SESSION['random_number'];
$_SESSION['captcha_string'] = $_SESSION['random_number'];
$images = glob("./style/captcha/*.png");
foreach ($images as $image_to_delete) {
@unlink($image_to_delete);
}
imagepng($image, "./style/captcha/" . $time . ".png");
//return array('image'=>$image,'count'=>$_SESSION['count']);
}
示例13: getCaptcha
/**
* 生成验证码
* @param int $width 验证码图片宽度.默认130
* @param int $height 验证码图片高度.默认40
* @param int $fontSize 验证码字体大小.默认20
* @param int $length 验证码字符个数.默认4
* @return string 验证码中的字符串
*/
public static function getCaptcha($width = '130', $height = '40', $fontSize = '20', $length = '4')
{
$chars = '0123456789abcdefghijklmnopqrstuvwxyz';
$randStr = substr(str_shuffle($chars), 0, $length);
$image = imagecreatetruecolor($width, $height);
// 定义背景色
$bgColor = imagecolorallocate($image, 0xff, 0xff, 0xff);
// 定义文字及边框颜色
$blackColor = imagecolorallocate($image, 0x0, 0x0, 0x0);
//生成矩形边框
imagefilledrectangle($image, 0, 0, $width, $height, $bgColor);
// 循环生成雪花点
for ($i = 0; $i < 200; $i++) {
$grayColor = imagecolorallocate($image, 128 + rand(0, 128), 128 + rand(0, 128), 128 + rand(0, 128));
imagesetpixel($image, rand(1, $width - 2), rand(4, $height - 2), $grayColor);
}
$font = ROOT_PATH . 'resources/fonts/acidic.ttf';
// 把随机字符串输入图片
$i = -1;
while (isset($randStr[++$i])) {
$fontColor = imagecolorallocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
if (!function_exists('imagettftext')) {
imagechar($image, $fontSize, 15 + $i * 30, rand(5, 20), $randStr[$i], $fontColor);
} else {
imagettftext($image, $fontSize, 0, 10 + $i * 30, rand(25, 35), $fontColor, $font, $randStr[$i]);
}
}
imagepng($image);
$image = $bgColor = $blackColor = $grayColor = $fontColor = null;
return $randStr;
}
示例14: CreateCaptchaCanvas
protected function CreateCaptchaCanvas()
{
// Create the image
$this->image = imagecreatetruecolor($this->_conf['width'], $this->_conf['height']);
$white = imagecolorallocate($this->image, 255, 255, 255);
imagefilledrectangle($this->image, 0, 0, $this->_conf['width'], $this->_conf['height'], $white);
}
示例15: generate
public function generate()
{
foreach ($this->__shapes as $shape) {
$type = array_shift($shape);
$color = array_shift($shape);
$color = $this->_owner->imagecolorallocate(!isset($color) || is_null($color) ? $this->__base_color : $color, $this->__base_alpha);
switch ($type) {
case self::LINE:
imageline($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
break;
case self::RECTANGLE:
imagerectangle($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
break;
case self::FILLED_RECTANGLE:
imagefilledrectangle($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
break;
case self::ELLIPSE:
imageellipse($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
break;
case self::FILLED_ELLIPSE:
imagefilledellipse($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
break;
case self::SPIRAL:
$angle = $r = 0;
while ($r <= $shape[2]) {
imagearc($this->_owner->image, $shape[0], $shape[1], $r, $r, $angle - $shape[3], $angle, $color);
$angle += $shape[3];
$r++;
}
break;
}
}
return true;
}