Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ EUI Limited <ian.evans3@admiralgroup.co.uk>
Katarina Sheremet <katarina@sheremet.ch>
Thomas Stockx <thomas@stockxit.com>
Sarbagya Dhaubanjar <sarbagyastha@gmail.com>
Ozkan Eksi <ozeksi@gmail.com>
Ozkan Eksi <ozeksi@gmail.com>
ko2ic <ko2ic.dev@gmail.com>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
2EF3EFF8E25860E112E91756 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 799CAB03D87EEEE1FF65E7BE /* libPods-Runner.a */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
5C5A74FB1EAA74D700FE37CF /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 5C5A74FA1EAA74D700FE37CF /* GoogleService-Info.plist */; };
Expand Down Expand Up @@ -42,7 +41,6 @@

/* Begin PBXFileReference section */
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
5C5A74FA1EAA74D700FE37CF /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
5C8223BE1EC265DD00E12B15 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -89,7 +87,6 @@
children = (
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
9740EEB21CF90195004384FC /* Debug.xcconfig */,
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
Expand Down Expand Up @@ -223,7 +220,6 @@
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */,
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
Expand Down
6 changes: 6 additions & 0 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.6.0+4

* iOS: Using first byte to determine original image type.
* iOS: Added XCTest target.
* iOS: The picked image now has the correct EXIF data copied from the original image.

## 0.6.0+3

* Android: fixed assertion failures due to reply messages that were sent on the wrong thread.
Expand Down
213 changes: 187 additions & 26 deletions packages/image_picker/example/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "680049162280D368006DD6AB"
BuildableName = "image_picker_exampleTests.xctest"
BlueprintName = "image_picker_exampleTests"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@
"idiom" : "ipad",
"filename" : "Icon-App-83.5x83.5@2x.png",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <XCTest/XCTest.h>
#import "ImagePickerMetaDataUtil.h"

@interface MetaDataUtilTests : XCTestCase

@property(strong, nonatomic) NSBundle *testBundle;

@end

@implementation MetaDataUtilTests

- (void)setUp {
self.testBundle = [NSBundle bundleForClass:self.class];
}

- (void)testGetImageMIMETypeFromImageData {
// test jpeg
NSData *dataJPG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"jpgImage"
ofType:@"jpg"]];
XCTAssertEqual([ImagePickerMetaDataUtil getImageMIMETypeFromImageData:dataJPG],
FlutterImagePickerMIMETypeJPEG);

// test png
NSData *dataPNG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"pngImage"
ofType:@"png"]];
XCTAssertEqual([ImagePickerMetaDataUtil getImageMIMETypeFromImageData:dataPNG],
FlutterImagePickerMIMETypePNG);
}

- (void)testSuffixFromType {
// test jpeg
XCTAssertEqualObjects(
[ImagePickerMetaDataUtil imageTypeSuffixFromType:FlutterImagePickerMIMETypeJPEG], @".jpg");

// test png
XCTAssertEqualObjects(
[ImagePickerMetaDataUtil imageTypeSuffixFromType:FlutterImagePickerMIMETypePNG], @".png");

// test other
XCTAssertNil([ImagePickerMetaDataUtil imageTypeSuffixFromType:FlutterImagePickerMIMETypeOther]);
}

- (void)testGetMetaData {
NSData *dataJPG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"jpgImage"
ofType:@"jpg"]];
NSDictionary *metaData = [ImagePickerMetaDataUtil getMetaDataFromImageData:dataJPG];
NSDictionary *exif = [metaData objectForKey:(NSString *)kCGImagePropertyExifDictionary];
XCTAssertEqual([exif[(NSString *)kCGImagePropertyExifPixelXDimension] integerValue], 12);
}

- (void)testGetEXIFData {
NSData *dataJPG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"jpgImage"
ofType:@"jpg"]];
NSDictionary *exif = [ImagePickerMetaDataUtil getEXIFFromImageData:dataJPG];
XCTAssertNotNil(exif);
// hard coded test case based on the test image file saved in directory.
XCTAssertEqualObjects(exif[@"PixelXDimension"], @(12));
XCTAssertEqualObjects(exif[@"PixelYDimension"], @(7));
}

