Giter VIP home page Giter VIP logo

Comments (5)

jcupitt avatar jcupitt commented on July 19, 2024

Hello, try plain crop. Smartcrop searches the image for features like faces or high-saturation areas and tries to centre the crop on that.

The libvips one is rather like:

https://github.com/jwagner/smartcrop.js

from pyvips.

jcupitt avatar jcupitt commented on July 19, 2024

Crop docs here:

http://jcupitt.github.io/libvips/API/current/libvips-conversion.html#vips-crop

(extract_area is a synonym for crop), or smartcrop docs are here:

http://jcupitt.github.io/libvips/API/current/libvips-conversion.html#vips-smartcrop

from pyvips.

marcrleonard avatar marcrleonard commented on July 19, 2024

Are there python bindings for vips-crop? I don't see them in the docs, nor did it work when I called it as a method.
For a better understanding of my workflow, I need resize, offset, crop, write image - in that order.

image_resize = self.original_image.resize(zoom)
image_offset = image_resize.copy(xoffset = int(x_total), yoffset = int(y_total))
image_vips = image_offset.smartcrop(self.output_raster_width, self.output_raster_height)
data = image_vips.write_to_buffer('.JPEG', Q=95)
image_bytes = PIL.Image.open(io.BytesIO(data))
image_bytes.save(p.stdin, 'JPEG')

So yes I can chain all these methods together, however, since crop is in the middle, I would have to call the pyvips version of it vs the PIL version. Any suggestions on how to improve this order of operations?
Many thanks for the help, John.

from pyvips.

jcupitt avatar jcupitt commented on July 19, 2024

Sure, it should work. I see:

john@kiwi:~/pics$ python
Python 2.7.14 (default, Sep 23 2017, 22:06:14) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> x = pyvips.Image.new_from_file("k2.jpg")
>>> x = x.crop(0, 0, 100, 100)
>>>

Historically, the vips operation was called extract_area, but that caused great confusion since people expect it to be called crop, so crop was added as a synonym. Anyway, either should work and they do the same thing.

Your code should be:

im = pyvips.Image.thumbnail('k2.jpg', 128)
im = im.crop(10, 20, 100, 100)
data = im.write_to_buffer('.jpg', Q=95)
sys.stdout.write(data)

You seem to be saving to stdin, which puzzles me a little. Are you sure you don't mean stdout?

thumbnail is much, much faster than new_from_file plus resize, since it can do tricks like libjpeg shrink-on-load. It also handles transparency correctly, so you get better quality too. It has a number of useful options, see:

http://jcupitt.github.io/libvips/API/current/libvips-resample.html#vips-thumbnail

from pyvips.

jcupitt avatar jcupitt commented on July 19, 2024

I'll close. Please reopen if there is still a problem.

from pyvips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.