Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 图库图像图纳视图_Php_Image_Resize_Gallery - Fatal编程技术网

Php 图库图像图纳视图

Php 图库图像图纳视图,php,image,resize,gallery,Php,Image,Resize,Gallery,您好,我正在使用此代码从文件夹中提取图像,然后将其作为简单的网格库查看。如何从提取的图像中显示小缩略图(200px*140px)。您可以看到我使用css(320px*240px)尝试的内容,但它仍然将整个大图像加载到该大小。请帮助我。我希望减少加载时间 <?php $files = glob("images/gallery/photos/*.*"); for ($i=1; $i<count($files); $i++) { $image = $files[$i]; ech

您好,我正在使用此代码从文件夹中提取图像,然后将其作为简单的网格库查看。如何从提取的图像中显示小缩略图(200px*140px)。您可以看到我使用css(320px*240px)尝试的内容,但它仍然将整个大图像加载到该大小。请帮助我。我希望减少加载时间

<?php


$files = glob("images/gallery/photos/*.*");

for ($i=1; $i<count($files); $i++)

{

$image = $files[$i];

echo '<img  src="'.$image .'"  class="group2" style="border:2px solid #666; height: 240px; width:320; margin: 5px; float: left;" />';
}

?>

对于我来说,此代码有效:

<?php


$files = glob("images/gallery/photos/*.*");

for ($i=1; $i<count($files); $i++)

{

$image = $files[$i];

echo '<img  src="'.$image .'"  class="group2" style="border:2px solid #666; width:200px; margin: 5px; float: left;" />';
}

?>


我建议您删除img的高度,这样图像就不会变形。

CSS样式应用于客户端的图像。这意味着整个(大)映像仍然必须由服务器发送到客户端

您可以使用PHP中包含的GD库在服务器上调整图像大小

更具体地说,有一种称为“imagecopyresized”的方法。更多文档和示例可在此处找到:

您可以这样做(摘自我上面链接的页面,只添加了标题):



宽度:320此处缺少px抱歉,这是一个类型错误。这会减少加载时间吗?每个图像的大小为2MB。@maurelio79不,不会。而OP并不仅仅要求chrome@safarov我向您保证,在linux上的Chrome中,它也能正常工作。无论如何,你是对的,事实上,在我添加的代码中,pxI可以看到头实际上也是在示例中定义的,所以你可以忽略“我的”示例的第一行。
<?PHP
header("Content-type: image/png");
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-Type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>