Skip to content

fix: apply targetWidth and targetHeight when picking images from gallery - #16

Open
andredestro wants to merge 1 commit into
mainfrom
fix/ios-gallery-target-size
Open

fix: apply targetWidth and targetHeight when picking images from gallery#16
andredestro wants to merge 1 commit into
mainfrom
fix/ios-gallery-target-size

Conversation

@andredestro

@andredestro andredestro commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes targetWidth and targetHeight being silently ignored when picking images from the gallery.
  • Adds size: IONCAMRSize? to IONCAMRGalleryOptions, decoded from the targetWidth/targetHeight keys (both must be present; if only one is provided, the size is ignored)
  • Propagates targetSize through IONCAMRGalleryBehaviour down to IONCAMRPhotoLibraryService
  • When targetSize is set, the selected image is resized via resizeTo(_:) and compressed with the default thumbnail quality before being returned as base64; otherwise the existing pictureThumbnailData() path is used

@andredestro
andredestro force-pushed the fix/ios-gallery-target-size branch from 7e498d8 to f6d1acf Compare April 27, 2026 16:49
@OS-pedrogustavobilro OS-pedrogustavobilro self-assigned this Apr 28, 2026

@OS-pedrogustavobilro OS-pedrogustavobilro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested and it seems to now resize the image when passing targetWidth / targetHeight from gallery, but noticed some things that may still need to be addressed.

Comment on lines +166 to +171
let resized = image.resizeTo(CGSize(size: size)) ?? image
let quality = CGFloat(IONCAMRTakePhotoOptions.ThumbnailDefaultConfigurations.quality) / 100
guard let data = resized.jpegData(compressionQuality: quality)?.base64EncodedString()
else { throw IONCAMRError.imageNotFound }
finalImage = resized
imageData = data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this should be applied to only the thumbnail or also the image URI being returned (i.e. save the image to a new URI, possibly cache, and return that instead)?

Also, targetWidth / targetHeight doesn't seem to get applied if we pass something in "editable". Possibly it goes through a different flow?

let finalImage: UIImage
let imageData: String
if let size = targetSize {
let resized = image.resizeTo(CGSize(size: size)) ?? image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the resize would be to the exact dimensions, but it seems that it does it an way that makes it such that it can switch up the dimensions. I think the capacitor example app doesn't show the thumbnail so it makes it hard to tell (related to my other comment), but this logic probably comes from the old cordova plugin / native library, but just checking if it's by design.

        // Figure out what our orientation is, and use that to form the rectangle
        let newSize = if widthRatio > heightRatio {
            CGSize(width: sourceImage.size.width * heightRatio, height: sourceImage.size.height * heightRatio)
        } else {
            CGSize(width: sourceImage.size.width * widthRatio, height: sourceImage.size.height * widthRatio)
        }

Because if it is, maybe we need to see what Android should do, and update the docs on what targetWidth / targetHeight are meant to be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants