php gd库 字体大小生成文字图片,关于字体大小的数学题

使用GD库生成带阴影文字的图片
(window.slotbydup=window.slotbydup || []).push({
id: '2611110',
container: s,
size: '240,200',
display: 'inlay-fix'
您当前位置: &
[ 所属分类
作者 红领巾 ]
最近使用GD库来进行微信公共账号的图片生成,研究了一下GD库文字阴影效果的生成同时也发现了GD库的强大。GD库,处理图形的扩展库,GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片。 在网站上GD库通常用来生成缩略图,或者用来对图片加水印,或者用来生成汉字验证码,或者对网站数据生成报表等。GD库的安装什么的网上都有,现在很多虚拟空间也都支持,这里就不再赘述。下面通过我实际应用代码的实例和相关的注释为大家介绍一下GD库的使用方法。原图:生成效果图:代码如下:$str="北京";$str2= "空气质量:轻度污染";// 通过图片生成一个对象$im$im = imagecreatefromjpeg("images/3.jpg");//载入字体zt.ttf$fnt = "zt.ttf";//创建颜色,用于文字字体的白和阴影的黑$white=imagecolorallocate($im,222,229,207);$black=imagecolorallocate($im,50,50,50);//创建关于相对图片位置的函数,方便调用$top=100;$left=60;$top2=170;//在图片中添加文字,imagettftext (image,size,angle, x, y,color,fontfile,text)imagettftext($im,41, 0, $left+1, $top+1, $black, $fnt, $str);imagettftext($im,41, 0, $left, $top, $white, $fnt, $str);imagettftext($im,43, 0, $left+1,$top2+1 , $black, $fnt, $str2);imagettftext($im,43, 0, $left,$top2, $white, $fnt, $str2);//将$im输出ImageJpeg($im);//销毁$im对象ImageDestroy($im);接下来详细解释一下:imagettftext (image,size,angle, x, y,color,fontfile,text)imagettftext() 是将字符串 text画到 image所代表的图像上,从坐标 x,y(左上角为 0, 0)开始,角度为 angle,颜色为 color,使用 fontfile 所指定的 TrueType 字体文件。由 x,y 所表示的坐标定义了第一个字符的基本点大概在字符的左下角。angle 以角度表示,0 度为从左向右阅读文本,更高的值表示逆时针方向(即如果值为 90 则表示从下向上阅读文本)。fontfile 是想要使用的 TrueType 字体的文件名。text 是文本字符串,可以包含 UTF-8 字符序列。color 是颜色的索引值。以上所述就是本文的全部内容了,希望大家能够喜欢。请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!
本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师
转载请注明本文标题:本站链接:
分享请点击:
1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
CodeSecTeam微信公众号
决定你人生高度的不是你的才能,而是你的态度!
手机客户端
,专注代码审计及安全周边编程,转载请注明出处:http://www.codesec.net
转载文章如有侵权,请邮件 admin[at]codesec.netPHP中怎么设置生成图片中的文字大小-PHP/基础编程-php-电脑编程网PHP中怎么设置生成图片中的文字大小-PHP/基础编程作者:charlzon 和相关&&如上,我想做个验证码,但是发现上面的字好小,怎么弄大点,比如CSDN登录时的验证码上的文字都挺大的..------回答---------------其他回答(10分)---------
ImageTTFText的第二个参数,就是fontsize------其他回答(5分)---------贴你的代码啊,贴出来看------其他回答(5分)---------手册上有相关资料:|||||||PHP中怎么设置生成图片中的文字大小-PHP/基础编程来源网络,如有侵权请告知,即处理!编程Tags:                &                    文字水印基本思路:1。用getimagesize()获取图片的信息(as:大小,属性等);2。根据图片信息用imagecreatefromjpeg
()/imagecreatefromgif/imagecreatepng创建图片(即标识符);3。设置要用到的字体(as:"arial.ttf",一定要给出存放的正确路径,如在
windows系统中,可到windows/fonts中把文件拷贝到程序的目录,或者从网
上下载到本地);4。设置作为水印的文字;5。用imagecolorallocate()设置水印文字的颜色;6。用imagettftext()把文字写到创建的图片中;7。根据图片的属性设置头部属性(as:header("content-
type:image/jpeg")));8。用imagejpeg(),imagepng()等相应的函数输出图像;其中:如:
imagejpeg($im)是给出相应的效果,没有真正打上水印,要真正给图打水印
,则给出相应的参数;如:imagejpeg($im, $newimagename[,
$flag]);9。用imagedestroy()销毁生成的内容
文字水印 &?php$image = "1.jpg";$ims =
getimagesize($image);list($width, $height) =
$switch($ims[2]){&case 1:&&$im =
imagecreatefromjpeg($image);&&&case 2:&&$im =
imagecreatefromjpeg($image);&&&case 3:&&$im =
imagecreatefrompng($image);&&}$font = "arial.ttf";$text =
"hi,world!";$col = imagecolorallocate($im, 255, 0, 0);imagettftext($im,
12, 0, rand(0, $width), rand(0, $height), $col,
$font,$text);header("Content-type:image/jpeg");//imagejpeg($im,
'ok.jpg');imagejpeg($im);imagedestroy($im);?&
图片水印基本思路:1。给出两幅图片,一幅要打水印的,一幅是作为水印的;2。用getimagesize()获取图片的信息(如是jpeg,gif,png等属性);3。根据图片的信息选择函数imagecreatefromgif(),
imagecreatefrompng()
等分别创建两个图片(图片标识符);4。用imagecopy()函数把水印图片复制到要打水印的图片;5。根据图片的属性选择头部函数(as:header("content-
type:image/jpeg"),
header("content-type:image/gif"));6。根据图片的属性用imagejpeg() imagepng()
等函数输出图片。如果是一
个参数的话,相当于是预览,多个参数即给出新图名称,新图就是打上水印
的效果图。7。用imagedestroy()销毁生成的内容
示例代码:
图片水印&?php$image = "1.jpg";$ims =
getimagesize($image);$logo = "2.jpg";$ins = getimagesize($logo);
switch($ims[2]){&case 1:&&$im =
imagecreatefromgif($image);&&&case 2:&&$im =
imagecreatefromjpeg($image);&&&case 3:&&$im =
imagecreatefrompng($image);&&}
switch($ins[2]){&case 1:&&$in =
imagecreatefromgif($logo);&&&case 2:&&$in =
imagecreatefromjpeg($logo);&&&case 3:&&$in =
imagecreatefrompng($logo);&&&} imagecopy($im, $in,
rand(10,300), rand(10, 50), 20, 20, 100, 100);
header("Content-type:image/jpeg");//imagejpeg($im,
'final.jpg');imagejpeg($im);imagedestroy($in);imagedestroy($im);?&
裁切成小图:基本思路:1。分别创建两个图片区域,一个是要输出的图片(原来没有的),用
imagecreatetruecolor()创建,一个是原来存在的图片(即原图),用
imagecreatefromjpeg(),imagecreatefromgif等函数创建;2。用imagecopyresized()函数把原图填充新区域;3。用imagejpeg(),
imagegif();等函数输出小图,如给出多个参数,就可以生成小图存放了。4。用imagedestroy()销毁生成的内容
小图示例代码:&?php
$filename = '1.jpg';$percent = 0.5;
// Content typeheader('Content-Type: image/jpeg');
// Get new sizeslist($width, $height) =
getimagesize($filename);$newwidth = $width * $$newheight =
$height * $
// Load$thumb = imagecreatetruecolor($newwidth, $newheight);$source =
imagecreatefromjpeg($filename);
// Resizeimagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth,
$newheight, $width, $height);
// Outputimagejpeg($thumb,
'final.jpg');imagejpeg($thumb);imagedestroy($thumb);imagedestroy($source);?&
阅读(...) 评论()PHP用GD库生成高质量的缩略图片
字体:[ ] 类型:转载 时间:
PHP用GD库生成高质量的缩略图片,PHP一般情况下生成的缩略图都比较不理想。今天试用PHP,GD库来生成缩略图。虽然并不100%完美。可是也应该可以满足缩略图的要求了。
以下是PHP源代码(ResizeImage.php)。
代码如下: &?php $FILENAME="image.thumb"; // 生成图片的宽度 $RESIZEWIDTH=400; // 生成图片的高度 $RESIZEHEIGHT=400; function ResizeImage($im,$maxwidth,$maxheight,$name){ $width = imagesx($im); $height = imagesy($im); if(($maxwidth && $width & $maxwidth) || ($maxheight && $height & $maxheight)){ if($maxwidth && $width & $maxwidth){ $widthratio = $maxwidth/$ $RESIZEWIDTH= } if($maxheight && $height & $maxheight){ $heightratio = $maxheight/$ $RESIZEHEIGHT= } if($RESIZEWIDTH && $RESIZEHEIGHT){ if($widthratio & $heightratio){ $ratio = $ }else{ $ratio = $ } }elseif($RESIZEWIDTH){ $ratio = $ }elseif($RESIZEHEIGHT){ $ratio = $ } $newwidth = $width * $ $newheight = $height * $ if(function_exists("imagecopyresampled")){ $newim = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); }else{ $newim = imagecreate($newwidth, $newheight); imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } ImageJpeg ($newim,$name . ".jpg"); ImageDestroy ($newim); }else{ ImageJpeg ($im,$name . ".jpg"); } } if($_FILES['image']['size']){ if($_FILES['image']['type'] == "image/pjpeg"){ $im = imagecreatefromjpeg($_FILES['image']['tmp_name']); }elseif($_FILES['image']['type'] == "image/x-png"){ $im = imagecreatefrompng($_FILES['image']['tmp_name']); }elseif($_FILES['image']['type'] == "image/gif"){ $im = imagecreatefromgif($_FILES['image']['tmp_name']); } if($im){ if(file_exists("$FILENAME.jpg")){ unlink("$FILENAME.jpg"); } ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME); ImageDestroy ($im); } } ?&
以下是测试代码(demo.php)
代码如下: &?php include('ResizeImage.php'); if(!empty($_POST)){ echo($FILENAME.".jpg?cache=".rand(0,999999)); } ?& &form name="test" action="?submit=true" enctype="multipart/form-data" method="post" & &input type="file" name="image" size="50" value="浏览"&&p& &input type="submit" value="上传图片"& &/form&
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具php 使用GD库压缩图片,添加文字图片水印
php 使用GD库压缩图片,添加文字图片水印
先上一个工具类,提供了压缩,添加文字、图片水印等方法:
image.class.php
class Image {
public function __construct($src) {
$info = getimagesize($src);
$this -& info = array(
"width" =& $info[0],
"height" =& $info[1],
"type" =& image_type_to_extension($info[2], false),
"mime" =& $info['mime']
$fun = "imagecreatefrom{$this-&info['type']}";
$this -& image = $fun($src);
public function thumb($width, $height) {
$imageThumb = imagecreatetruecolor($width, $height);
imagecopyresampled(
$imageThumb,
$this -& image,
$this -& info["width"],
$this -& info["height"]);
imagedestroy($this -& image);
$this -& image = $imageT
public function waterMarkText($text, $fontPath, $fontSize, $color, $x, $y, $angle) {
$color = imagecolorallocatealpha(
$this -& image,
$color[0],
$color[1],
$color[2],
$color[3]);
imagettftext(
$this -& image,
$fontSize,
$fontPath,
public function waterMarkImage($source, $x, $y, $alpha) {
$markInfo = getimagesize($source);
//3、获取水印图片类型
$markType = image_type_to_extension($markInfo[2], false);
//4、在内存创建图像
$markCreateImageFunc = "imagecreatefrom{$markType}";
//5、把水印图片复制到内存中
$water = $markCreateImageFunc($source);
//特别处理,设置透明
$color=imagecolorallocate($water,255,255,255);
imagefill($water,0,0,$color);
imagecolortransparent($water,$color);
//6、合并图片
imagecopymerge($this -& image, $water, $x, $y, 0, 0, $markInfo[0], $markInfo[1], $alpha);
public function show() {
header("Content-type:" . $this -& info['mime']);
$outputfunc = "image{$this -& info['type']}";
$outputfunc($this -& image);
public function save($newname) {
$outputfunc = "image{$this -& info['type']}";
$outputfunc($this -& image, $newname . '.' . $this -& info['type']);
public function __destruct() {
imagedestroy($this -& image);
require "image.class.php";
$src = "aeroplane.jpg";
$image = new Image($src);
$source = "logo.png";
$image -& waterMarkImage($source, 0, 0, 30);
$image -& thumb(500, 500);
$fontPath = "STXINGKA.ttf";
$text = "文字图片水印";
$image -& waterMarkText(
$fontPath,
array(255, 255, 255, 20),
$image -& show();
$image -& save("image_mark");
上面用到的图片和字体都跟代码文件在同一个目录下。
相关标签:
分享即可 +1积分
请登录后,发表评论
评论(Enter+Ctrl)
评论加载中...
评论加载中...
全栈工程师
作者的热门手记
Copyright (C)
All Rights Reserved | 京ICP备 号-2

我要回帖

更多关于 数学题生成器 的文章

 

随机推荐