2013-12-16 295 views
-2

我期待在页面加载时使用PHP缩小图像大小。 ?我真的不来知道如何做到这一点,我已经尽可能获得维度,但我会如何降低使用PHP只有这些尺寸得到这里是我当前的代码:缩小图像大小php

<?php 
$stmt = $db->query('SELECT * FROM img_gallery ORDER BY list'); 
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : 
$image = $row['url']; 
list($width, $height) = getimagesize($image); //grab the image dimensions here 
?> 

<img src="" width="<?=$width ?>px" height="<?=$height ?>px" /> //image here 

所以每个尺寸减少几百个像素?

+0

有什么问题?只需将值分为任何你想要的值 – Ohgodwhy

+0

phpThumb()是PHP缩略图生成器链接 - http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php –

+1

你的意思是像 mmmm

回答

0

地尝试一下PHP imagejpeg

imagejpeg (resource $image [,string $filename [,int $quality ] ]); 

欲了解更多信息请点击here

0

你需要创建一个新的画布所需尺寸和复印有重采样帆布:

$newcanvas = imagecreatetruecolor($width,$height); 
$oldcanvas = imagecreatefromjpeg($imagePath); 
imagecopyresampled($newcanvas,$oldcanvas,0,0,0,0,$width, $height,$originalwidth,$originalheight);