Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

SpectrumKit not working with screenshot images in iOS 13 #223

@rahulvyas

Description

@rahulvyas

I have following version of spectrum
SpectrumCore (1.1.0)
SpectrumKit (1.1.0)
mozjpeg (3.3.2)
spectrum-folly (2019.01.21.00)

When I try to compress a screenshot I'm getting a plain white image. I'm not getting any error. I'm testing on iPhone XR iOS 13.1.2.

Attaching some input images and some screenshot of what I'm getting as output.

Skype_Picture_2020_09_04T05_51_17_725Z
IMG_1070

I'm not getting any kind of error when compressing these images just plain white image I'm getting

Screenshot 2020-09-04 at 11 10 39 AM
Screenshot 2020-09-04 at 11 11 14 AM

This is my image picking code

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
   NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
   if ([mediaType isEqualToString:@"public.image"]){
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        UIImage *transcoded = [self transcodeImage:image];
   }
}


- (UIImage*)transcodeImage:(UIImage*)image {
    
    FSPSpectrum *spectrum = [[FSPSpectrum alloc] initWithPlugins:@[[FSPJpegPlugin new]]
    configuration:nil];
    
    FSPEncodeRequirement *encodeRequirement =
        [FSPEncodeRequirement encodeRequirementWithFormat:FSPEncodedImageFormat.jpeg
                                                     mode:FSPEncodeRequirementModeLossy
                                                  quality:70];
    
    FSPConfiguration * configuration = [[FSPConfiguration alloc]init];

    FSPTransformations *transformations = [FSPTransformations new];
    transformations.resizeRequirement =
        [[FSPResizeRequirement alloc] initWithMode:FSPResizeRequirementModeExactOrSmaller
                                        targetSize:CGSizeMake(1024, 1024)];

    FSPEncodeOptions *options =
        [FSPEncodeOptions encodeOptionsWithEncodeRequirement:encodeRequirement
                                             transformations:transformations
                                                    metadata:nil
                                               configuration:configuration
                         outputPixelSpecificationRequirement:nil];

    NSError *error;
    FSPResultData *result = [spectrum encodeImage:image options:options error:&error];
    if (result.result.didSucceed && result.data) {
        UIImage* image = [UIImage imageWithData:result.data];
        if (image) {
            return image;
        }
    }
    return image;
}

Does anyone knows any fix. I have to release the app on store and it's the only issue I'm stuck with.

I've tried same images on facebook and these are working perfectly.

Edit : Updating targetSize:CGSizeMake(2048, 2048) in FSPResizeRequirement produces the below image

Screenshot 2020-09-04 at 12 06 37 PM

Edit 2 : Updating targetSize:CGRectZero in FSPResizeRequirement always gives error and I'm not able to compress the image

Here is the error log

Printing description of error:
Error Domain=com.facebook.spectrum Code=255 "(null)" UserInfo={com.facebook.spectrum.error-name=scalingX > 0, com.facebook.spectrum.error-location=facebook::spectrum::core::proc::ScalingBlockImpl::ScalingBlockImpl(const image::pixel::Specification &, const image::Size &, const image::Size &):62}

Edit 3 : Same code works fine in iPhone 6 (iOS 12.4.6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions