導航:首頁 > 編程語言 > 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