//Your Image
$imgSrc = "image.jpg";
list($width, $height) = getimagesize($imgSrc);
$myImage = imagecreatefromjpeg($imgSrc);
if ($width > $height) {
$y = 0;
$x = ($width - $height)/2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width)/2;
$smallestSide = $width;
}
$thumbSize = 100;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
//Output
imagejpeg($thumb);
頁評論:PHP裁剪圖像,而不把它上傳
<?php
$sql1 = mysql_query("SELECT * FROM images");
while($row_img = mysql_fetch_array($sql1)){
$img_url=$row_img['3']; ?>
<img src="/<? echo $img_url; ?>" />
<?php } ?>
我想利用這個代碼,同時查看從數據庫中我的照片。
我的圖像名稱爲db $imgSrc=$img_url;
即行名。
謝謝
好像有很多的代碼從此卻下落不明。通過方法名稱判斷,它聽起來像是在創建圖像,而不是從數據庫中檢索它。你可能想澄清你正在嘗試做什麼。你的問題越好,答案越好:) – jmort253
現在看看代碼,我編輯它:) – rixlinux
所以你想:1從數據庫檢索圖像文件名? 2.裁剪? 3.顯示裁剪的圖像? –