Private
Public Access
1
0

Adds support for image previews

Just need to append ?preview=1 to attachment fetch operation.
This commit is contained in:
James Magahern
2022-12-20 16:29:26 -08:00
parent ba8f76f4bd
commit 3082c4ab19
6 changed files with 144 additions and 12 deletions

View File

@@ -0,0 +1,12 @@
//
// MBIMImageUtils.h
// kordophoned
//
// Created by James Magahern on 12/20/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
extern NSData* MBIMCGImageJPEGRepresentation(CGImageRef imageRef);

View File

@@ -0,0 +1,37 @@
//
// MBIMImageUtils.m
// kordophoned
//
// Created by James Magahern on 12/20/22.
// Copyright © 2022 James Magahern. All rights reserved.
//
#import "MBIMImageUtils.h"
#import <ImageIO/ImageIO.h>
NSData* MBIMCGImageJPEGRepresentation(CGImageRef imageRef)
{
if (imageRef == NULL) return nil;
NSNumber *const DPI = @72.0;
NSNumber *const compressionQuality = @0.9;
NSDictionary *properties = @{
(__bridge NSString *)kCGImagePropertyDPIWidth : DPI,
(__bridge NSString *)kCGImagePropertyDPIHeight : DPI,
(__bridge NSString *)kCGImageDestinationLossyCompressionQuality : compressionQuality,
};
bool success = false;
NSMutableData *data = [NSMutableData data];
if (data) {
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData((CFMutableDataRef)data, CFSTR("public.jpeg"), 1/*count*/, NULL/*options*/);
if (imageDestination != NULL) {
CGImageDestinationAddImage(imageDestination, imageRef, (__bridge CFDictionaryRef)properties);
success = CGImageDestinationFinalize(imageDestination);
CFRelease(imageDestination);
}
}
return success ? data : nil;
}