- (void)testWriteEXIFData {
NSData *dataJPG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"jpgImage"
ofType:@"jpg"]];
NSDictionary *metaData = [ImagePickerMetaDataUtil getMetaDataFromImageData:dataJPG];
NSDictionary *exif = [metaData objectForKey:(NSString *)kCGImagePropertyExifDictionary];
NSString *tmpFile = [NSString stringWithFormat:@"image_picker_test.jpg"];
NSString *tmpDirectory = NSTemporaryDirectory();
NSString *tmpPath = [tmpDirectory stringByAppendingPathComponent:tmpFile];
NSData *newData = [ImagePickerMetaDataUtil updateEXIFData:exif toImage:dataJPG];
if ([[NSFileManager defaultManager] createFileAtPath:tmpPath contents:newData attributes:nil]) {
NSData *savedTmpImageData = [NSData dataWithContentsOfFile:tmpPath];
NSDictionary *tmpMetaData =
[ImagePickerMetaDataUtil getMetaDataFromImageData:savedTmpImageData];
NSDictionary *tmpExif = [tmpMetaData objectForKey:(NSString *)kCGImagePropertyExifDictionary];
XCTAssert([tmpExif isEqualToDictionary:exif]);
} else {
XCTAssert(NO);
}
}

- (void)testConvertImageToData {
NSData *dataJPG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"jpgImage"
ofType:@"jpg"]];
UIImage *imageJPG = [UIImage imageWithData:dataJPG];
NSData *convertedDataJPG = [ImagePickerMetaDataUtil convertImage:imageJPG
usingType:FlutterImagePickerMIMETypeJPEG
quality:@(0.5)];
XCTAssertEqual([ImagePickerMetaDataUtil getImageMIMETypeFromImageData:convertedDataJPG],
FlutterImagePickerMIMETypeJPEG);

NSData *convertedDataPNG = [ImagePickerMetaDataUtil convertImage:imageJPG
usingType:FlutterImagePickerMIMETypePNG
quality:nil];
XCTAssertEqual([ImagePickerMetaDataUtil getImageMIMETypeFromImageData:convertedDataPNG],
FlutterImagePickerMIMETypePNG);

// test throws exceptions
XCTAssertThrows([ImagePickerMetaDataUtil convertImage:imageJPG
usingType:FlutterImagePickerMIMETypePNG
quality:@(0.5)],
@"setting quality when converting to PNG throws exception");
}
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <XCTest/XCTest.h>
#import "ImagePickerMetaDataUtil.h"
#import "ImagePickerPhotoAssetUtil.h"

@interface PhotoAssetUtilTests : XCTestCase

@property(strong, nonatomic) NSBundle *testBundle;

@end

@implementation PhotoAssetUtilTests

- (void)setUp {
self.testBundle = [NSBundle bundleForClass:self.class];
}

- (void)testSaveImageWithOriginalImageData_ShouldSaveWithTheCorrectExtentionAndMetaData {
// test jpg
NSData *dataJPG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"jpgImage"
ofType:@"jpg"]];
UIImage *imageJPG = [UIImage imageWithData:dataJPG];
NSString *savedPathJPG = [ImagePickerPhotoAssetUtil saveImageWithOriginalImageData:dataJPG
image:imageJPG];
XCTAssertNotNil(savedPathJPG);
XCTAssertEqualObjects([savedPathJPG substringFromIndex:savedPathJPG.length - 4], @".jpg");

// test png
NSData *dataPNG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"pngImage"
ofType:@"png"]];
UIImage *imagePNG = [UIImage imageWithData:dataPNG];
NSString *savedPathPNG = [ImagePickerPhotoAssetUtil saveImageWithOriginalImageData:dataPNG
image:imagePNG];
XCTAssertNotNil(savedPathPNG);
XCTAssertEqualObjects([savedPathPNG substringFromIndex:savedPathPNG.length - 4], @".png");
}

