本文目錄一覽:
- 1、PHP中獲取圖像尺寸大小的方法是什麼?
- 2、尋求php高手!!php中如何得到圖片的長和寬,並進行比較
- 3、關於php圖片縮放問題,比如一張400*300的圖片
- 4、php 中 圖片如何輸出多尺寸
- 5、請問有哪位朋友知道在PHP中如何獲取圖片大小
PHP中獲取圖像尺寸大小的方法是什麼?
getimagesize()獲取圖片尺寸
imagesx()獲取圖片的寬度
imagesy()獲取圖片的高度
/br
/br
尋求php高手!!php中如何得到圖片的長和寬,並進行比較
$arr=getimagesize(“bg.jpg”);
$arr[0] //寬度
$arr[1] //高度
寬高比自己計算吧。
關於php圖片縮放問題,比如一張400*300的圖片
1、html頁面不能對圖片有寬度和高度限制;
2、php進行縮放的話,你用的是GD?可以嘗試縮放的時候等比縮放:
前面getimagesize,imagesx,imagesy什麼的,我省略了,直接獲得當前的圖片的信息:
$size = array(
‘s’ = array(‘width’=$savewidth, ‘height’=$saveheight),
‘o’ = array(‘width’=$width, ‘height’=$height),
);
//s代表當前圖片的寬高,
//o代表規則圖片的寬高,(就是你的200*200,超出就縮放的規則標準)
function parseimageresizerule($size = array()){
$extract = extract($size);
if($s[‘width’] = $o[‘width’] || $s[‘height’] = $o[‘height’
if($s[‘width’] = $o[‘width’]){
$radio[‘w’] = $o[‘width’] / $s[‘width’];
$state[‘w’] = true;
}
if($s[‘height’] = $o[‘height’]){
$radio[‘h’] = $o[‘height’] / $s[‘height’];
$state[‘h’] = true;
}
if($state[‘w’] $state[‘h’]){
if($radio[‘w’] $radio[‘h’]){
$radio[‘s’] = $radio[‘w’];
$radio[‘h’] = false;
}else{
$radio[‘s’] = $radio[‘h’];
$radio[‘w’] = false;
}
}elseif($state[‘w’]){
$radio[‘s’] = $radio[‘w’];
}else{
$radio[‘s’] = $radio[‘h’];
}
$width = intval($s[‘width’] * $radio[‘s’]);
$height = intval($s[‘height’] * $radio[‘s’]);
$top = 0;
$left = 0;
}else{
$width = $s[‘width’];
$height = $s[‘height’];
$top = intval(($o[‘height’] – $height) / 2);
$left = intval(($o[‘width’] – $width) / 2);
}
return array(
‘width’ = $width,
‘height’ = $height,
‘top’ = $top,
‘left’ = $left,
);
}
最後返回的數組是實際圖片的長寬以及200,150這個圖片在200*200的圖片里的上左距離;
再用
imagefill($filesave, 0, 0, $white);
imagecopyresampled($filesave, $filecache, $left, $top, 0, 0, $width, $height, $savewidth, $saveheight);
就得到1個等比縮放完成的圖片!明白?
代碼我手敲的,原理肯定可以的~ !
By ahonronline
php 中 圖片如何輸出多尺寸
php的gd庫可以實現讀取寬和高
GetImageSize
作用:取得圖片的大小[即長與寬]
PHP GD庫函用法:array GetImageSize(string filename, array [imageinfo]);
這裡我很好奇的問一句為什麼要寬和高呢?
如果你是直接輸出原樣式大小,不用寫長或寬,在html頁面顯示的就是原圖大小
如果你是因為頁面的關係,直接width=「300」,高度會自動等比變化~
請問有哪位朋友知道在PHP中如何獲取圖片大小
用php或js獲取圖片大小,高寬尺寸
?
$arr=getimagesize(“images/album_01.gif”);
echo $arr[3];
$strarr=explode(“\””,$arr[3]);
echo $strarr[1];
?
HTML
HEAD
TITLE演示圖片等比例縮小/TITLE
script
function Wa_SetImgAutoSize(img)
{
//var img=document.all.img1;//獲取圖片
var MaxWidth=200;//設置圖片寬度界限
var MaxHeight=100;//設置圖片高度界限
var HeightWidth=img.offsetHeight/img.offsetWidth;//設置高寬比
var WidthHeight=img.offsetWidth/img.offsetHeight;//設置寬高比
alert(“test”+img.offsetHeight+img.fileSize);
if(img.offsetHeight1) alert(img.offsetHeight);
if(img.readyState!=”complete”){
return false;//確保圖片完全載入
}
if(img.offsetWidthMaxWidth){
img.width=MaxWidth;
img.height=MaxWidth*HeightWidth;
}
if(img.offsetHeightMaxHeight){
img.height=MaxHeight;
img.width=MaxHeight*WidthHeight;
}
}
function CheckImg(img)
{
var message=””;
var MaxWidth=1;//設置圖片寬度界限
var MaxHeight=1;//設置圖片高度界限
if(img.readyState!=”complete”){
return false;//確保圖片完全載入
}
if(img.offsetHeightMaxHeight) message+=”\r高度超額:”+img.offsetHeight;
if(img.offsetWidthMaxWidth) message+=”\r寬度超額:”+img.offsetWidth;
if(message!=””) alert(message);
}
/script
/HEAD
BODY
img src=”images/frequency.gif” border=0 id=”img1″ onload=”CheckImg(this);”
br
input id=inp type=”file” onpropertychange=”img1.src=this.value;”
/BODY
/HTML
原創文章,作者:SBBA,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/133181.html