Skip to content

Main content

Random Object-Fit Crop Corpus Generator

Generate image and box sizes with delegated contain/cover geometry and reconstruct source crops from alignment or clamped source focal coordinates.

Loading tool…

Description

Generate image and box sizes with delegated contain/cover geometry and reconstruct source crops from alignment or clamped source focal coordinates.

An interface fixture makes content and state explicit so a consumer can test a rendering or interaction. Literal labels, modeled states, and calculated geometry remain separate from what a browser or assistive technology actually displays or announces.

Generate image and box sizes with delegated contain/cover geometry and reconstruct source crops from alignment or clamped source focal coordinates.

When to use this tool

Use this generator to create reproducible object fit crop corpus cases from the supplied model or bank. Inspect the returned evidence before using cases in a test or exercise.

How to use the tool and how it works

  1. Supply count, imageWidthPx, imageHeightPx, boxWidthPx, boxHeightPx, xPercent, yPercent, positionMode in the field shapes below. Set seed when you need an explicit replay.
  2. Run the tool and correct any input error. For generated controls, distinguish a successful fixture containing an invalid case from failure to generate the fixture.
  3. Read cases. Use the conventions below and keep answer-bearing fields separate when presenting an exercise.

Draw image and box dimensions and compute contain and cover sizes. Treat percentages as alignment or convert a source focal point into clamped alignment, delegate offsets, and return the visible source crop in original-image pixels.1

Delegated operations used for this result: object fit contain letterbox dims; object fit cover scale factor. Their calculation or parsing conventions apply to the corresponding result fields.2, 3

Input fieldMeaning and unitsAccepted input
countRequested count; the mechanics explain whether one draw expands into several returned records.Required. Safe integer; minimum 1; maximum 64.
imageWidthPxImage Width PxRequired. Object; no unknown keys.
imageWidthPx.minimumMinimumRequired. Safe integer; minimum 1.
imageWidthPx.maximumMaximumRequired. Safe integer; minimum 1.
imageHeightPxImage Height PxRequired. Object; no unknown keys.
imageHeightPx.minimumMinimumRequired. Safe integer; minimum 1.
imageHeightPx.maximumMaximumRequired. Safe integer; minimum 1.
boxWidthPxBox Width PxRequired. Object; no unknown keys.
boxWidthPx.minimumMinimumRequired. Safe integer; minimum 1.
boxWidthPx.maximumMaximumRequired. Safe integer; minimum 1.
boxHeightPxBox Height PxRequired. Object; no unknown keys.
boxHeightPx.minimumMinimumRequired. Safe integer; minimum 1.
boxHeightPx.maximumMaximumRequired. Safe integer; minimum 1.
xPercentX PercentRequired. Object; no unknown keys.
xPercent.minimumMinimumRequired. Safe integer; minimum 0; maximum 100.
xPercent.maximumMaximumRequired. Safe integer; minimum 0; maximum 100.
yPercentY PercentRequired. Object; no unknown keys.
yPercent.minimumMinimumRequired. Safe integer; minimum 0; maximum 100.
yPercent.maximumMaximumRequired. Safe integer; minimum 0; maximum 100.
positionModePosition ModeRequired. Text; one of "alignment", "source-focal".
seedOptional numeric seed; takes precedence over context randomness. Without either, use the fixed tool.io default seed.Optional. Safe integer.
Output fieldInterpretationReturned shape
casesCasesRequired. Array of Object; no unknown keys.; minimum items 1; maximum items 64.
cases[].imageWidthPxImage Width PxRequired. Finite number.
cases[].imageHeightPxImage Height PxRequired. Finite number.
cases[].boxWidthPxBox Width PxRequired. Finite number.
cases[].boxHeightPxBox Height PxRequired. Finite number.
cases[].inputXPercentInput XPercentRequired. Finite number.
cases[].inputYPercentInput YPercentRequired. Finite number.
cases[].fitsFitsRequired. Array of Object; no unknown keys.; minimum items 2; maximum items 2.
cases[].fits[].modeModeRequired. Text; one of "contain", "cover".
cases[].fits[].scaleScaleRequired. Finite number.
cases[].fits[].renderedWidthPxRendered Width PxRequired. Finite number.
cases[].fits[].renderedHeightPxRendered Height PxRequired. Finite number.
cases[].fits[].alignmentXPercentAlignment XPercentRequired. Finite number.
cases[].fits[].alignmentYPercentAlignment YPercentRequired. Finite number.
cases[].fits[].offsetXPxOffset XPxRequired. Finite number.
cases[].fits[].offsetYPxOffset YPxRequired. Finite number.
cases[].fits[].sourceCropSource CropRequired. Object; no unknown keys.
cases[].fits[].sourceCrop.xXRequired. Finite number.
cases[].fits[].sourceCrop.yYRequired. Finite number.
cases[].fits[].sourceCrop.widthWidthRequired. Finite number.
cases[].fits[].sourceCrop.heightHeightRequired. Finite number.
randomnessReplay metadata: source is seed or context; seed is the normalized 32-bit seed or null for a context source.Required. Object; no unknown keys.
randomness.seedOptional numeric replay seed; normalization and precedence are explained below.Required. Safe integer. or Null.
randomness.sourceSourceRequired. Text; one of "context", "seed".

