本文整理汇总了PHP中ImagePNG函数的典型用法代码示例。如果您正苦于以下问题:PHP ImagePNG函数的具体用法?PHP ImagePNG怎么用?PHP ImagePNG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImagePNG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extractAppInfo
function extractAppInfo($img)
{
//アイコン切り出し
$homeLeftPadding = 34;
$homeTopPadding = 67;
$appSideMargin = 38;
//1列目と2列め、3列めと4列目の間のマージン
$appCenterMargin = 40;
//2列めと3列めの間のマージン
$appBottomMargin = 62;
$featurePadding = 6;
//角丸分を削る
for ($y = 0; $y < 4; $y++) {
for ($x = 0; $x < 4; $x++) {
//アイコン切り出し
$appXAlpha = $x < 2 ? 0 : $appCenterMargin - $appSideMargin;
$appX = $homeLeftPadding + ($x * (self::appWidth + $appSideMargin) + $appXAlpha);
$appY = $homeTopPadding + $y * (self::appHeight + $appBottomMargin);
$appImg = ImageCreateTrueColor(self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2);
ImageCopyResampled($appImg, $img, 0, 0, $appX + $featurePadding, $appY + $featurePadding, self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2, self::appWidth - $featurePadding * 2, self::appHeight - $featurePadding * 2);
$appIdx = $y * 4 + $x;
$filename = "app_icon.{$appIdx}.png";
ImagePNG($appImg, $filename);
echo "{$filename} \n";
//アイコンを3x3に分割して平均色を抽出、特徴量とする
//$features = $this->calcIconImgFeature($appImg);
ImageDestroy($appImg);
}
}
}
示例2: create_captcha
function create_captcha($width = 60, $height = 32)
{
session_start();
//生成验证码图片
Header("Content-type: image/PNG");
$im = imagecreate($width, $height);
// width and height of image
$back = ImageColorAllocate($im, 245, 245, 245);
// specify background color
imagefill($im, 0, 0, $back);
// fill the background color into image
$vcodes = "";
srand((double) microtime() * 1000000);
//生成4位数字
for ($i = 0; $i < 4; $i++) {
$font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
// 生成随机颜色
$authnum = rand(1, 9);
$vcodes .= $authnum;
imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
}
for ($i = 0; $i < 100; $i++) {
// interuppting
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
// 画像素点函数
}
ImagePNG($im);
ImageDestroy($im);
$_SESSION['captcha'] = $vcodes;
}
示例3: create_error
function create_error($text)
{
$text = $text;
$size = "8";
$font = "classes/fonts/trebuchet.ttf";
$TextBoxSize = imagettfbbox($size, 0, $font, preg_replace("/\\[br\\]/is", "\r\n", $text));
$TxtBx_Lwr_L_x = $TextBoxSize[0];
$TxtBx_Lwr_L_y = $TextBoxSize[1];
$TxtBx_Lwr_R_x = $TextBoxSize[2];
$TxtBx_Lwr_R_y = $TextBoxSize[3];
$TxtBx_Upr_R_x = $TextBoxSize[4];
$TxtBx_Upr_R_y = $TextBoxSize[5];
$TxtBx_Upr_L_x = $TextBoxSize[6];
$TxtBx_Upr_L_y = $TextBoxSize[7];
$width = max($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x) - min($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x);
$height = max($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y) - min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
$x = -min($TxtBx_Upr_L_x, $TxtBx_Lwr_L_x);
$y = -min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
$img = imagecreate($width + 2, $height + 1);
// Only PHP-Version 4.3.2 or higher
if (function_exists('imageantialias')) {
imageantialias($img, FALSE);
}
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $white);
ImageTTFText($img, $size, 0, $x, $y, $black, $font, preg_replace("/<br>/is", "\r\n", $text));
header("Content-Type: image/png");
ImagePNG($img);
ImageDestroy($img);
exit;
}
示例4: show
public function show()
{
$size = min($this->im_y, $this->im_x / $this->text_num);
$size = ceil($size * 0.8);
$im = imagecreatetruecolor($this->im_x, $this->im_y);
$text_c = imagecolorallocate($im, 255, 0, 0);
$bg_c = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_c);
for ($i = 0; $i < $this->text_num; $i++) {
$ypos = $size * 1.2;
if (preg_match('/[ygJup]/', $this->text[$i])) {
$ypos = ceil($ypos * 0.8);
}
//反色
$rnd = rand(1, $this->text_num - 1);
if ($i % $this->text_num == $rnd) {
imagefilledellipse($im, $this->im_x * 0.05 + $i * $size * 1.3 + $size / 2, $ypos / 2, $size * 1.2, $this->im_y * 1.1, $text_c);
imagettftext($im, $size, 0, $this->im_x * 0.05 + $i * $size * 1.3, $ypos, $bg_c, $this->ttf_file, $this->text[$i]);
} else {
imagettftext($im, $size, rand(-20, 20), $this->im_x * 0.05 + $i * $size * 1.3, $ypos, $text_c, $this->ttf_file, $this->text[$i]);
}
}
ob_clean();
header("Content-type: image/png");
ImagePNG($im);
ImageDestroy($im);
echo '= ' . base64_encode('@author:miaokuan<eyou80@gmail.com>');
}
示例5: ConvertToImage
function ConvertToImage($content)
{
$imageFile = ".counter.png";
$relativePath = ".counter.png";
$noOfChars = strlen($content);
$charHeight = ImageFontHeight(5);
$charWidth = ImageFontWidth(5);
$strWidth = $charWidth * $noOfChars;
$strHeight = $charHeight;
//15 padding
$imgWidth = $strWidth + 15;
$imgHeight = $strHeight + 15;
$imgCenterX = $imgWidth / 2;
$imgCenterY = $imgHeight / 2;
$im = ImageCreate($imgWidth, $imgHeight);
$script = ImageColorAllocate($im, 0, 255, 0);
$outercolor = ImageColorAllocate($im, 99, 140, 214);
$innercolor = ImageColorAllocate($im, 0, 0, 0);
ImageFilledRectangle($im, 0, 0, $imgWidth, $imgHeight, $outercolor);
ImageFilledRectangle($im, 3, 3, $imgWidth - 4, $imgHeight - 4, $innercolor);
//draw string
$drawPosX = $imgCenterX - $strWidth / 2 + 1;
$drawPosY = $imgCenterY - $strHeight / 2;
ImageString($im, 5, $drawPosX, $drawPosY, $content, $script);
//save image and return
ImagePNG($im, $imageFile);
return $relativePath;
}
示例6: SaveImage
function SaveImage($im, $filename)
{
$res = null;
// ImageGIF is not included into some GD2 releases, so it might not work
// output png if gifs are not supported
if ($this->image_type == 1 && !function_exists('imagegif')) {
$this->image_type = 3;
}
switch ($this->image_type) {
case 1:
if ($this->save_to_file) {
header("Content-type: image/gif");
$res = ImageGIF($im, $filename);
$res = ImageGIF($im, NULL);
} else {
header("Content-type: image/gif");
$res = ImageGIF($im, $filename);
$res = ImageGIF($im, NULL);
}
break;
case 2:
if ($this->save_to_file) {
header("Content-type: image/jpeg");
$res = ImageJPEG($im, $filename, $this->quality);
$res = ImageJPEG($im, NULL, $this->quality);
} else {
header("Content-type: image/jpeg");
$res = ImageJPEG($im, $filename, $this->quality);
$res = ImageJPEG($im, NULL, $this->quality);
}
break;
case 3:
if (PHP_VERSION >= '5.1.2') {
// Convert to PNG quality.
// PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
$quality = 9 - min(round($this->quality / 10), 9);
if ($this->save_to_file) {
header("Content-type: image/png");
$res = ImagePNG($im, $filename, $quality);
$res = ImagePNG($im, NULL, $quality);
} else {
header("Content-type: image/png");
$res = ImagePNG($im, $filename, $quality);
$res = ImagePNG($im, NULL, $quality);
}
} else {
if ($this->save_to_file) {
header("Content-type: image/png");
$res = ImagePNG($im, $filename);
$res = ImagePNG($im);
} else {
header("Content-type: image/png");
$res = ImagePNG($im, $filename);
$res = ImagePNG($im);
}
}
break;
}
return $res;
}
示例7: TransformPicture
function TransformPicture($inputfname, $outputfname, $transform)
{
$img = ImageCreateFromPNG($inputfname);
Imagesavealpha($img, true);
$sizex = imagesx($img);
$sizey = imagesy($img);
for ($x = 0; $x < $sizex; $x++) {
for ($y = 0; $y < $sizey; $y++) {
$color = imagecolorat($img, $x, $y);
$allcolors[dechex($color)]++;
$blue = 0xff & $color;
$green = (0xff00 & $color) >> 8;
$red = (0xff0000 & $color) >> 16;
foreach ($transform as $line) {
list($from, $to) = split("\t", $line);
list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
if ($blue == $fb and $red == $fr and $green == $fg) {
imagesetpixel($img, $x, $y, hexdec($to));
}
}
}
}
ImagePNG($img, "{$outputfname}");
imagedestroy($img);
print_r($allcolors);
}
示例8: TransFormPicture
function TransFormPicture($inputfname, $outputfname, $transform, $backgroundcolor)
{
$img_in = ImageCreateFromPNG($inputfname);
$sizex = imagesx($img_in);
$sizey = imagesy($img_in);
$img_out = @ImageCreateTrueColor($sizex, $sizey) or die("Cannot create image handle.");
imagefill($img_out, 0, 0, hexdec($backgroundcolor));
ImageCopy($img_out, $img_in, 0, 0, 0, 0, $sizex, $sizey);
for ($x = 0; $x < $sizex; $x++) {
for ($y = 0; $y < $sizey; $y++) {
$color = imagecolorat($img_in, $x, $y);
$allcolors[dechex($color)]++;
$blue = 0xff & $color;
$green = (0xff00 & $color) >> 8;
$red = (0xff0000 & $color) >> 16;
foreach ($transform as $line) {
list($from, $to) = split("\t", $line);
list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
if ($blue == $fb and $red == $fr and $green == $fg) {
imagesetpixel($img_out, $x, $y, hexdec($to));
}
}
}
}
ImagePNG($img_out, "out/{$outputfname}");
imagedestroy($img_in);
imagedestroy($img_out);
print_r($allcolors);
}
示例9: resize
public function resize($width, $height)
{
$type = exif_imagetype($this->image);
if ($type == 2) {
$images_orig = ImageCreateFromJPEG($this->image);
} elseif ($type == 3) {
$images_orig = ImageCreateFromPNG($this->image);
} elseif ($type == 1) {
$images_orig = ImageCreateFromGIF($this->image);
} else {
return false;
}
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
if ($type == 2) {
ImageJPEG($images_fin, $this->image);
} elseif ($type == 3) {
ImagePNG($images_fin, $this->image);
} elseif ($type == 1) {
ImageGIF($images_fin, $this->image);
}
ImageDestroy($images_orig);
ImageDestroy($images_fin);
return true;
}
示例10: rand_create
function rand_create()
{
//通知浏览器将要输出PNG图片
Header("Content-type: image/PNG");
//准备好随机数发生器种子
srand((double) microtime() * 1000000);
//准备图片的相关参数
$im = imagecreate(62, 20);
$black = ImageColorAllocate($im, 0, 0, 0);
//RGB黑色标识符
$white = ImageColorAllocate($im, 255, 255, 255);
//RGB白色标识符
$gray = ImageColorAllocate($im, 200, 200, 200);
//RGB灰色标识符
//开始作图
imagefill($im, 0, 0, $gray);
while (($randval = rand() % 100000) < 10000) {
}
$_SESSION["login_check_num"] = $randval;
//将四位整数验证码绘入图片
imagestring($im, 5, 10, 3, $randval, $black);
//加入干扰象素
for ($i = 0; $i < 200; $i++) {
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
}
//输出验证图片
ImagePNG($im);
//销毁图像标识符
ImageDestroy($im);
}
示例11: createAICode
function createAICode()
{
global $bBlog;
$code = $this->randomString();
$bBlog->db->query("\n\tDELETE FROM `" . T_CHECKCODE . "` WHERE `timestamp`+3000<NOW()");
$bBlog->db->query("\n\tINSERT INTO `" . T_CHECKCODE . "` ( `id` , `checksum` , `timestamp` )\n\tVALUES ('', '" . md5($code . $_SERVER["REMOTE_ADDR"]) . "', NOW( ))");
if (!isset($plugins_dir)) {
$plugins_dir = dirname(__FILE__) . '/';
}
$fontfile = "atomicclockradio.ttf";
$font = $plugins_dir . $fontfile;
$im = @imageCreate(110, 50) or die("Cannot Initialize new GD image stream");
$background_color = imageColorAllocate($im, 195, 217, 255);
$text_color = imageColorAllocate($im, 168, 18, 19);
ImageTTFText($im, 20, 5, 18, 38, $text_color, $font, $code);
// Date in the past
header("Expires: Thu, 28 Aug 1997 05:00:00 GMT");
// always modified
$timestamp = gmdate("D, d M Y H:i:s");
header("Last-Modified: " . $timestamp . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
// dump out the image
header("Content-type: image/png");
ImagePNG($im);
}
示例12: create
/** 创建验证码 */
public function create()
{
// 创建图象
$this->_img_res = imagecreate($this->width, $this->height);
// 填充背景
ImageColorAllocate($this->_img_res, $this->backgroundColor[0], $this->backgroundColor[1], $this->backgroundColor[2]);
// 分配颜色
$col_ellipse = imagecolorallocate($this->_img_res, $this->iconColor[0], $this->iconColor[1], $this->iconColor[2]);
$minArea = $this->iconSize / 2 + 3;
// 混淆用图象,不完整的圆
for ($i = 0; $i < $this->icon; $i++) {
$x = mt_rand($minArea, $this->width - $minArea);
$y = mt_rand($minArea, $this->height - $minArea);
$s = mt_rand(0, 360);
$e = $s + 330;
imagearc($this->_img_res, $x, $y, $this->iconSize, $this->iconSize, $s, $e, $col_ellipse);
}
// 验证用图象,完整的圆
$x = mt_rand($minArea, $this->width - $minArea);
$y = mt_rand($minArea, $this->height - $minArea);
$r = $this->iconSize / 2;
imagearc($this->_img_res, $x, $y, $this->iconSize, $this->iconSize, 0, 360, $col_ellipse);
// 记录圆心坐标及半径
$this->captcha_session($this->sess_name, array($x, $y, $r));
// 生成图象
Header("Content-type: image/PNG");
ImagePNG($this->_img_res);
ImageDestroy($this->_img_res);
exit;
}
示例13: createImage
function createImage($_text, $_fontsize = 11)
{
/* create filename */
$filename = 'button_' . md5($_text) . '.png';
$filename = strtolower($filename);
/* see if file exists already, we cache it */
if (file_exists(PHPGW_IMAGES_FILEDIR . '/' . $filename)) {
return $filename;
}
$size = imagettfbbox($_fontsize, 0, $this->font, $_text);
$dx = abs($size[2] - $size[0]);
$dy = abs($size[5] - $size[3]);
$xpad = 9;
$ypad = 9;
$im = imagecreate($dx + $xpad, $dy + $ypad);
$blue = ImageColorAllocate($im, 0x2c, 0x6d, 0xaf);
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
ImageRectangle($im, 0, 0, $dx + $xpad - 1, $dy + $ypad - 1, $black);
ImageRectangle($im, 0, 0, $dx + $xpad, $dy + $ypad, $white);
ImageTTFText($im, $_fontsize, 0, (int) ($xpad / 2) + 1, $dy + (int) ($ypad / 2), -$black, $this->font, $_text);
ImageTTFText($im, $_fontsize, 0, (int) ($xpad / 2), $dy + (int) ($ypad / 2) - 1, -$white, $this->font, $_text);
ImagePNG($im, PHPGW_IMAGES_FILEDIR . '/' . $filename);
ImageDestroy($im);
return $filename;
}
示例14: getAuthImage
function getAuthImage($text)
{
$this->setpin($text);
$im_x = 160;
$im_y = 40;
$im = imagecreatetruecolor($im_x, $im_y);
$text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
$tmpC0 = mt_rand(100, 255);
$tmpC1 = mt_rand(100, 255);
$tmpC2 = mt_rand(100, 255);
$buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
imagefill($im, 16, 13, $buttum_c);
$font = PATH_SYS_PUBLIC . 'font-awesome/fonts/verdana.ttf';
for ($i = 0; $i < strlen($text); $i++) {
$tmp = substr($text, $i, 1);
$array = array(-1, 1);
$p = array_rand($array);
$an = $array[$p] * mt_rand(1, 10);
//角度
$size = 28;
imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
}
$distortion_im = imagecreatetruecolor($im_x, $im_y);
imagefill($distortion_im, 16, 13, $buttum_c);
for ($i = 0; $i < $im_x; $i++) {
for ($j = 0; $j < $im_y; $j++) {
$rgb = imagecolorat($im, $i, $j);
if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
}
}
}
//加入干扰象素;
$count = 160;
//干扰像素的数量
for ($i = 0; $i < $count; $i++) {
$randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
}
$rand = mt_rand(5, 30);
$rand1 = mt_rand(15, 25);
$rand2 = mt_rand(5, 10);
for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
for ($px = -80; $px <= 80; $px = $px + 0.1) {
$x = $px / $rand1;
if ($x != 0) {
$y = sin($x);
}
$py = $y * $rand2;
imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
}
}
//设置文件头;
Header("Content-type: image/JPEG");
//以PNG格式将图像输出到浏览器或文件;
ImagePNG($distortion_im);
//销毁一图像,释放与image关联的内存;
ImageDestroy($distortion_im);
ImageDestroy($im);
}
示例15: create_captcha
function create_captcha()
{
session_start();
//生成验证码图片
Header("Content-type: image/PNG");
$im = imagecreate(44, 18);
// 画一张指定宽高的图片
$back = ImageColorAllocate($im, 245, 245, 245);
// 定义背景颜色
imagefill($im, 0, 0, $back);
//把背景颜色填充到刚刚画出来的图片中
$vcodes = "";
srand((double) microtime() * 1000000);
//生成4位数字
for ($i = 0; $i < 4; $i++) {
$font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
// 生成随机颜色
$authnum = rand(1, 9);
$vcodes .= $authnum;
imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
}
$_SESSION['VCODE'] = $vcodes;
for ($i = 0; $i < 100; $i++) {
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
// 画像素点函数
}
ImagePNG($im);
ImageDestroy($im);
}