Why does the thumbnail I create have a larger file size than the original image?

google-maps, image, php

Solution

The thumbnail you create has 4 times the bit depth of the original. Reducing the bit depth will reduce the file size.

Edit:

To reduce the bit-depth is quite simple, but I can't see any way to do this via CodeIgniter:

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

However, this file is still larger than the original (~17KiB vs. ~13KiB). Running it through TinyPNG gets it down to ~13KiB, close to the original.

Problem

I want to save Google Maps images to my server. Below is the code I am using to get and save these images, and the code for creating a thumbnail. I'm using CodeIgniter for this. ``` //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(); ``` My problem is that the generated thumbnail image is much bigger in size then the original. For comparison: - Original image - Thumbnail image Why is the thumbnail bigger than the original?

Original source