欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php初學(xué)者教程之圖片縮放和裁剪

 更新時(shí)間:2022年02月08日 10:29:54   作者:quan9i  
這篇文章主要給大家介紹了關(guān)于php圖片縮放和裁剪的相關(guān)資料,主要利用的是imagecopyresampled(),文中通過實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

php程序中改變圖片大小的函數(shù)大多數(shù)人都想到用imagecopyresized(),不過經(jīng)過測(cè)試比較發(fā)現(xiàn),使用imagecopyresampled()改變的圖片質(zhì)量更高。

1、imagecopyresampled的使用

1、目標(biāo)函數(shù)資源

2、源圖像資源<要采樣的圖片資源>

3、x(0,0指圖左上角)

4、y(x,y確定一個(gè)坐標(biāo),坐標(biāo)確定了把采樣的部分放到目標(biāo)圖像資源的位置)

5、源x(0,0指圖右上角)

6、源y(源x與源y確定一個(gè)坐標(biāo),你要采用的原圖像資源的某個(gè)部分的起始位置)

7、w

8、h(weight與height確定了放到目標(biāo)圖像資源上面的尺寸)

9、源w

10、源h(源w與源h確定了采樣原圖像資源的某個(gè)部分)

2、$height=$width/($imgWidth/$imgHeight);使得圖片整體不會(huì)被裁剪,縮放代碼只需控制width即可

<?php
header('Content-type:image/jpeg');
$width=300;
$img=imagecreatefromjpeg('1/php1.jpg');
$imgWidth=imagesx($img);
$imgHeight=imagesy($img);
$height=$width/($imgWidth/$imgHeight);
$img1=imagecreatetruecolor(500,500);
imagecopyresampled($img1,$img,100,100,100,100,$width,$height,$imgWidth,$imgHeight);
imagejpeg($img1);
imagedestroy($img1);
imagedestroy($img);

<?php
header('Content-type:image/jpeg');
$width=200;
$img=imagecreatefromjpeg('1/php1.jpg');
$imgWidth=imagesx($img);
$imgHeight=imagesy($img);
$height=$width/($imgWidth/$imgHeight);
$img1=imagecreatetruecolor(500,500);
imagecopyresampled($img1,$img,100,100,100,100,$width,$height,$imgWidth,$imgHeight);
imagejpeg($img1);
imagedestroy($img1);
imagedestroy($img);

3、控制x、y與源x、源y可以進(jìn)行裁剪

<?php
header('Content-type:image/jpeg');
$width=500;
$img=imagecreatefromjpeg('1/php1.jpg');
$imgWidth=imagesx($img);
$imgHeight=imagesy($img);
$height=$width/($imgWidth/$imgHeight);
$img1=imagecreatetruecolor(500,500);
imagecopyresampled($img1,$img,0,0,300,300,$width,$height,$imgWidth,$imgHeight);
imagejpeg($img1);
imagedestroy($img1);
imagedestroy($img);

<?php
header('Content-type:image/jpeg');
$width=500;
$img=imagecreatefromjpeg('1/php1.jpg');
$imgWidth=imagesx($img);
$imgHeight=imagesy($img);
$height=$width/($imgWidth/$imgHeight);
$img1=imagecreatetruecolor(500,500);
imagecopyresampled($img1,$img,330,330,0,0,$width,$height,$imgWidth,$imgHeight);
imagejpeg($img1);
imagedestroy($img1);
imagedestroy($img);

總結(jié) 

到此這篇關(guān)于php圖片縮放和裁剪的文章就介紹到這了,更多相關(guān)php圖片縮放和裁剪內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論