Showing posts with label c image resize. Show all posts
Showing posts with label c image resize. Show all posts

Monday, November 28, 2011

Batch resize for photos/images on Tablet or Phone

Recently I ended up in having high quality images for an event with the total size of 4.5 GB. Transferring that to Tablet was itself a pain and I was loosing precious space on my 64 GB Android Tablet.

Better way was to resize the image to the screen area, I needed a batch tool to do so. On Mac the best way was ImageMagick.

It comes with a batch tool, and using that was a piece of cake.  Install ImageMagick from binary distribution or through Darwin port.

$ sudo port install ImageMagick

And launch the batch resizing by:

$ mogrify -path ~/Desktop/Images/FinalFolder  1280x800 *.JPG

I had JPEG images and my tablet resolution was 1280x800. Mogrify maintains the aspect ratio and best fit image is generated. Ran quite good on my mac core i7.

The result, I cud trim the folder size of 4.5 GB to 438 MB, transferred all the files to my tablet in 15 minutes than 3 hrs! Quality remains the same unless one zooms in :)




Monday, September 26, 2011

PNG Image scaling with Lib Cairo

Just wrote now for a tool and I liked the small utility.


#include "stdio.h"
#include

//#define ENABLE_DEBUG_LOG

#ifdef ENABLE_DEBUG_LOG
void printtImageDetails( cairo_surface_t * image, const char * text)
{
        if(text != NULL)
                printf("%s:\n", text);

        printf("W=%d H=%d\n", cairo_image_surface_get_width (image), cairo_image_surface_get_height (image));
        printf("Format:%d Stride:%d\n", cairo_image_surface_get_format(image), cairo_image_surface_get_stride (image));
}
#else
#define printtImageDetails(__image, __text)
#endif /* ENABLE_DEBUG_LOG */

void imageResize ( const char * sourceName, const char * destName, double ratio)
{
cairo_surface_t *image;
cairo_surface_t *dest;

image = cairo_image_surface_create_from_png (sourceName);
printtImageDetails(image, sourceName); 

dest = cairo_surface_create_similar (image, CAIRO_CONTENT_COLOR_ALPHA,
cairo_image_surface_get_width (image) * ratio,
cairo_image_surface_get_height (image) * ratio);

cairo_t *cr = cairo_create (dest);

cairo_scale (cr, ratio, ratio);
cairo_set_source_rgba (cr, 0, 0, 0, 0);
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (image);

printtImageDetails(dest, destName);
cairo_surface_write_to_png (dest, destName); 

cairo_destroy (cr);
cairo_surface_destroy (dest);

}/* end method imageResize */