Skip to content

Commit

Permalink
fix image quality will change after export
Browse files Browse the repository at this point in the history
  • Loading branch information
lilthree committed Mar 30, 2019
1 parent 58b0e45 commit 5ae9e20
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
6 changes: 4 additions & 2 deletions Pod/Classes/SeafFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,10 @@ - (UIImage *)image
if (!self.ooid)
return nil;
NSString *path = [SeafStorage.sharedObject documentPath:self.ooid];
NSString *cachePath = [[SeafStorage.sharedObject tempDir] stringByAppendingPathComponent:self.ooid];
return [Utils imageFromPath:path withMaxSize:IMAGE_MAX_SIZE cachePath:cachePath andFileName:self.name];
NSString *name = [@"cacheimage-preview-" stringByAppendingString:self.name];
NSString *cachePath = [[[SeafStorage.sharedObject tempDir] stringByAppendingPathComponent:self.ooid] stringByAppendingPathComponent:name];
return [Utils imageFromPath:path withMaxSize:IMAGE_MAX_SIZE cachePath:cachePath];

}

- (long long)filesize
Expand Down
8 changes: 3 additions & 5 deletions Pod/Classes/SeafPhotoAsset.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ - (NSString *)assetName:(PHAsset *)asset {
//private api,same as originalFilename, test on iOS12 iOS11.1 iOS10.3 iOS9.0 iOS8.4
name = [asset valueForKey:@"filename"];
} else {
if (@available(iOS 9.0, *)) {
//it's very slow to get the originalFilename
NSArray *resources = [PHAssetResource assetResourcesForAsset:asset];
name = ((PHAssetResource*)resources.firstObject).originalFilename;
}
//it's very slow to get the originalFilename
NSArray *resources = [PHAssetResource assetResourcesForAsset:asset];
name = ((PHAssetResource*)resources.firstObject).originalFilename;
}
if ([name hasPrefix:@"IMG_"]) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
Expand Down
1 change: 0 additions & 1 deletion Pod/Classes/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

+ (UIImage *)reSizeImage:(UIImage *)image toSquare:(float)length;
+ (UIImage *)imageFromPath:(NSString *)path withMaxSize:(float)length cachePath:(NSString *)cachePath;
+ (UIImage *)imageFromPath:(NSString *)path withMaxSize:(float)length cachePath:(NSString *)cachePath andFileName:(NSString *)fileName;

+ (NSDictionary *)queryToDict:(NSString *)query;
+ (void)dict:(NSMutableDictionary *)dict setObject:(id)value forKey:(NSString *)defaultName;
Expand Down
20 changes: 0 additions & 20 deletions Pod/Classes/Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -521,26 +521,6 @@ + (UIImage *)imageFromPath:(NSString *)path withMaxSize:(float)length cachePath:
return nil;
}

+ (UIImage *)imageFromPath:(NSString *)path withMaxSize:(float)length cachePath:(NSString *)cachePath andFileName:(NSString *)fileName
{
const int MAX_SIZE = 2048;
if ([[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",cachePath,fileName]];
return image;
}

if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
UIImage *image = [UIImage imageWithContentsOfFile:path];
if (image.size.width > MAX_SIZE || image.size.height > MAX_SIZE) {
UIImage *img = [Utils reSizeImage:image toSquare:MAX_SIZE];
[UIImageJPEGRepresentation(img, 1.0) writeToFile:path atomically:YES];
return img;
}
return image;
}
return nil;
}

+ (NSString *)encodePath:(NSString *)server username:(NSString *)username repo:(NSString *)repoId path:(NSString *)path
{
NSMutableCharacterSet *allowedSet = [NSMutableCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ0123456789"];
Expand Down

0 comments on commit 5ae9e20

Please sign in to comment.