Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Image Compression

Hi. I've got an application (runs on iPhone simulator) and runs OK on my iPhone 3GS (4.0.2 ios).

It captures an image from the camera/phone, some meta data and posts this to a webservice. No error, just times out. I'm guessing it's an issue with the image size.

Any suggestions on how to compress the image before sending?

Thanks.

Jennifer

— asked August 27th 2010 by Jennifer Bonnett
  • compression
  • image
  • iphone
  • json
0 Comments

6 Answers

  • Accepted Answer

    I've spent several hours looking into this. Since I don't know objective C (thus why I'm using Titanium in the first place), I found a way to hack the class to statically change the compression level. Here's what I did to get this to work (for iPhone):

    Navigate to /Library/Application Support/Titanium/mobilesdk/osx/1.4.x/iphone/Classes

    Open the files TiBlob.m and PLSqlitePreparedStatement.m files and change the code "UIImageJPEGRepresentation(value, 1.0)" to "UIImageJPEGRepresentation(value, x.x)" where x.x = your compression level between 0 and 1.

    Rebuild your iphone build and myImage.toImage() should now output to that compression level.

    If anyone has a better solution, I'm all ears.

    — answered September 28th 2010 by Dan Satterfield
    permalink
    0 Comments
  • jennifer,
    post your code ( using correct formatting syntax ) or a link to the code on pastie.org and i'll check it out to give you some advise.

    rocksteady,
    danno~

    — answered August 28th 2010 by danno watts
    permalink
    0 Comments
  • Do you have any good suggestion on image compression? I want to kind a fine toolkit whose way of processing is simple and fast to help me with that. Thanks in advance.

    Best regards,
    Arron

    — answered October 25th 2013 by arron lee
    permalink
    0 Comments
  • It must be very convenient to use iphone devices to compress image without any external procedures to install image compressing software on PC.

    — answered December 9th 2013 by HILLARY HALL
    permalink
    0 Comments
  • It must be very convenient to use iphone devices to compress image without any external procedures to install image compressing software on PC.

    — answered December 9th 2013 by HILLARY HALL
    permalink
    0 Comments
  • Much easier to do this

    Titanium.Media.showCamera({
    success:function(event)
    {
    var image = event.media;

    //CREATE IMAGEVIEW WITH event.media - USE HEIGHT & WIDTH AS AUTO TO GET IMAGE DIMENSIONS
    var image1 = Ti.UI.createImageView({
    image: image,
    height: 'auto',
    width: 'auto'
    });

    //RESIZE IMAGE - HERE IS DIVIDING THE IMAGE DIMENSIONS BY 4
    var image = image.imageAsResized((image1.width/4), (image1.height/4));
    //…………
    xhr.send({media:image});

    },
    
    — answered January 25th 2012 by Alex McDaid
    permalink
    1 Comment
    • Size will, of course, take down the file size with it BUT jpeg compression has nothing to do with file dimensions. With compression ratio you can save a 1000x750px image under 100Kb with reasonable good quality.

      Image compression means compression ratio, more info wikipedia JPG (see Effects of JPEG compression)

      — commented June 17th 2012 by Lluis Gerard Lopez
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.