Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow post-resize crop #23

Closed
lovell opened this issue Apr 24, 2014 · 16 comments
Closed

Allow post-resize crop #23

lovell opened this issue Apr 24, 2014 · 16 comments
Milestone

Comments

@lovell
Copy link
Owner

lovell commented Apr 24, 2014

As requested by @mcgoooo in #8 (comment):

im really interested in this library, but for one killer feature. the basic needs are the rescrop function found in here.

https://github.com/hacksparrow/node-easyimage

i could try to help, but i can't write c, yet! :D"

@mcgoooo
Copy link

mcgoooo commented Apr 24, 2014

Amazing, thanks @lovell, this library is amazingly faster than imagemagick!!/

@lovell lovell added this to the v0.6.0 milestone May 19, 2014
@tombatossals
Copy link

Hi, this would be a great feature. +1 here.

Thanks for such an awesome library, just tell me if I could help.

@lovell
Copy link
Owner Author

lovell commented Jul 4, 2014

Once any bugs are fixed and support for Streams is added, cropping is the next feature I plan to work on.

Question (for both @tombatossals and @mcgoooo): do you need totally flexibility here or would the gravity-based suggestion of #45 suffice for your needs? If you only require the latter then that might keep the API cleaner (and possibly be quicker/easier to implement).

@tombatossals
Copy link

Hi @lovell, I think the gravity aproximation will be more than sufficient in my case. I plan to generate thumbs (resized and cropped), and there are some cases where the centered crop approximation is a little short, but if we could specify an optional gravity parameter "south", "center", "north" to the crop function we could give more precision to the thumbnailing functionality.

Thanks

@mcgoooo
Copy link

mcgoooo commented Jul 4, 2014

The gravity based one is a good way to go for sure, eventually the option
for the other more custom would be good, we need both cases, but its
definitely a good start with the square as that is most frequent.

I have a feeling with the streams you may be able to chain the operations
and do it yourself?
On 4 Jul 2014 18:23, "David Rubert" notifications@github.com wrote:

Hi @lovell https://github.com/lovell, I think the gravity aproximation
will be more than sufficient in my case. I plan to generate thumbs (resized
and cropped), and there are some cases where the centered crop
approximation is a little short, but if we could specify an optional
gravity parameter "south", "center", "north" to the crop function we could
give more precision to the thumbnailing functionality.

Thanks


Reply to this email directly or view it on GitHub
#23 (comment).

@kszlim
Copy link

kszlim commented Jul 4, 2014

For my usage of your library, it would be really useful to be able to specify an offset so that you can customize a region of the image to crop.

@lerouxb
Copy link

lerouxb commented Jul 24, 2014

Another thing I noticed is that I wanted to crop the image to a specific size before resizing. I only know the image's width, not the height. But let's say the image is 1024x8000 (it is a screenshot of a full web page) and I want to crop the top 1024x768 (the first screenful), then size that cropped area down to 512x384.

@neonerd
Copy link

neonerd commented Jul 29, 2014

+1 for custom crop with the ability to select a region of the image, this would be really useful!

@lovell
Copy link
Owner Author

lovell commented Aug 21, 2014

The ability to specify the gravity of the crop will be available in the forthcoming v0.6.0 of this module. See https://github.com/lovell/sharp#cropgravity for the API additions to support this. This should make @tombatossals happy.

I plan to use this feature request to focus on the ability to extract a region of the image via offsets, both pre-resize and post-resize as this is what most comments here are looking for.

@lovell lovell modified the milestones: v0.6.0, v0.7.0 Aug 21, 2014
@mcgoooo
Copy link

mcgoooo commented Aug 21, 2014

That is amazing news, good work 💃
On 21 Aug 2014 11:30, "Lovell Fuller" notifications@github.com wrote:

The ability to specify the gravity of the crop will be available in the
forthcoming v0.6.0 of this module. See
https://github.com/lovell/sharp#cropgravity for the API additions to
support this. This should make @tombatossals
https://github.com/tombatossals happy.

I plan to use this feature request to focus on the ability to extract a
region of the image via offsets, both pre-resize and post-resize as this is
what most comments here are looking for.


Reply to this email directly or view it on GitHub
#23 (comment).

@lovell
Copy link
Owner Author

lovell commented Aug 25, 2014

Here's a usage example of the API I plan to add to support pre- and post-resize area extraction:

sharp(input)
  .extract(topOffsetPre, leftOffsetPre, widthPre, heightPre)
  .resize(width, height)
  .extract(topOffsetPost, leftOffsetPost, widthPost, heightPost)
  .toFile(output);

If resizing is not required, a simple extraction can be achieved via:

sharp(input)
  .extract(top, left, width, height)
  .toFile(output);

Any comments before I go ahead?

@mcgoooo
Copy link

mcgoooo commented Aug 26, 2014

this looks perfect to me :)

On Mon, Aug 25, 2014 at 9:32 PM, Lovell Fuller notifications@github.com
wrote:

Here's a usage example of the API I plan to add to support pre- and
post-resize area extraction:

sharp(input)
.extract(topOffsetPre, leftOffsetPre, widthPre, heightPre)
.resize(width, height)
.extract(topOffsetPost, leftOffsetPost, widthPost, heightPost)
.toFile(output);

If resizing is not required, a simple extraction can be achieved via:

sharp(input)
.extract(top, left, width, height)
.toFile(output);

Any comments before I go ahead?


Reply to this email directly or view it on GitHub
#23 (comment).

@eschwim
Copy link

eschwim commented Sep 13, 2014

Hi @lovell! Thanks so much for writing sharp! It saved me the agony of having to write my own nginx vips filter module :)

I also wanted to throw my +1 hat into the ring for a sharp custom crop feature! I've got a sharp-based image re-sizing proxy server ready to publish, I just need to be able to crop images. Thanks again!

@lovell
Copy link
Owner Author

lovell commented Oct 7, 2014

Thanks to some sterling work from @brandonaaron the API described by #23 (comment) is now available on the alpha branch.

Please can one (or more) of the participants here check this meets their needs before this is merged to master and released as v0.7.0.

npm install lovell/sharp#alpha

@lovell
Copy link
Owner Author

lovell commented Oct 13, 2014

This feature is now is master.

@lovell
Copy link
Owner Author

lovell commented Oct 17, 2014

This feature is in v0.7.0, now available via npm. Thanks everyone for all the help and suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants