Skip to content

Conversation

@tonytw1
Copy link
Member

@tonytw1 tonytw1 commented Jul 27, 2025

What does this change?

Cropping is implemented using libvips.

Aims to only load the image once.
The image processing operations happen in memory rather than forking out to shell commands.

Nudges the Crops.cropType crop file type decision towards a more deterministic set of parameters.

isGraphic decision for crop type is inferred from the number of bands in the source image.
Do not know how to implement this colour depth query in libvibs.

 // val isGraphic = !colourType.matches("True[ ]?Color.*")

IPTC tagging

Moves to to the XMP block with the XMP block been built in memory.

Performance

Some marginal reductions on cropping time and predictable memory use.
These test images can be cropped by a container with 2Gb of memory.

Time for "POST /crops to return after making a fullset of 5:3 full frame crops of various test images.

imagemagick: 
3301x2173 image/jpeg 1324968 : 1290ms
3500x2334 image/jpeg 2492334:  2050ms
4165x3407 image/png 26741926 : 8904ms
8640x5760 image/jpeg 27134591: 5279ms
5000x3333 image/jpeg 8674990: 2521ms

vips:
3301x2173 image/jpeg 1324968 : 1127ms
3500x2334 image/jpeg 2492334 : 1307ms
4165x3407 image/png 26741926 : 5036ms
8640x5760 image/jpeg 27134591 : 4001ms
5000x3333 image/jpeg 8674990 : 1619ms

How should a reviewer test this change?

How can success be measured?

Who should look at this?

Tested? Documented?

  • locally by committer
  • locally by Guardian reviewer
  • on the Guardian's TEST environment
  • relevant documentation added or amended (if needed)

@tonytw1 tonytw1 force-pushed the libvips branch 2 times, most recently from c8f8217 to c96ff82 Compare August 11, 2025 19:06
@tonytw1 tonytw1 force-pushed the libvips branch 4 times, most recently from d296629 to 25c0148 Compare September 28, 2025 10:12
@tonytw1 tonytw1 force-pushed the libvips-cropping branch 2 times, most recently from 5997767 to 7ced3c4 Compare September 28, 2025 11:22
@tonytw1 tonytw1 force-pushed the libvips-cropping branch 6 times, most recently from c916363 to dcd3779 Compare December 30, 2025 11:08
TODO restore this decision.
…n loaded.

So that hasAlpha and colour depth can possibly come from the actual master crop image.
…can be made at a more implementation specific level.
…he number of bands in the image.

image_get_typeof palette as an indication that the image had a palette is another good signal for isGraphic.
format and bands are likely to be required to infer colour depth.
…; leaving more RAM for off heap VIPS operations.

Cropped 20% heap.
…decision based on no icc profile seen.

Nice and clean; cribbed from vips thumbnail source code.
… without relying in strip on save.

Leads to been able to set metadata on crops.
If not removed, orientation will express itself on save if not removed even though it's not in a exif prefixed field.
…on reference into the XMP using IPTC metadata fields.

Explicitly use compact XMP format.
IPTC has moved from the app13 block into XMP.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant