當前位置:首頁 » 編程語言 » php圖片寬高

php圖片寬高

發布時間: 2023-08-31 07:49:06

Ⅰ 關於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);
imageresampled($filesave, $filecache, $left, $top, 0, 0, $width, $height, $savewidth, $saveheight);
就得到1個等比縮放完成的圖片!明白?

代碼我手敲的,原理肯定可以的~ !

By ahonronline

Ⅱ php怎麼修改圖片的尺寸大小並且覆蓋原圖

<?php
$imgsrc = "http://www.nowamagic.net/images/3.jpg";
$width =
780;
$height = 420;
resizejpg($imgsrc,$imgdst,$width,$height);

function resizejpg($imgsrc,$imgdst,$imgwidth,$imgheight)
{
//$imgsrc
jpg格式圖像路徑 $imgdst jpg格式圖像保存文件名 $imgwidth要改變的寬度 $imgheight要改變的高度

//取得圖片的寬度,高度值
$arr = getimagesize($imgsrc);
header("Content-type:
image/jpg");
$imgWidth = $imgwidth;
$imgHeight = $imgheight;
//
Create image and define colors
$imgsrc = imagecreatefromjpeg($imgsrc);

$image = imagecreatetruecolor($imgWidth, $imgHeight); //創建一個彩色的底圖

imageresampled($image, $imgsrc, 0, 0, 0, 0,$imgWidth,$imgHeight,$arr[0],
$arr[1]);
imagepng($image);
imagedestroy($image);
}
?>

Ⅲ 請高手幫幫忙! 怎樣在php中調整圖片顯示的大小

你在顯示的時候,直接指定圖片顯示的大小是不會改變你的源文件大小的。
如:
<img src='/upload/1.jpg' width='100' /> 那麼顯示的時候,就是寬度100,高度會根據你的圖片的尺寸縮放。

Ⅳ php 在多個上傳圖片時 怎麼獲取 要上傳的圖片寬高

分兩個部分,一個是「多個圖片」,一個是獲取圖片的寬、高。
第一個用循環做到,也就是用for、foreach之類的東西遍歷你從頁面中得到的圖片數組
下一步用getimagesize()函數獲得圖片的信息。
此函數在php手冊里有解釋:圖像生成與處理→GD→GD and image函數里。
此函數返回的結果如下:
返回一個具有四個單元的數組。索引 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 標記。

Ⅳ PHP語言編寫的網頁,圖片代碼尺寸怎麼調整

樓上的哥們屬性寫錯了,標簽屬性width和height裡面是不能帶px的,css裡面才要帶px。
強制控制寬高:<img scr="" width="200" height="300"/>

固定寬度,高度自適應:<img scr="" width="200"/>

固定高度,寬度自適應:<img scr="" height="300"/>

熱點內容
linux嵌入式書籍 發布:2025-02-04 03:44:07 瀏覽:331
sql分組最後一條 發布:2025-02-04 03:38:24 瀏覽:270
單宮數字奇門演算法 發布:2025-02-04 03:33:57 瀏覽:862
文件夾盒子 發布:2025-02-04 03:33:05 瀏覽:110
python教案 發布:2025-02-04 03:10:38 瀏覽:798
怎麼編程套料 發布:2025-02-04 02:50:31 瀏覽:208
副編譯 發布:2025-02-04 02:05:25 瀏覽:613
解壓按摩師 發布:2025-02-04 01:21:31 瀏覽:424
linuxssh限制 發布:2025-02-04 01:20:40 瀏覽:697
腳本式是什麼 發布:2025-02-04 01:06:24 瀏覽:250