我使用的URL鏈接到調整大小的圖像,如:調整圖像尺寸PHP
image.php?name=butterfly&size=1100x1100
例如:
<img src="image.php?name=butterfly&size=1100x1100">
我正在使用的代碼是:
<?php
if(isset($_GET['name'])){ //name
$image['name'] = $_GET['name'];
} else {
$image['name'] = null;
}
if(isset($_GET['size'])){ //dimensions
$image['size'] = $_GET['size'];
$size = explode('x', $image['size']);
$image['width'] = $size[0];
$image['height'] = $size[1];
} else {
$image['size'] = null;
}
if(isset($_GET['text'])){ //text
$image['text'] = $_GET['text'];
} else {
$image['text'] = null;
}
// File and new size
$filename = 'images/'.$image["name"].'.jpeg';
// Content type
header('Content-Type: image/jpeg');
// Output
imagecreatefromjpeg($filename);
// Set a maximum height and width
$width = $image['width'];
$height = $image['height'];
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
?>
我的代碼只適用於一部分,這是寬度,圖像被調整爲它的寬度但不是高度。當我調整窗口大小時,圖片每次都會變小。謝謝你的時間,並對任何不好的解釋感到抱歉。
如果圖像的大小與您的瀏覽器,然後這聽起來像一個CSS /造型問題 –
我沒有任何CSS,它是一個不同的PHP代碼,當我用image.php調整窗口它不' t worj –
第一個'imagecreatefromjpeg($ filename);'調用的結果不被使用。 –