android-smsmms icon indicating copy to clipboard operation
android-smsmms copied to clipboard

Library stalls when trying to send .gif file

Open NickM-27 opened this issue 7 years ago • 12 comments

I use the code below to allow users to send gifs:

Message message = new Message(body, address);
message.addMedia(extra, "image/gif");

My issue is that the gifs that come from the keyboard or are sent by the user are 2-3 mb which make the sending process just sit and I don't see an error, just all future messages also don't work.

Can you provide a procedure to lower the .gif size in order to send it using this library?

Thanks!

NickM-27 avatar Aug 01 '17 14:08 NickM-27

I've worked with GIFs a bit and from what I understand, sending 2-3 MB through most MMS providers will not work. I find that I have success when I keep the size of the GIF under 1MB.

Can you test sending a GIF that is less than 500KB which is guaranteed to be supported by all carriers? If you are unable to send/receive that GIF, then it means there is something wrong in your code or configurations and probably not the library.

rayliverified avatar Aug 01 '17 14:08 rayliverified

@searchy2 I can try to find a small gif to send. The issue for me is that I do not know how to lower the file size of gifs that are provided to me. I know a lot of mms apps out there are able to lower the file size of the gif before sending, I am hoping to find out how to do that.

NickM-27 avatar Aug 01 '17 15:08 NickM-27

This library won't support compressing images or gifs, but that is most likely the problem.

klinker41 avatar Aug 01 '17 15:08 klinker41

@NickM-27 If you make a way to do this, post it here. I don't have a way to resize them at this time. I just download lower quality versions from GIPHY: https://github.com/klinker24/Android-GiphySearch

klinker24 avatar Aug 01 '17 15:08 klinker24

@klinker24 @klinker41 ohhhh interesting, that makes sense. So in your app when a user chooses a local file that is a gif, it is just sent as a static image?

NickM-27 avatar Aug 01 '17 15:08 NickM-27

I will work on finding a way to do this, I have a few ideas that might work. I will post here if I find something.

NickM-27 avatar Aug 01 '17 15:08 NickM-27

Gifs are basically just a bunch of jpg frames combined I believe, so I wonder how difficult it would be to resize each individual frame and then check the file size again?

klinker41 avatar Aug 01 '17 15:08 klinker41

@klinker41 I was talking to Francisco Franko about this and he told me that when you get a byte[] from a gif file, the first parts of the array are gif headers. He recommended trying to find the header which corresponds to the w * h size and change that, then make a new gif file to send which has the new size. He also gave me this link: http://www.onicos.com/staff/iz/formats/gif.html which has the header positions on there.

NickM-27 avatar Aug 01 '17 16:08 NickM-27

Sure... but I can't see that working out exactly as you're picturing. Changing the header and making a new gif may force each frame to be that size, but I'd be very surprised if it actually resized the frame instead of just chopping off the extra. I'm not even sure that will work, you're going to have to modify the underlying byte[] somehow, just passing the same bytes into a new file with a different header isn't going to change anything for you, probably just how the gif gets displayed.

klinker41 avatar Aug 01 '17 16:08 klinker41

@klinker41 True, that's a good point. I know that there is a way to get each frame, maybe that would be the best bet to try. If I am not too busy tomorrow, I may try it then.

NickM-27 avatar Aug 01 '17 16:08 NickM-27

@klinker41 I believe that with the new Android P support with ImageDecoder it will be trivial to make a gif that is a small enough size to send (250 x 250?). I am going to test this soon but will let you know

NickM-27 avatar May 17 '18 19:05 NickM-27

I haven't read much into ImageDecoder, but that would be cool if it does work well!

klinker41 avatar May 17 '18 21:05 klinker41