Uploaded Image Size For native.showPopUp( )

I am looking for some advice on how the social media plugin processes images before uploading them to twitter.

The issue that I am having is that I am trying to upload a large image to twitter on iOS, as big as 1024 x 4096, but when I upload it via the native.showPopUp function the height is clamped down to 1024. Now I know that twitter will limit the size of images uploading to its platform, but when I upload the same image through the twitter app or through the web client the height is only getting clamped at 2048.

This does not appear to be an issue on Android, though I would wager it is due in part to the difference between the way the two platforms handle sharing social media. Is there something special going on with the native library on iOS that is causing the image to be shrunk further than it has to be?

Thanks for the help,

Ian

Hey Ian,

The plugin code for the social popup plugin does not do any special processing of images posted to Twitter. Any service specific image processing is done by the Apple APIs used to implement the social popup plugin on iOS.

In fact, here’s the relevant code bits:

// native.showPopup("social") entry point int IOSSocialNativePopupProvider::showPopup( lua\_State \*L ) { // ... Lua::Ref listenerRef = NULL; // options.listener lua\_getfield( L, -1, "listener" ); if ( Lua::IsListener( L, -1, kEventName ) ) { // Create native reference to listener listenerRef = Lua::NewRef( L, -1 ); } lua\_pop( L, 1 ); // ... // Set up our SLComposeViewController, for the service type specified controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceType]; // ... // options.image lua\_getfield( L, -1, "image" ); if ( lua\_istable( L, -1 ) ) { int numImages = lua\_objlen( L, -1 ); if ( numImages \> 0 ) { bool noError = true; // table is an array of 'path' tables for ( int i = 1; noError && i \<= numImages; i++ ) { lua\_rawgeti( L, -1, i ); noError = AddImage( L, controller, listenerRef ); lua\_pop( L, 1 ); } } else { AddImage( L, controller, listenerRef ); } } lua\_pop( L, 1 ); // ... } static bool AddImage( lua\_State \*L, SLComposeViewController \*controller, Corona::Lua::Ref listenerRef ) { using namespace Corona; bool result = false; // pathService-\>PushPath( L, -1 ); CoronaLibraryCallFunction( L, "system", "pathForTable", "t\>s", CoronaLuaNormalize( L, -1 ) ); const char \*str = lua\_tostring( L, -1 ); if ( str ) { NSString \*path = [NSString stringWithUTF8String:str]; UIImage \*image = [UIImage imageWithContentsOfFile:path]; result = [controller addImage:image]; if ( ! result && listenerRef ) { // Create event PushEvent( L, str ); Lua::DispatchEvent( L, listenerRef, 0 ); } } lua\_pop( L, 1 ); return result; }

Outside of creating an SLComposeViewController for a specific service type, the call to [SLComposeViewController addImage] is where any service-specific image processing would occur. The Discussion section of that APIs docs states that:

Image size limits are dependent on the target service and are documented by the service provider. 

After a quick browse through Twitter’s REST documentation, it seems that their constraints on images files are just based on file size, not resolution.

All that being said, it sounds like the limits that Twitter imposes to Apple are inconsistent with what’s allowed with their app or through the browser. Why that’s the case is a good question.

Also, the code for this plugin is open-source if you want to dive deeper into it. It’s available on GitHub here.

Hope that helps.

Hey Ian,

The plugin code for the social popup plugin does not do any special processing of images posted to Twitter. Any service specific image processing is done by the Apple APIs used to implement the social popup plugin on iOS.

In fact, here’s the relevant code bits:

// native.showPopup("social") entry point int IOSSocialNativePopupProvider::showPopup( lua\_State \*L ) { // ... Lua::Ref listenerRef = NULL; // options.listener lua\_getfield( L, -1, "listener" ); if ( Lua::IsListener( L, -1, kEventName ) ) { // Create native reference to listener listenerRef = Lua::NewRef( L, -1 ); } lua\_pop( L, 1 ); // ... // Set up our SLComposeViewController, for the service type specified controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceType]; // ... // options.image lua\_getfield( L, -1, "image" ); if ( lua\_istable( L, -1 ) ) { int numImages = lua\_objlen( L, -1 ); if ( numImages \> 0 ) { bool noError = true; // table is an array of 'path' tables for ( int i = 1; noError && i \<= numImages; i++ ) { lua\_rawgeti( L, -1, i ); noError = AddImage( L, controller, listenerRef ); lua\_pop( L, 1 ); } } else { AddImage( L, controller, listenerRef ); } } lua\_pop( L, 1 ); // ... } static bool AddImage( lua\_State \*L, SLComposeViewController \*controller, Corona::Lua::Ref listenerRef ) { using namespace Corona; bool result = false; // pathService-\>PushPath( L, -1 ); CoronaLibraryCallFunction( L, "system", "pathForTable", "t\>s", CoronaLuaNormalize( L, -1 ) ); const char \*str = lua\_tostring( L, -1 ); if ( str ) { NSString \*path = [NSString stringWithUTF8String:str]; UIImage \*image = [UIImage imageWithContentsOfFile:path]; result = [controller addImage:image]; if ( ! result && listenerRef ) { // Create event PushEvent( L, str ); Lua::DispatchEvent( L, listenerRef, 0 ); } } lua\_pop( L, 1 ); return result; }

Outside of creating an SLComposeViewController for a specific service type, the call to [SLComposeViewController addImage] is where any service-specific image processing would occur. The Discussion section of that APIs docs states that:

Image size limits are dependent on the target service and are documented by the service provider. 

After a quick browse through Twitter’s REST documentation, it seems that their constraints on images files are just based on file size, not resolution.

All that being said, it sounds like the limits that Twitter imposes to Apple are inconsistent with what’s allowed with their app or through the browser. Why that’s the case is a good question.

Also, the code for this plugin is open-source if you want to dive deeper into it. It’s available on GitHub here.

Hope that helps.