An explicit safe-integer seed takes precedence over injected context randomness and is normalized to an unsigned 32-bit integer. With no seed and no context source, replay uses the fixed tool.io default seed. A context source must return finite values from zero inclusive to one exclusive; its advancing state must be retained separately. randomness records the source and normalized seed, or null for context. These generators are not cryptographic random sources.

json
{
  "input": {
    "count": 1,
    "imageWidthPx": {
      "minimum": 400,
      "maximum": 400
    },
    "imageHeightPx": {
      "minimum": 200,
      "maximum": 200
    },
    "boxWidthPx": {
      "minimum": 100,
      "maximum": 100
    },
    "boxHeightPx": {
      "minimum": 100,
      "maximum": 100
    },
    "xPercent": {
      "minimum": 25,
      "maximum": 25
    },
    "yPercent": {
      "minimum": 50,
      "maximum": 50
    },
    "positionMode": "alignment",
    "seed": 42
  },
  "output": {
    "cases": [
      {
        "imageWidthPx": 400,
        "imageHeightPx": 200,
        "boxWidthPx": 100,
        "boxHeightPx": 100,
        "inputXPercent": 25,
        "inputYPercent": 50,
        "fits": [
          {
            "mode": "contain",
            "scale": 0.25,
            "renderedWidthPx": 100,
            "renderedHeightPx": 50,
            "alignmentXPercent": 25,
            "alignmentYPercent": 50,
            "offsetXPx": 0,
            "offsetYPx": 25,
            "sourceCrop": {
              "x": 0,
              "y": 0,
              "width": 400,
              "height": 200
            }
          },
          {
            "mode": "cover",
            "scale": 0.5,
            "renderedWidthPx": 200,
            "renderedHeightPx": 100,
            "alignmentXPercent": 25,
            "alignmentYPercent": 50,
            "offsetXPx": -25,
            "offsetYPx": 0,
            "sourceCrop": {
              "x": 50,
              "y": 0,
              "width": 200,
              "height": 200
            }
          }
        ]
      }
    ],
    "randomness": {
      "seed": 42,
      "source": "seed"
    }
  }
}

Limitations and assumptions

  • Contain can leave empty box space while cover can crop the source. No image is fetched or edited. Focal centering is clamped to feasible alignment and inherits floating-point calculator precision.
  • A replay requires the same complete input and implementation. Randomized construction does not guarantee uniform coverage of every feasible output; finite samples can repeat unless a distinct-selection rule is explicitly stated.
  • The field tables state structural bounds; cross-field constraints and bounded search or output budgets also apply. Unknown keys are rejected where the object contract disallows them. Input errors are distinct from null fields and deliberate invalid controls in a successful output.

Alternative or Complementary methods

For a supplied example, inspect the returned construction or delegated check directly. To evaluate a consumer, also test cases chosen for its own boundaries; a generated finite corpus does not establish exhaustive coverage.

References

  1. Tool behavior and example: Random Object-Fit Crop Corpus Generator — tool.io

  2. Calculation or validation: css/object-fit-contain-letterbox-dims — tool.io

  3. Calculation or validation: css/object-fit-cover-scale-factor — tool.io

Similar or alternative tools