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
4 changes: 4 additions & 0 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0+12

* Use class instead of struct for `GIFInfo` in iOS implementation.

## 0.6.0+11

* Don't use module imports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (void)testScaledGIFImage_ShouldBeScaled {
// gif image that frame size is 3 and the duration is 1 second.
NSData *data = [NSData dataWithContentsOfFile:[self.testBundle pathForResource:@"gifImage"
ofType:@"gif"]];
GIFInfo info = [FLTImagePickerImageUtil scaledGIFImage:data maxWidth:@3 maxHeight:@2];
GIFInfo *info = [FLTImagePickerImageUtil scaledGIFImage:data maxWidth:@3 maxHeight:@2];

NSArray<UIImage *> *images = info.images;
NSTimeInterval duration = info.interval;
Expand Down
19 changes: 11 additions & 8 deletions packages/image_picker/ios/Classes/FLTImagePickerImageUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

NS_ASSUME_NONNULL_BEGIN

typedef struct GIFInfo {
// frames of animation
NSArray<UIImage *> *images;
NSTimeInterval interval;
} GIFInfo;
@interface GIFInfo : NSObject

@property(strong, nonatomic, readonly) NSArray<UIImage *> *images;
@property(assign, nonatomic, readonly) NSTimeInterval interval;

- (instancetype)initWithImages:(NSArray<UIImage *> *)images interval:(NSTimeInterval)interval;

@end

@interface FLTImagePickerImageUtil : NSObject

Expand All @@ -20,9 +23,9 @@ typedef struct GIFInfo {
maxHeight:(NSNumber *)maxHeight;

// Resize all gif animation frames.
+ (GIFInfo)scaledGIFImage:(NSData *)data
maxWidth:(NSNumber *)maxWidth
maxHeight:(NSNumber *)maxHeight;
+ (GIFInfo *)scaledGIFImage:(NSData *)data
maxWidth:(NSNumber *)maxWidth
maxHeight:(NSNumber *)maxHeight;

@end

Expand Down
31 changes: 25 additions & 6 deletions packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
#import "FLTImagePickerImageUtil.h"
#import <MobileCoreServices/MobileCoreServices.h>

@interface GIFInfo ()

@property(strong, nonatomic, readwrite) NSArray<UIImage *> *images;
@property(assign, nonatomic, readwrite) NSTimeInterval interval;

@end

@implementation GIFInfo

- (instancetype)initWithImages:(NSArray<UIImage *> *)images interval:(NSTimeInterval)interval;
{
self = [super init];
if (self) {
self.images = images;
self.interval = interval;
}
return self;
}

@end

@implementation FLTImagePickerImageUtil : NSObject

+ (UIImage *)scaledImage:(UIImage *)image
Expand Down Expand Up @@ -57,9 +78,9 @@ + (UIImage *)scaledImage:(UIImage *)image
return scaledImage;
}

+ (GIFInfo)scaledGIFImage:(NSData *)data
maxWidth:(NSNumber *)maxWidth
maxHeight:(NSNumber *)maxHeight {
+ (GIFInfo *)scaledGIFImage:(NSData *)data
maxWidth:(NSNumber *)maxWidth
maxHeight:(NSNumber *)maxHeight {
NSMutableDictionary<NSString *, id> *options = [NSMutableDictionary dictionary];
options[(NSString *)kCGImageSourceShouldCache] = @(YES);
options[(NSString *)kCGImageSourceTypeIdentifierHint] = (NSString *)kUTTypeGIF;
Expand Down Expand Up @@ -98,9 +119,7 @@ + (GIFInfo)scaledGIFImage:(NSData *)data

CFRelease(imageSource);

GIFInfo info;
info.images = images;
info.interval = interval;
GIFInfo *info = [[GIFInfo alloc] initWithImages:images interval:interval];

return info;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/image_picker/ios/Classes/FLTImagePickerPhotoAssetUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#import "FLTImagePickerImageUtil.h"
#import "FLTImagePickerMetaDataUtil.h"

#import <MobileCoreServices/MobileCoreServices.h>;
#import <MobileCoreServices/MobileCoreServices.h>

@implementation FLTImagePickerPhotoAssetUtil

Expand Down Expand Up @@ -35,9 +35,9 @@ + (NSString *)saveImageWithOriginalImageData:(NSData *)originalImageData
metaData = [FLTImagePickerMetaDataUtil getMetaDataFromImageData:originalImageData];
}
if (type == FLTImagePickerMIMETypeGIF) {
GIFInfo gifInfo = [FLTImagePickerImageUtil scaledGIFImage:originalImageData
maxWidth:maxWidth
maxHeight:maxHeight];
GIFInfo *gifInfo = [FLTImagePickerImageUtil scaledGIFImage:originalImageData
maxWidth:maxWidth
maxHeight:maxHeight];

return [self saveImageWithMetaData:metaData gifInfo:gifInfo suffix:suffix];
} else {
Expand All @@ -54,7 +54,7 @@ + (NSString *)saveImageWithPickerInfo:(nullable NSDictionary *)info image:(UIIma
}

+ (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
gifInfo:(GIFInfo)gifInfo
gifInfo:(GIFInfo *)gifInfo
suffix:(NSString *)suffix {
NSString *path = [self temporaryFilePath:suffix];
return [self saveImageWithMetaData:metaData gifInfo:gifInfo path:path];
Expand Down Expand Up @@ -82,7 +82,7 @@ + (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
}

+ (NSString *)saveImageWithMetaData:(NSDictionary *)metaData
gifInfo:(GIFInfo)gifInfo
gifInfo:(GIFInfo *)gifInfo
path:(NSString *)path {
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
(CFURLRef)[NSURL fileURLWithPath:path], kUTTypeGIF, gifInfo.images.count, NULL);
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors:
- Flutter Team <flutter-dev@googlegroups.com>
- Rhodes Davis Jr. <rody.davis.jr@gmail.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker
version: 0.6.0+11
version: 0.6.0+12

flutter:
plugin:
Expand Down