[英]BLOB - PHP re-size Image
我有一個小問題重新調整blob圖像的大小。 我發現我必須做BLOB的高度和寬度,但由於人們上傳的圖像不是正方形,我該如何正確地重新調整它們?
基本上我想要最大寬度為300px;
我目前的代碼是
$desired_width = 300;
$desired_height = 300;
$sth = mysql_query("SELECT photobase FROM userpictures WHERE id = '".$array[0]."'");
while($r = mysql_fetch_assoc($sth)) {
$blobcontents = $r["photobase"];
$im = imagecreatefromstring($blobcontents);
$new = imagecreatetruecolor($desired_width, $desired_height);
$x = imagesx($im);
$y = imagesy($im);
imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y);
imagedestroy($im);
header('Content-type: <span class="posthilit">image</span>/jpeg');
imagejpeg($new, null, 85);
一種調整圖像大小的簡單方法,保持約束比例:
<?php
// Constraints
$max_width = 100;
$max_height = 100;
list($width, $height) = getimagesize($img_path);
$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
// New dimensions
$width = intval($ratio*$width);
$height = intval($ratio*$height);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.