[英]How can I cache the uploaded file of the user in my website, without any database
[英]How can I make a picture a user uploaded to automatically adjust to a specific width and height on my PHP website without spoiling the dimentions?
我創建了一個用戶可以上傳圖片的網站,但我沒有指定他們可以上傳的圖片尺寸。 那么,如何讓用戶上傳的圖片自動調整到數據庫中的特定寬度和高度,然后才能被提取顯示在我的網站上?
早上好。
我想你可以使用這樣的函數:
function resize_my_image_to_max_900($my_image){
$control_width = imagesx($my_image); // Store original width value
$control_height = imagesy($my_image); // Store original height value
$n_width = $control_width; // Default, case value <= 900
$n_height = $control_height; // Default, case value <= 900
if($n_width >= 900 || $n_height >= 900):
while(($n_width >= 900) || ($n_height >= 900)):
$n_width = $control_width - ($control_width * 0.25);
$n_height = $control_height - ($control_height * 0.25);
if($n_width < 900 || $n_height < 900): break; endif;
endwhile;
endif;
$new_image = imagecreatetruecolor($n_width, $n_height);
imagealphablending($new_image, false);
imagesavealpha($new_image, true);
imagecopyresampled($new_image, $my_image, 0, 0, 0, 0, $n_width, $n_height, $control_width, $control_height);
}
祝你有美好的一天和良好的工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.