-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-12189] set appropriate Blob mime-type when manipulating on images #3678
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,9 @@ | |
//NOTE:FilesystemFile is conditionally compiled based on the filesystem module. | ||
#import "TiFilesystemFileProxy.h" | ||
|
||
static NSString *const MIMETYPE_PNG = @"image/png"; | ||
static NSString *const MIMETYPE_JPEG = @"image/jpeg"; | ||
|
||
@implementation TiBlob | ||
|
||
-(void)dealloc | ||
|
@@ -106,7 +109,7 @@ -(id)initWithImage:(UIImage*)image_ | |
{ | ||
image = [image_ retain]; | ||
type = TiBlobTypeImage; | ||
mimetype = [@"image/jpeg" retain]; | ||
mimetype = [MIMETYPE_JPEG copy]; | ||
} | ||
return self; | ||
} | ||
|
@@ -117,7 +120,7 @@ -(id)initWithData:(NSData*)data_ mimetype:(NSString*)mimetype_ | |
{ | ||
data = [data_ retain]; | ||
type = TiBlobTypeData; | ||
mimetype = [mimetype_ retain]; | ||
mimetype = [mimetype_ copy]; | ||
} | ||
return self; | ||
} | ||
|
@@ -128,7 +131,7 @@ -(id)initWithFile:(NSString*)path_ | |
{ | ||
type = TiBlobTypeFile; | ||
path = [path_ retain]; | ||
mimetype = [[Mimetypes mimeTypeForExtension:path] retain]; | ||
mimetype = [[Mimetypes mimeTypeForExtension:path] copy]; | ||
} | ||
return self; | ||
} | ||
|
@@ -175,7 +178,7 @@ -(NSData*)data | |
} | ||
case TiBlobTypeImage: | ||
{ | ||
if ([@"image/png" isEqualToString:mimetype]) { | ||
if ([mimetype isEqualToString:MIMETYPE_PNG]) { | ||
return UIImagePNGRepresentation(image); | ||
} | ||
return UIImageJPEGRepresentation(image,1.0); | ||
|
@@ -217,7 +220,7 @@ -(void)setImage:(UIImage *)image_ | |
{ | ||
RELEASE_TO_NIL(image); | ||
image = [image_ retain]; | ||
[self setMimeType:@"image/jpeg" type:TiBlobTypeImage]; | ||
[self setMimeType:MIMETYPE_JPEG type:TiBlobTypeImage]; | ||
} | ||
|
||
-(NSString*)path | ||
|
@@ -263,7 +266,7 @@ -(NSNumber*)length | |
-(void)setMimeType:(NSString*)mime type:(TiBlobType)type_ | ||
{ | ||
RELEASE_TO_NIL(mimetype); | ||
mimetype = [mime retain]; | ||
mimetype = [mime copy]; | ||
type = type_; | ||
} | ||
|
||
|
@@ -302,7 +305,9 @@ - (id)imageWithAlpha:(id)args | |
[self ensureImageLoaded]; | ||
if (image!=nil) | ||
{ | ||
return [[[TiBlob alloc] initWithImage:[UIImageAlpha imageWithAlpha:image]] autorelease]; | ||
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageAlpha imageWithAlpha:image]]; | ||
[blob setMimeType:MIMETYPE_PNG type:TiBlobTypeImage]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not required |
||
return [blob autorelease]; | ||
} | ||
return nil; | ||
} | ||
|
@@ -314,7 +319,9 @@ - (id)imageWithTransparentBorder:(id)args | |
{ | ||
ENSURE_SINGLE_ARG(args,NSObject); | ||
NSUInteger size = [TiUtils intValue:args]; | ||
return [[[TiBlob alloc] initWithImage:[UIImageAlpha transparentBorderImage:size image:image]] autorelease]; | ||
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageAlpha transparentBorderImage:size image:image]]; | ||
[blob setMimeType:MIMETYPE_PNG type:TiBlobTypeImage]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not Required |
||
return [blob autorelease]; | ||
} | ||
return nil; | ||
} | ||
|
@@ -326,7 +333,9 @@ - (id)imageWithRoundedCorner:(id)args | |
{ | ||
NSUInteger cornerSize = [TiUtils intValue:[args objectAtIndex:0]]; | ||
NSUInteger borderSize = [args count] > 1 ? [TiUtils intValue:[args objectAtIndex:1]] : 1; | ||
return [[[TiBlob alloc] initWithImage:[UIImageRoundedCorner roundedCornerImage:cornerSize borderSize:borderSize image:image]] autorelease]; | ||
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageRoundedCorner roundedCornerImage:cornerSize borderSize:borderSize image:image]]; | ||
[blob setMimeType:MIMETYPE_PNG type:TiBlobTypeImage]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not Required |
||
return [blob autorelease]; | ||
} | ||
return nil; | ||
} | ||
|
@@ -339,12 +348,13 @@ - (id)imageAsThumbnail:(id)args | |
NSUInteger size = [TiUtils intValue:[args objectAtIndex:0]]; | ||
NSUInteger borderSize = [args count] > 1 ? [TiUtils intValue:[args objectAtIndex:1]] : 1; | ||
NSUInteger cornerRadius = [args count] > 2 ? [TiUtils intValue:[args objectAtIndex:2]] : 0; | ||
return [[[TiBlob alloc] initWithImage:[UIImageResize thumbnailImage:size | ||
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageResize thumbnailImage:size | ||
transparentBorder:borderSize | ||
cornerRadius:cornerRadius | ||
interpolationQuality:kCGInterpolationHigh | ||
image:image]] | ||
autorelease]; | ||
image:image]]; | ||
[blob setMimeType:MIMETYPE_PNG type:TiBlobTypeImage]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not Required |
||
return [blob autorelease]; | ||
} | ||
return nil; | ||
} | ||
|
@@ -357,7 +367,9 @@ - (id)imageAsResized:(id)args | |
ENSURE_ARG_COUNT(args,2); | ||
NSUInteger width = [TiUtils intValue:[args objectAtIndex:0]]; | ||
NSUInteger height = [TiUtils intValue:[args objectAtIndex:1]]; | ||
return [[[TiBlob alloc] initWithImage:[UIImageResize resizedImage:CGSizeMake(width, height) interpolationQuality:kCGInterpolationHigh image:image hires:NO]] autorelease]; | ||
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageResize resizedImage:CGSizeMake(width, height) interpolationQuality:kCGInterpolationHigh image:image hires:NO]]; | ||
[blob setMimeType:self.mimeType type:self.type]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not Required |
||
return [blob autorelease]; | ||
} | ||
return nil; | ||
} | ||
|
@@ -374,7 +386,9 @@ - (id)imageAsCropped:(id)args | |
bounds.size.height = [TiUtils floatValue:@"height" properties:args def:imageSize.height]; | ||
bounds.origin.x = [TiUtils floatValue:@"x" properties:args def:(imageSize.width - bounds.size.width) / 2.0]; | ||
bounds.origin.y = [TiUtils floatValue:@"y" properties:args def:(imageSize.height - bounds.size.height) / 2.0]; | ||
return [[[TiBlob alloc] initWithImage:[UIImageResize croppedImage:bounds image:image]] autorelease]; | ||
TiBlob *blob = [[TiBlob alloc] initWithImage:[UIImageResize croppedImage:bounds image:image]]; | ||
[blob setMimeType:self.mimeType type:self.type]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not Required |
||
return [blob autorelease]; | ||
} | ||
return nil; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (UIImageAlpha hasAlpha:image] {
mimetype = [MIMETYPE_PNG copy];
}
else {
mimetype = [MIMETYPE_JPEG copy];
}