本文整理汇总了PHP中imagepng函数的典型用法代码示例。如果您正苦于以下问题:PHP imagepng函数的具体用法?PHP imagepng怎么用?PHP imagepng使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagepng函数的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: smart_spam
function smart_spam($code)
{
@putenv('GDFONTPATH=' . realpath('.'));
$font = 'FONT.TTF';
// antispam image height
$height = 40;
// antispam image width
$width = 110;
$font_size = $height * 0.6;
$image = @imagecreate($width, $height);
$background_color = @imagecolorallocate($image, 255, 255, 255);
$noise_color = @imagecolorallocate($image, 20, 40, 100);
/* add image noise */
for ($i = 0; $i < $width * $height / 4; $i++) {
@imageellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
}
/* render text */
$text_color = @imagecolorallocate($image, 20, 40, 100);
@imagettftext($image, $font_size, 0, 7, 29, $text_color, $font, $code) or die('Cannot render TTF text.');
//output image to the browser *//*
header('Content-Type: image/png');
@imagepng($image) or die('imagepng error!');
@imagedestroy($image);
exit;
}
示例4: save
function save($handle, $uri = null, $compression = 9, $filters = PNG_ALL_FILTERS)
{
if ($compression > 9) {
$compression *= 9 / 100;
}
return imagepng($handle, $uri, $compression, $filters);
}
示例5: 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);
}
示例6: makeDataMatrix
function makeDataMatrix($code, $path)
{
$x = 70;
// barcode center
$y = 70;
// barcode center
$height = 125;
// barcode height in 1D ; module size in 2D
$width = 4;
// barcode height in 1D ; not use in 2D
$angle = 90;
// rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
$type = 'datamatrix';
$im = imagecreatetruecolor(140, 140);
$black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
$white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
$red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
$blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
imagefilledrectangle($im, 0, 0, 140, 140, $white);
$data = \BarcodeGEN::gd($im, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height);
/*for($i=1; $i<5; $i++){
drawCross($im, $blue, $data['p'.$i]['x'], $data['p'.$i]['y']);
}*/
imagepng($im, $path);
imagedestroy($im);
}
示例7: save
public function save()
{
$maxHeight = 0;
$width = 0;
foreach ($this->_segmentsArray as $segment) {
$maxHeight = max($maxHeight, $segment->height);
$width += $segment->width;
}
// create our canvas
$img = imagecreatetruecolor($width, $maxHeight);
$background = imagecolorallocatealpha($img, 255, 255, 255, 127);
imagefill($img, 0, 0, $background);
imagealphablending($img, false);
imagesavealpha($img, true);
// start placing our images on a single x axis
$xPos = 0;
foreach ($this->_segmentsArray as $segment) {
$tmp = imagecreatefromjpeg($segment->pathToImage);
imagecopy($img, $tmp, $xPos, 0, 0, 0, $segment->width, $segment->height);
$xPos += $segment->width;
imagedestroy($tmp);
}
// create our final output image.
imagepng($img, $this->_saveToPath);
}
示例8: 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);
}
示例9: __image
private static function __image()
{
self::__background();
self::__adulterate();
self::__font();
header("Expires: 0" . PHP_EOL);
header("Cache-Control: no-cache" . PHP_EOL);
header("Pragma: no-cache" . PHP_EOL);
if (function_exists('imagejpeg')) {
header('Content-type:image/jpeg' . PHP_EOL);
$void = imagejpeg(self::$im);
} else {
if (function_exists('imagepng')) {
header('Content-type:image/png' . PHP_EOL);
$void = imagepng(self::$im);
} else {
if (function_exists('imagegif')) {
header('Content-type:image/gif' . PHP_EOL);
$void = imagegif(self::$im);
} else {
return false;
}
}
}
imagedestroy(self::$im);
return $void;
}
示例10: createSemacode
public function createSemacode($info, $name)
{
$_img = $this->_semacode->asGDImage($info, 120);
header('Content-Type: image/png');
imagepng($_img, "/tmp/{$name}.png");
imagedestroy($_img);
}
示例11: setUp
function setUp() {
parent::setUp();
if(!file_exists(ASSETS_PATH)) mkdir(ASSETS_PATH);
// Create a test folders for each of the fixture references
$folderIDs = $this->allFixtureIDs('Folder');
foreach($folderIDs as $folderID) {
$folder = DataObject::get_by_id('Folder', $folderID);
if(!file_exists(BASE_PATH."/$folder->Filename")) mkdir(BASE_PATH."/$folder->Filename");
}
// Create a test files for each of the fixture references
$fileIDs = $this->allFixtureIDs('Image');
foreach($fileIDs as $fileID) {
$file = DataObject::get_by_id('Image', $fileID);
$image = imagecreatetruecolor(300,300);
imagepng($image, BASE_PATH."/$file->Filename");
imagedestroy($image);
$file->write();
}
}
示例12: __construct
/**
* Class constructor generates the CAPTCHA image.
*
* @return blob the image
* @access public
*/
function __construct()
{
session_start();
$image = imagecreate($this->width, $this->height);
$random_str = $this->gen_str($this->chars_nr);
#md5( microtime() ); // md5 to generate the random string
$result_str = substr($random_str, 0, $this->chars_nr);
//trim $chars_nr digit
$bg_color = imagecolorallocate($image, $this->background_color['red'], $this->background_color['green'], $this->background_color['blue']);
// background color
$tx_color = imagecolorallocate($image, $this->text_color['red'], $this->text_color['gree'], $this->text_color['blue']);
// text color
for ($i = 0; $i <= $this->lines; $i++) {
$line_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
//line color
imageline($image, rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), $line_color);
// Create lines on image
}
imagestring($image, 5, 20, 10, $result_str, $tx_color);
// Draw a random string horizontally
$_SESSION['key'] = $result_str;
// Carry the data through session
header("Content-type: image/png");
// Out out the image
imagepng($image);
// Output image to browser
}
示例13: writeToCache
function writeToCache($ID, $pChartObject)
{
/* Compute the paths */
$TemporaryFile = $this->CacheFolder . "/tmp_" . rand(0, 1000) . ".png";
$Database = $this->CacheFolder . "/" . $this->CacheDB;
$Index = $this->CacheFolder . "/" . $this->CacheIndex;
/* Flush the picture to a temporary file */
imagepng($pChartObject->Picture, $TemporaryFile);
/* Retrieve the files size */
$PictureSize = filesize($TemporaryFile);
$DBSize = filesize($Database);
/* Save the index */
$Handle = fopen($Index, "a");
fwrite($Handle, $ID . "," . $DBSize . "," . $PictureSize . "," . time() . ",0 \r\n");
fclose($Handle);
/* Get the picture raw contents */
$Handle = fopen($TemporaryFile, "r");
$Raw = fread($Handle, $PictureSize);
fclose($Handle);
/* Save the picture in the solid database file */
$Handle = fopen($Database, "a");
fwrite($Handle, $Raw);
fclose($Handle);
/* Remove temporary file */
unlink($TemporaryFile);
}
示例14: createCode
function createCode($len = 4)
{
$width = 100;
$height = 50;
$size = 22;
//字体大小
$font = ROOT_PATH . '/static/font/arial.ttf';
//字体
$img = imagecreatetruecolor($width, $height);
//创建画布
$bgimg = imagecreatefromjpeg(ROOT_PATH . '/static/background/' . rand(1, 5) . '.jpg');
//生成背景图片
$bg_x = rand(0, 100);
//随机招贴画布起始X轴坐标
$bg_y = rand(0, 50);
//随机招贴画布起始Y轴坐标
imagecopy($img, $bgimg, 0, 0, $bg_x, $bg_y, $bg_x + $width, $bg_y + $height);
//把背景图片$bging粘贴的画布上
$str = $this->creaStr($len);
//字符串
for ($i = 0, $j = 5; $i < 4; $i++) {
$array = array(-1, 1);
$p = array_rand($array);
$an = $array[$p] * mt_rand(1, 10);
//扭曲角度
imagettftext($img, $size, $an, $j + 5, 34, imagecolorallocate($img, rand(0, 100), rand(0, 100), rand(0, 100)), $font, $str[$i]);
//生成验证字符窜
$j += 20;
}
cookie('captchacode', strtolower($str));
header('Content-type:image/png');
imagepng($img);
imagedestroy($img);
}
示例15: get
/**
* 生成验证码
* @param string $file 图片保存文件名,不指定则图片会被直接输出
* @return null
*/
public function get($file = "")
{
$support = $this->support();
list($code, $answer) = $this->generateCode();
$image = null;
@session_start();
$_SESSION['vitex.captcha.answer'] = strtolower($answer);
if ($support == 'imagick') {
$image = new \Imagick();
$image->newImage($this->width, $this->height, "none");
$image->setImageFormat('png');
$image = $this->imagickLine($image, $this->linenum);
$image = $this->imagickDrawText($image, $code);
$image->swirlImage(30);
$image->oilPaintImage(1);
if ($file) {
$image->writeImage($file);
} else {
header("Content-type:image/png");
echo $image->getImageBlob();
}
} else {
$image = imagecreate($this->width, $this->height);
$color = imagecolorallocate($image, 255, 255, 255);
imagecolortransparent($image, $color);
$this->gdLine($image, $this->linenum);
$this->gdDrawText($image, $code);
if ($file) {
imagepng($image, $file);
} else {
header("Content-type: image/jpeg; Cache-Control: no-store, no-cache, must-revalidate");
imagepng($image);
}
}
}