I changed the block of code to look like this:
if (maxPixelSize != -1) {
originalImage =
CGImageSourceCreateThumbnailAtIndex(source, 0, (CFDictionaryRef)thumbnailOpts);
NSInteger oWidth =
CGImageGetWidth(originalImage);
NSInteger oHeight =
CGImageGetHeight(originalImage);
if (_resizeWidth > _resizeHeight) {
if (oHeight > oWidth) {
maxPixelSize = (oHeight *
maxPixelSize) / oWidth;
}
} else {
if (oWidth > oHeight) {
maxPixelSize = (oWidth *
maxPixelSize) / oHeight;
}
}
[thumbnailOpts setObject:[NSNumber
numberWithInt:maxPixelSize] forKey:(id)kCGImageSourceThumbnailMaxPixelSize];
originalImage =
CGImageSourceCreateThumbnailAtIndex(source, 0, (CFDictionaryRef)thumbnailOpts);
}
I got rid of the BOOL variable and added the check for if width is greater but
the picture is vertically oriented. I tested (briefly) the four possibilities
and saw the result I expected.
Best,
Johnny
On Oct 30, 2010, at 9:49 AM, Johnny Miller wrote:
> OK,
>
> Here is a screen a shot of the build settings I used to get it work. I'm on
> a MacPro running 10.6
>
> <Screen shot 2010-10-30 at 9.44.41 AM.png>
>
>
> Here are the changes I made to ImageIOImageProcessorjnilib.m
>
> // Added a boolean
> BOOL maxPixelSizeByWidth = TRUE;
> if (source != nil) {
> int maxPixelSize;
> if (_resizeWidth == -1 && _resizeHeight == -1) {
> maxPixelSize = -1;
> }
> else if (_resizeWidth > _resizeHeight) {
> maxPixelSize = _resizeWidth;
> }
> else {
> // set it to false
> maxPixelSizeByWidth = FALSE;
> maxPixelSize = _resizeHeight;
> }
>
> CGImageRef originalImage;
> NSMutableDictionary *thumbnailOpts =
> [NSMutableDictionary dictionary];
> [thumbnailOpts setObject:(id)kCFBooleanTrue
> forKey:(id)kCGImageSourceCreateThumbnailWithTransform];
> [thumbnailOpts setObject:(id)kCFBooleanTrue
> forKey:(id)kCGImageSourceCreateThumbnailFromImageAlways];
> if (_dpi != -1) {
> NSNumber *dpiNumber = [NSNumber
> numberWithInt:_dpi];
> [thumbnailOpts setObject:dpiNumber
> forKey:(id)kCGImagePropertyDPIWidth];
> [thumbnailOpts setObject:dpiNumber
> forKey:(id)kCGImagePropertyDPIHeight];
> }
>
> if (maxPixelSize != -1) {
> if (! maxPixelSizeByWidth) {
> // logic used to calculate the actual
> max pixel size.
> originalImage =
> CGImageSourceCreateThumbnailAtIndex(source, 0,
> (CFDictionaryRef)thumbnailOpts);
> NSInteger oWidth =
> CGImageGetWidth(originalImage);
> NSInteger oHeight =
> CGImageGetHeight(originalImage);
> if (oWidth > oHeight) {
> maxPixelSize = (oWidth *
> maxPixelSize) / oHeight;
> }
> }
>
> [thumbnailOpts setObject:[NSNumber
> numberWithInt:maxPixelSize] forKey:(id)kCGImageSourceThumbnailMaxPixelSize];
> originalImage =
> CGImageSourceCreateThumbnailAtIndex(source, 0,
> (CFDictionaryRef)thumbnailOpts);
> }
>
>
> There is a whole in my logic - I need to figure out what to do if width is
> set but not the height and the image has a vertical orientation.
>
> best,
>
> Johnny
>
>
> On Oct 29, 2010, at 2:19 PM, Mike Schrag wrote:
>
>> i seem to recall it tries to fit he image into a 90x90 square? it's a bit of
>> a blur
>>
>> On Oct 29, 2010, at 5:09 PM, Johnny Miller wrote:
>>
>>> Hi,
>>>
>>> I'm using ERAttachment + JNI and I want an image upload to be auto scaled
>>> so that it's max height is X. The width is not a concern.
>>>
>>> So I set the following in my properties file (per
>>> http://webobjects.mdimension.com/hudson/job/Wonder53/javadoc/er/attachment/package-summary.html)
>>>
>>> er.attachment.MyEntity.MyAttachmentRelationship.height=90
>>>
>>> But when the image is scaled it sets the width to 90 and the height to
>>> something less. Is there a configuration that I'm missing? i.e.
>>>
>>> er.attachment.MyEntity.MyAttachmentRelationship.width=auto
>>>
>>>
>>> TIA,
>>>
>>> Johnny Miller
>>> Kahalawai Media Corp
>>> http://www.kahalawai.com
>>>
>>>
>>>
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list ([email protected])
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com
>>>
>>> This email sent to [email protected]
>>
>
> Johnny Miller
> Kahalawai Media Corp
> http://www.kahalawai.com
>
>
>
Johnny Miller
Kahalawai Media Corp
http://www.kahalawai.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]