[ 
https://issues.apache.org/jira/browse/CB-54?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13158869#comment-13158869
 ] 

Shazron Abdullah commented on CB-54:
------------------------------------

by: https://github.com/patdenice

I finally wrote a phonegap plugin to extend camera API:

In my app, I call camera.getResizedPicture method instead of camera.getPicture 
with same parameters. With targetWidth and targetHeight parameters, my image is 
just resized and not cropped.

cameraExtended.js

    Camera.prototype.getResizedPicture = function(successCallback, 
errorCallback, options) {
    
        // successCallback required
        if (typeof successCallback != "function") {
            console.log("Camera Error: successCallback is not a function");
            return;
        }
    
        // errorCallback optional
        if (errorCallback && (typeof errorCallback != "function")) {
            console.log("Camera Error: errorCallback is not a function");
            return;
        }
    
        PhoneGap.exec(successCallback, errorCallback, 
"com.phonegap.cameraExtended","getPicture",[options]);
    };

cameraExtended.h

    #import "PhoneGap/Camera.h"
    
    @interface PGCameraExtended : PGCamera<UIImagePickerControllerDelegate, 
                                                                        
UINavigationControllerDelegate,
                                                                        
UIPopoverControllerDelegate>
    {
    }
    
    - (UIImage*)imageByScalingAndCroppingForSize:(UIImage*)anImage 
toSize:(CGSize)targetSize;
    
    @end

cameraExtended.m

    #import "cameraExtended.h"
    
    @implementation PGCameraExtended
    
    - (UIImage*)imageByScalingAndCroppingForSize:(UIImage*)anImage 
toSize:(CGSize)targetSize
    {
        UIImage *sourceImage = anImage;
        UIImage *newImage = nil;        
        CGSize imageSize = sourceImage.size;
        CGFloat width = imageSize.width;
        CGFloat height = imageSize.height;
        CGFloat targetWidth = targetSize.width;
        CGFloat targetHeight = targetSize.height;
        CGFloat scaledWidth = targetWidth;
        CGFloat scaledHeight = targetHeight;
      
        CGFloat ratio_width  = width / targetWidth;
        CGFloat ratio_height = height / targetHeight;
      
        // maximal size exceeded ?
        if (ratio_width > 1 || ratio_height > 1)
        {
          if (ratio_width < ratio_height)
          { 
            scaledWidth = ceil(width / ratio_height);
          }
          else
          { 
            scaledHeight = ceil(height / ratio_width);
          }
    
          targetSize = CGSizeMake(scaledWidth, scaledHeight);
          self.pickerController.targetSize = targetSize;
        }
        else
        {
          return sourceImage;
        }
        
        UIGraphicsBeginImageContext(targetSize);
        
        CGRect thumbnailRect = CGRectZero;
        thumbnailRect.size.width  = scaledWidth;
        thumbnailRect.size.height = scaledHeight;
        
        [sourceImage drawInRect:thumbnailRect];
        
        newImage = UIGraphicsGetImageFromCurrentImageContext();
        if(newImage == nil) 
            NSLog(@"could not scale image");
        
        //pop the context to get back to the default
        UIGraphicsEndImageContext();
        return newImage;
    }
    
    @end
                
> Feature request: ability to downsize pictures with camera.getPicture (no crop)
> ------------------------------------------------------------------------------
>
>                 Key: CB-54
>                 URL: https://issues.apache.org/jira/browse/CB-54
>             Project: Apache Callback
>          Issue Type: New Feature
>          Components: iOS
>            Reporter: Shazron Abdullah
>
> reported at: https://github.com/phonegap/phonegap-iphone/issues/287
> by: https://github.com/patdenice
> Hi,
> We're working on a mobile application using phonegap. The application is 
> designed to upload photos from the smartphone/tablet to a Piwigo gallery. 
> Piwigo is a popular open source web application to create photo galleries. 
> The application "Piwigo for iOS/Android" is nearly complete, we just need the 
> ability to downsize photos before upload. Unfortunately, targetWidth and 
> targetHeight parameters on camera.getPicture method are designed to crop the 
> photo, which is what we're seeking. Would it be possible to add 
> maxWidth/maxHeight parameters and resize algorithm ?
> Thanks.
> P@t
> Piwigo Team.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to