Spectrum

Spectrum

  • About Spectrum
  • Getting Started
  • GitHub

›Using Spectrum

Intro

  • About Spectrum

Getting Started

  • Getting Started on Android
  • Getting Started on iOS
  • Sample Apps

Concepts

  • Supported Image Flows
  • Supported Image Formats

Using Spectrum

  • Transcoding Images for Upload
  • Resizing Images
  • Cropping Images
  • Rotating Images
  • Encoding Images
  • FAQ

Contributing

  • Project Structure
  • Contributing on Android
  • Contributing on iOS

Cropping Images

To crop an image, define a crop requirement in the options' transformations. A crop requirement can be defined in multiple ways:

  • Relatively: Specify relative values which should be evaluated against the image dimensions. Each value starts from the top/left axis. For example, top: 0.25, left: 0.25, bottom: 0.75, right: 0.75 crops the centre of an image.
  • Absolutely: Specify absolute values measured in pixel of the original image. Each value starts from the top/left axis. For example, top: 100, left: 100, bottom: 200, right: 250 crops an image of size 150x100.

Finally, a crop requirement can also be approximate (controlled via mustBeExact) which may in some cases be more efficient.

Code Sample

The following code exactly crops the centre point of the image:

Android

final CropRequirement cropRequirement =
    CropRequirement.makeRelativeToOrigin(
        /* top */ 0.25,
        /* left */ 0.25,
        /* bottom */ 0.75,
        /* right */ 0.75,
        /* mustBeExact */ true);

// Pass crop requirement to the options' transformations

iOS

FSPRelativeToOriginCropRequirement *cropRequirement =
    [FSPRelativeToOriginCropRequirement relativeToOriginCropRequirementWithValues:{
      .top = 0.25f,
      .left = 0.25f,
      .bottom = 0.75f,
      .right = 0.75f,
    } mustBeExact:YES];

// Pass crop requirement to the options' transformations
← Resizing ImagesRotating Images →
  • Code Sample
    • Android
    • iOS
Spectrum
Docs
About SpectrumGetting StartedContributing
Community
FacebookTwitter
Legal
Terms of UseData PolicyCookie Policy
More
GitHubStar
Facebook Open Source
Copyright © 2022 Facebook