gpt4 book ai didi

php - 为什么我创建的缩略图的文件大小比原始图像大?

转载 作者:行者123 更新时间:2023-12-02 06:58:03 26 4
gpt4 key购买 nike

我想将 Google map 图像保存到我的服务器。下面是我用来获取和保存这些图像的代码,以及创建缩略图的代码。为此,我正在使用 CodeIgniter。

//saving original image on server
$post = $_POST;
$file = file_get_contents("http://maps.google.com/maps/api/staticmap?size=".$post['w']."x".$post['h']."&sensor=false&markers=color:red|size:mid|".$post['lt'].",".$post['lg']."&&zoom=".$post['z']);

$filename = 'map_'.uniqid().'.png';
$name = './assets/images/upload/'.$filename;
file_put_contents($name, $file);

// creating thumbnail
$config_manip = array(
'image_library' => 'gd2',
'source_image' => './assets/images/upload/'.$filename,
'new_image' => './assets/images/upload/thumb_'.$filename,
'maintain_ratio' => false,
'quality' => "10%",
'width' => 480,
'height' => 480
);

$this->load->library('image_lib', $config_manip);
$this->image_lib->resize();

我的问题是生成的缩略图比原始图像大得多。为了比较:

为什么缩略图比原来的大?

最佳答案

您创建的缩略图的位深度是原始缩略图的 4 倍。降低位深度将减小文件大小。

Properties of original file Properties of thumbnail file


编辑:

减少位深度非常简单,但我看不出有什么方法可以通过 CodeIgniter 做到这一点:

$im = imagecreatefrompng('./original.png');
imagetruecolortopalette($im, false, 256);
imagepng($im, './output.png');

但是,此文件仍然比原始文件大(~17KiB 与~13KiB)。通过 TinyPNG 运行它将它降低到 ~13KiB,接近原来的水平。

关于php - 为什么我创建的缩略图的文件大小比原始图像大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27065594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com