If you have an issue with any of our projects. feel free to register.

Commit e16d4e8a authored by Dmitry Nevedomsky's avatar Dmitry Nevedomsky

Save artwork to jpg instead of png to reduce size.

parent bd4e64c0
......@@ -177,26 +177,31 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
if ([defaults boolForKey:@"notifications.show-album-art"] && [pe albumArtInternal]) {
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *tmpSubFolderName = [NSProcessInfo.processInfo globallyUniqueString];
NSURL *tmpSubFolderURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()]
URLByAppendingPathComponent:tmpSubFolderName isDirectory:true];
URLByAppendingPathComponent:@"cog-artworks-cache" isDirectory:true];
if ([fileManager createDirectoryAtPath:[tmpSubFolderURL path]
error:&error]) {
NSURL *fileURL = [tmpSubFolderURL URLByAppendingPathComponent:@"art.png"];
NSString *tmpFileName = [[NSProcessInfo.processInfo globallyUniqueString] stringByAppendingString:@".jpg"];
NSURL *fileURL = [tmpSubFolderURL URLByAppendingPathComponent:tmpFileName];
NSImage *image = [pe albumArt];
CGImageRef cgRef = [image CGImageForProposedRect:NULL context:nil hints:nil];
NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
[newRep setSize:[image size]];
NSData *pngData = [newRep representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
[pngData writeToURL:fileURL atomically:YES];
NSData *jpgData = [newRep representationUsingType:NSBitmapImageFileTypeJPEG
properties:@{NSImageCompressionFactor: @0.5f}];
[jpgData writeToURL:fileURL atomically:YES];
UNNotificationAttachment *icon = [UNNotificationAttachment attachmentWithIdentifier:@"art"
content.attachments = @[icon];
if (error) {
// We have size limit of 10MB per image attachment.
NSLog(@"%@", error.localizedDescription);
} else {
content.attachments = @[icon];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment