question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resizing and cropping on demand

See original GitHub issue

Hi,

This is more a request for advice than issue, if you can help!

The use case is a UI that allows to load images and zoom in / span across the image. Images can be in different formats (JPG, PNG, TIFF), that can be say from KBs to 1-2GB.

The approach we are following at the moment is to differentiate between big and small images.

For small images, we might not use pyvips at all since it seems that the overhead kills the performance gain.

For big images: we are loading first a low resolution image which we create beforehand. Then upon zooming, we are loading the relevant region that needs zooming (or rather, a slightly larger and high resolution region than needed, to minimise the number of calls made to libvips). For this, we are currently doing something like:

image = pyvips.Image.new_from_file(filename, access='sequential') image = image.crop() out = image.resize() data = out.write_to_buffer('.jpg', Q=quality)

Some questions:

  1. Is this the most efficient way to approach the problem?
  2. Reading through other issues (https://github.com/libvips/pyvips/issues/26) and libvips documentation, I’m thinking that something like the below should instead be quite faster?

im = pyvips.Image.thumbnail(filename, ) im = im.crop() data = im.write_to_buffer('.jpg', Q=quality)

  1. Is it worth to have different approaches depending on the format of the image?
  2. would something like direct access to the relevant region of the image be more efficient? But I could not find much documentation on this

Thanks a lot

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jcupittcommented, Dec 19, 2019

The 2s is for openslide images (up to about 300,000 x 300,000 pixels), it’d be quicker for more normal files.

I made a node binding for libvips:

https://github.com/libvips/node-vips

You could probably write the tile server in that. I did it as an exercise and I don’t know anything about node, so it might need a bit of fixing up. It’s only ~2,000 lines, so it should be easy to work on.

0reactions
drewlrcommented, Dec 19, 2019

Thanks for the pointers @jcupitt !

It’s for a webapp (to be ran either in browser or in an Electron.JS wrapper) that should be able to run locally on Mac/Linux/Windows. We have a React.JS frontend - we need to make the zoom and span experience fast, the specific use case is images annotation for Computer Vision (I guess you must be getting a lot of traffic due to Deep Learning these days! 😃 )

We can’t really create tiles beforehand for all the pictures as that could eat up a lot of disk space.

Waiting ~2s per image when needing to zoom in is not ideal either I guess, but possibly that could work - it would come into play only for big images. We will do some tests on our end using your pointers, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImageBoss | On-demand image processing, resizing ...
Content aware image resizing, cropping, CDN, compression, watermarking and filters. All web development best practices, hassle-free in one simple and powerful ...
Read more >
thumbor - open-source smart on-demand image cropping ...
Thumbor is a smart imaging service. It enables on-demand crop, resizing and flipping of images. It features a very smart detection of important...
Read more >
Image Cropping and Resizing Services
If your images require resizing and cropping, we can provide you fast services. Our expert designer can handle bulk resizing and cropping for...
Read more >
Resizing and cropping your images - Lightspeed eCommerce
Editing the size of your images to match your theme is an important step in creating a professional website. Images that are properly...
Read more >
Resizing and Cropping Images Using IrfanView
Resizing and Cropping Images Using IrfanView · 1. To crop the image, go to the Edit menu. · 2. Choose, Create custom crop...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found