- (void)testSaveImageWithPickerInfo_ShouldSaveWithDefaultExtention {
NSData *dataJPG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"jpgImage"
ofType:@"jpg"]];
UIImage *imageJPG = [UIImage imageWithData:dataJPG];
NSString *savedPathJPG = [ImagePickerPhotoAssetUtil saveImageWithPickerInfo:nil image:imageJPG];

XCTAssertNotNil(savedPathJPG);
// should be saved as
XCTAssertEqualObjects([savedPathJPG substringFromIndex:savedPathJPG.length - 4],
kFlutterImagePickerDefaultSuffix);
}

- (void)testSaveImageWithPickerInfo_ShouldSaveWithTheCorrectExtentionAndMetaData {
NSDictionary *dummyInfo = @{
UIImagePickerControllerMediaMetadata : @{
(__bridge NSString *)kCGImagePropertyExifDictionary :
@{(__bridge NSString *)kCGImagePropertyExifMakerNote : @"aNote"}
}
};
NSData *dataJPG = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"jpgImage"
ofType:@"jpg"]];
UIImage *imageJPG = [UIImage imageWithData:dataJPG];
NSString *savedPathJPG = [ImagePickerPhotoAssetUtil saveImageWithPickerInfo:dummyInfo
image:imageJPG];
NSData *data = [NSData dataWithContentsOfFile:savedPathJPG];
NSDictionary *exif = [ImagePickerMetaDataUtil getEXIFFromImageData:data];
XCTAssertEqualObjects(exif[(__bridge NSString *)kCGImagePropertyExifMakerNote], @"aNote");
}

@end
44 changes: 44 additions & 0 deletions packages/image_picker/ios/Classes/ImagePickerMetaDataUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef enum : NSUInteger {
FlutterImagePickerMIMETypePNG,
FlutterImagePickerMIMETypeJPEG,
FlutterImagePickerMIMETypeOther,
} FlutterImagePickerMIMEType;

extern NSString *const kFlutterImagePickerDefaultSuffix;
extern const FlutterImagePickerMIMEType kFlutterImagePickerMIMETypeDefault;

@interface ImagePickerMetaDataUtil : NSObject

// Retrieve MIME type by reading the image data. We currently only support some popular types.
+ (FlutterImagePickerMIMEType)getImageMIMETypeFromImageData:(NSData *)imageData;

// Get corresponding surfix from type.
+ (NSString *)imageTypeSuffixFromType:(FlutterImagePickerMIMEType)type;

+ (NSDictionary *)getMetaDataFromImageData:(NSData *)imageData;

+ (NSDictionary *)getEXIFFromImageData:(NSData *)imageData;

+ (NSData *)updateEXIFData:(NSDictionary *)exifData toImage:(NSData *)imageData;

// Converting UIImage to a NSData with the type proveide.
//
// The quality is for JPEG type only, it defaults to 1. It throws exception if setting a non-nil
// quality with type other than FlutterImagePickerMIMETypeJPEG. Converting UIImage to
// FlutterImagePickerMIMETypeGIF or FlutterImagePickerMIMETypeTIFF is not supported in iOS. This
// method throws exception if trying to do so.
+ (nonnull NSData *)convertImage:(nonnull UIImage *)image
Copy link
Contributor

@ko2ic ko2ic May 10, 2019

Choose a reason for hiding this comment

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

If the argument type here is not UIImage but NSData, it can handle gif images.

Please refer to the following.

https://github.com/flutter/plugins/pull/866/files#diff-ce2e9c98db20f69ecf981788585d7a87R209

This will be able to also handle animated gif.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can add the gif handling in a separate PR. I also want to take a deeper dive into the implementation to see if there is a way to support scaling gif. If not, then we need to decide how to handle when people passed the scaling factors into the API.

usingType:(FlutterImagePickerMIMEType)type
quality:(nullable NSNumber *)quality;

@end

NS_ASSUME_NONNULL_END
Loading