FBImageProcessor.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <Foundation/Foundation.h>
  10. #import <CoreGraphics/CoreGraphics.h>
  11. @class UTType;
  12. NS_ASSUME_NONNULL_BEGIN
  13. // Those values define the allowed ranges for the scaling factor and compression quality settings
  14. extern const CGFloat FBMinScalingFactor;
  15. extern const CGFloat FBMaxScalingFactor;
  16. extern const CGFloat FBMinCompressionQuality;
  17. extern const CGFloat FBMaxCompressionQuality;
  18. @interface FBImageProcessor : NSObject
  19. /**
  20. Puts the passed image on the queue and dispatches a scaling operation. If there is already a image on the
  21. queue it will be replaced with the new one
  22. @param image The image to scale down
  23. @param completionHandler called after successfully scaling down an image
  24. @param scalingFactor the scaling factor in range 0.01..1.0. A value of 1.0 won't perform scaling at all
  25. */
  26. - (void)submitImageData:(NSData *)image
  27. scalingFactor:(CGFloat)scalingFactor
  28. completionHandler:(void (^)(NSData *))completionHandler;
  29. /**
  30. Scales and crops the source image
  31. @param image The source image data
  32. @param uti Either UTTypePNG or UTTypeJPEG
  33. @param scalingFactor Scaling factor in range 0.01..1.0. A value of 1.0 won't perform scaling at all
  34. @param compressionQuality the compression quality in range 0.0..1.0 (0.0 for max. compression and 1.0 for lossless compression).
  35. Only works if UTI is set to kUTTypeJPEG
  36. @param error The actual error instance if the returned result is nil
  37. @returns Processed image data compressed according to the given UTI or nil in case of a failure
  38. */
  39. - (nullable NSData *)scaledImageWithData:(NSData *)image
  40. uti:(UTType *)uti
  41. scalingFactor:(CGFloat)scalingFactor
  42. compressionQuality:(CGFloat)compressionQuality
  43. error:(NSError **)error;
  44. @end
  45. NS_ASSUME_NONNULL_END