导航:首页 > 编程语言 > imagedestroyphp

imagedestroyphp

发布时间:2022-10-19 19:12:26

php图像处理函数有哪些

php图像处理函数大全

php图片处理代码分享,包括缩放、剪裁、缩放、翻转、旋转、透明、锐化等。需要的朋友可以参考下

一、创建图片资源
imagecreatetruecolor(width,height);
imagecreatefromgif(图片名称);
imagecreatefrompng(图片名称);
imagecreatefromjpeg(图片名称);画出各种图像
imagegif(图片资源,保存路径);
imagepng()
imagejpeg();

二、获取图片属性
imagesx(res//宽度
imagesy(res//高度
getimagesize(文件路径)
返回一个具有四个单元的数组。索引
0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标记:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 =
PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10
= JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。这些标记与 PHP 4.3.0 新加的
IMAGETYPE 常量对应。索引 3 是文本字符串,内容为“height="yyy" width="xxx"”,可直接用于 IMG
标记。
销毁图像资源
imagedestroy(图片资源);

三、透明处理
PNG、jpeg透明色都正常,只有gif不正常
imagecolortransparent(resource
image [,int
color])//将某个颜色设置成透明色
imagecolorstotal()
imagecolorforindex();

四、图片的裁剪
imageresized()
imageresampled();

五、加水印(文字、图片)
字符串编码转换string iconv ( string $in_charset ,
string $out_charset , string $str )

六、图片旋转
imagerotate();//制定角度的图片翻转

七、图片的翻转
沿X轴 沿Y轴翻转

八、锐化
imagecolorsforindex()
imagecolorat()

⑵ PHP代码一个数字问题

<?php
session_start();
function random($len)
{
if($i==0)
{
$str="";
$s="";
for($i=0;$i <$len;$i++){
$s.=$str[rand(0,35)];
}
}
return strtoupper($s);
}
$code=random(4); //随机生成的字符串
$width = 50; //验证码图片的宽度
$height = 20; //验证码图片的高度
@header("Content-Type:image/png");
$_SESSION["code"] = $code;
$im=imagecreate($width,$height);
//背景色
$back=imagecolorallocate($im,255, 255, 255);
//模糊点颜色
$pix=imagecolorallocate($im,187,230,247);
//字体色
$font=imagecolorallocate($im,41,163,238);
//绘模糊作用的点
for($i=0;$i <1000;$i++)
{
imagesetpixel($im,rand(0,$width),rand(0,$height),$pix);
}
imagestring($im, 5, 7, 2,$code, $font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
?>这样试试呢,如果你对php有兴趣的话,可以向我一样在后盾人平台多看看自己学习学习,时间长了自己就慢慢明白了,希望能帮到你,给个采纳吧谢谢(๑>ڡ<)☆

⑶ php 图片压缩显示

(1)网页结构里用:<img src="image.php?name=p01.png">,来调用处理后的图片信息。
(2)在后台脚本 image.php 里对传过来的图片名进行处理返回:
<?php
$pic = $_REQUEST['name'];
// 1.打开图片源文件资源
$im = @imagecreatefrompng($pic);
if ($im) {
// 2.源文件的宽高,也可写为定值
$fx = imagesx($im); // 取宽
$fy = imagesy($im); // 取高
// 3.使用新的宽高
$sx = 150;
$sy = 100;
// 4.生成小图资源
$sm = imagecreatetruecolor($sx,$sy);
// 5.进行缩放
imageresampled($sm,$im,0,0,0,0,$sx,$sy,$fx,$fy);
// 6.输出图像
header('Content-Type: image/png');
imagepng($sm);
// 7.释放资源
imagedestroy($sm);
imagedestroy($im);
}

(3)代码里假设是对 png 图片处理,相关字都是 png,如果想对 jpg 类型处理的可都换成 jpeg

⑷ php imagedestroy有什么用,为什么最后销毁了还能显示出来

它的功能是释放与
image 关联的内存。image
是由图像创建函数返回的图像标识符,而不是图像的本身

⑸ PHP:ImageDestroy 求解这是什么

GD的图像操作函数。
用来销毁图像
下面是一个例子,
是一个生成验证码的
其中就用到了ImageDestroy

<?PHP
session_start();
session_register('SafeCode');
$type = 'gif';
$width= 40;
$height= 16;
header("Content-type: image/".$type);
srand((double)microtime()*1000000);
$randval = randStr(4,"");
if($type!='gif' && function_exists('imagecreatetruecolor')){
$im = @imagecreatetruecolor($width,$height);
}else{
$im = @imagecreate($width,$height);
}
$r = Array(225,211,255,223);
$g = Array(225,236,237,215);
$b = Array(225,236,166,125);

$key = rand(0,3);

$backColor = ImageColorAllocate($im,$r[$key],$g[$key],$b[$key]);//背景色(随机)
$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色
$pointColor = ImageColorAllocate($im, 255, 170, 255);//点颜色

@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//背景位置
@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor); //边框位置
$stringColor = ImageColorAllocate($im, 255,51,153);

for($i=0;$i<=100;$i++){
$pointX = rand(2,$width-2);
$pointY = rand(2,$height-2);
@imagesetpixel($im, $pointX, $pointY, $pointColor);
}

@imagestring($im, 3, 5, 1, $randval, $stringColor);
$ImageFun='Image'.$type;
$ImageFun($im);
@ImageDestroy($im);
$_SESSION['SafeCode'] = $randval;
//产生随机字符串
function randStr($len=6,$format='chinese') {
switch($format) {
case 'ALL':
$chars=''; break;
case 'CHAR':
$chars=''; break;
case 'NUMBER':
$chars='0123456789'; break;
default :
$chars='';
break;
}
$string="";
while(strlen($string)<$len)
$string.=substr($chars,(mt_rand()%strlen($chars)),1);
return $string;
}

⑹ 如何用PHP生成验证码

PHP生成验证码的原理:使用PHP的GD库,生成一张带验证码的图片,并将验证码保存在Session中。PHP生成验证码的大致流程有:

1、产生一张png的图片;

2、为图片设置背景色;

3、设置字体颜色和样式;

4、产生4位数的随机的验证码;

5、把产生的每个字符调整旋转角度和位置画到png图片上;

6、加入噪点和干扰线防止注册机器分析原图片来恶意破解验证码;

7、输出图片;

8、释放图片所占内存。

session_start();
getCode(4,60,20);

functiongetCode($num,$w,$h){
$code="";
for($i=0;$i<$num;$i++){
$code.=rand(0,9);
}
//4位验证码也可以用rand(1000,9999)直接生成
//将生成的验证码写入session,备验证时用
$_SESSION["helloweba_num"]=$code;
//创建图片,定义颜色值
header("Content-type:image/PNG");
$im=imagecreate($w,$h);
$black=imagecolorallocate($im,0,0,0);
$gray=imagecolorallocate($im,200,200,200);
$bgcolor=imagecolorallocate($im,255,255,255);
//填充背景
imagefill($im,0,0,$gray);

//画边框
imagerectangle($im,0,0,$w-1,$h-1,$black);

//随机绘制两条虚线,起干扰作用
$style=array($black,$black,$black,$black,$black,
$gray,$gray,$gray,$gray,$gray
);
imagesetstyle($im,$style);
$y1=rand(0,$h);
$y2=rand(0,$h);
$y3=rand(0,$h);
$y4=rand(0,$h);
imageline($im,0,$y1,$w,$y3,IMG_COLOR_STYLED);
imageline($im,0,$y2,$w,$y4,IMG_COLOR_STYLED);

//在画布上随机生成大量黑点,起干扰作用;
for($i=0;$i<80;$i++){
imagesetpixel($im,rand(0,$w),rand(0,$h),$black);
}
//将数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx=rand(3,8);
for($i=0;$i<$num;$i++){
$strpos=rand(1,6);
imagestring($im,5,$strx,$strpos,substr($code,$i,1),$black);
$strx+=rand(8,12);
}
imagepng($im);//输出图片
imagedestroy($im);//释放图片所占内存
}

⑺ PHP等比例压缩图片的实例代码

具体代码如下所示:
/**
*
desription
压缩图片
*
@param
sting
$imgsrc
图片路径
*
@param
string
$imgdst
压缩后保存路径
*/
public
function
compressedImage($imgsrc,
$imgdst)
{
list($width,
$height,
$type)
=
getimagesize($imgsrc);
$new_width
=
$width;//压缩后的图片宽
$new_height
=
$height;//压缩后的图片高
if($width
>=
600){
$per
=
600
/
$width;//计算比例
$new_width
=
$width
*
$per;
$new_height
=
$height
*
$per;
}
switch
($type)
{
case
1:
$giftype
=
check_gifcartoon($imgsrc);
if
($giftype)
{
header('Content-Type:image/gif');
$image_wp
=
imagecreatetruecolor($new_width,
$new_height);
$image
=
imagecreatefromgif($imgsrc);
imageresampled($image_wp,
$image,
0,
0,
0,
0,
$new_width,
$new_height,
$width,
$height);
//90代表的是质量、压缩图片容量大小
imagejpeg($image_wp,
$imgdst,
90);
imagedestroy($image_wp);
imagedestroy($image);
}
break;
case
2:
header('Content-Type:image/jpeg');
$image_wp
=
imagecreatetruecolor($new_width,
$new_height);
$image
=
imagecreatefromjpeg($imgsrc);
imageresampled($image_wp,
$image,
0,
0,
0,
0,
$new_width,
$new_height,
$width,
$height);
//90代表的是质量、压缩图片容量大小
imagejpeg($image_wp,
$imgdst,
90);
imagedestroy($image_wp);
imagedestroy($image);
break;
case
3:
header('Content-Type:image/png');
$image_wp
=
imagecreatetruecolor($new_width,
$new_height);
$image
=
imagecreatefrompng($imgsrc);
imageresampled($image_wp,
$image,
0,
0,
0,
0,
$new_width,
$new_height,
$width,
$height);
//90代表的是质量、压缩图片容量大小
imagejpeg($image_wp,
$imgdst,
90);
imagedestroy($image_wp);
imagedestroy($image);
break;
}
}
总结
以上所述是小编给大家介绍的PHP等比例压缩图片的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:php中10个不同等级压缩优化图片操作示例PHP
实现等比压缩图片尺寸和大小实例代码php
gd等比例缩放压缩图片函数基于PHP实现等比压缩图片大小php上传图片并压缩的实现方法PHP实现图片上传并压缩PHP实现图片压缩的两则实例php使用imagick模块实现图片缩放、裁剪、压缩示例

⑻ php imagedestroy函数可以销毁内存中的图片到底是什么意思

这个销毁是指你之前用过imagecreate()这样的函数,是销毁这里的图片的。

⑼ php 处理图片问题

把你的邮箱留下来,我把代码发给你
php生成图片的思路如下:
1 创建一个大小和宽度自定义的png图片 ,png的图片背景黑色填充,透明度自己设计
$dirname=dirname(__FILE__)."/";
$picname="pic_1.jpg";
$pngpicname="pic_2.png";
$name="222.jpg";
$str="我要加的文字";
list($w,$h) = getimagesize($name);//获得上传图片的长宽
$h=100;
$im = imagecreate($w,$h);
$backgroundColor = imagecolorallocatealpha($im,0,0,0,80);//背景通明图片颜色及通明度
imagepng($im,$pngpicname,9);
imagedestroy($im);
2 对创建的png图片加文字水印
将字符串分割成数组
$yy=50;//初始坐标
$xx=110;//初始坐标
$len=strlen($str);
$aa=msubstr($str,0,$len);//分割字符串
foreach($aa as $valuess){
$img = imagecreatefrompng($pngpicname);
$fontcolor = imagecolorallocate($img, 255, 255, 255);
$no =iconv('GB2312', 'UTF-8', $valuess);
imagettftext($img,$fontsize,0,$xx,$yy,$fontcolor,$dirname."simhei.ttf",$no);
imagepng($img,$pngpicname,9);
imagedestroy($img);
$xx=$xx+60;
}
3 把加水印的png图片覆盖到原图上去
$image1 = imagecreatefrompng($pngpicname);
$image2 = imagecreatefromjpeg($name);
imageresized($image2,$image1,0,450,0,0,$w,$h,$w,$h); //拷贝
imagejpeg($image2 ,$picname,100);
imagedestroy($image1);
imagedestroy($image2 );
4输出结果
<img src="<?=$picname;?>?t=<?=rand(1000,2000000);?>" />

⑽ php如何往带颜色的背景图片上写入白色文字

<?php
//定义输出为图像类型
header("content-type:image/png");
//新建图象
$pic=imagecreate(400,40);
//定义黑白颜色
//imagecolorallocate第一次调用就是背景色,这里为了演示就是黑色
$black=imagecolorallocate($pic,0,0,0);
//白色字体颜色
$white=imagecolorallocate($pic,255,255,255);
//定义字体
$font="c://WINDOWS//fonts//simhei.ttf";
//定义输出字体串
$str="WRITESOMETHING-qingwei.tech";
//打印TTF文字到图中
imagettftext($pic,20,0,10,30,$white,$font,$str);
//建立GIF图型
imagepng($pic);
//结束图形,释放内存空间
imagedestroy($pic);

如上述代码,用到了php的GD库,请在phpinfo中确认你是否开启了GD库。这里是在黑底图片上添加白字 ,你也可以用图片做背景改动一下就可以了

阅读全文

与imagedestroyphp相关的资料

热点内容
rf3148编程器 浏览:505
浙江标准网络服务器机柜云主机 浏览:587
设置网络的服务器地址 浏览:600
java图形界面设计 浏览:751
纯前端项目怎么部署到服务器 浏览:538
瓜子脸程序员 浏览:505
如何保证服务器优质 浏览:94
小微信aPP怎么一下找不到了 浏览:299
算法纂要学术价值 浏览:975
程序员你好是什么意思 浏览:801
倩女幽魂老服务器如何玩 浏览:561
电子钟单片机课程设计实验报告 浏览:999
看加密频道 浏览:381
程序员算不算流水线工人 浏览:632
三星电视我的app怎么卸载 浏览:44
简述vi编译器的基本操作 浏览:507
让程序员选小号 浏览:91
加强数字货币国际信息编译能力 浏览:584
购买的app会员怎么退安卓手机 浏览:891
程序员的种类及名称 浏览:295