Hi There,
Sharp is very very good, chainable api, ease to use. Really appreciated for the this great project.
While is it possible to support rotate angles other than 90/180/270/360 ? Cuz i tested that node-easyimage has supported this feature already.
Thanks!
"Unsupported angle: angle must be a positive/negative multiple of 90"
Hello, there has been a previous PR #906 related to this, but it was closed.
Let's use this issue to track your request to expose the vips_affine operation, which provides arbitrary tilt, skew and scale features. A possible API to expose is mentioned in https://github.com/lovell/sharp/pull/906#issuecomment-321075215
The forthcoming libvips v8.7.0 provides a new vips_rotate operation.
Perhaps rather than expose the full affine transformation logic, we could provide what most people seem to need via the existing rotate() operation and it extend it to also accept an angle where angle % 90 != 0.
This would also mean extending the signature to accept an object to pass in an optional background parameter.
rotate() // existing signature, auto-rotate based on EXIF
rotate(angle) // existing signature, default to a black background
rotate({ angle, background })
As always, happy to help with and accept a PR for this.
Any news on this?
Any news on this? Again
vips_rotate will be added in the forthcoming libvips v8.7.0.
I would need the raw vips_affeine functionality in my use case. We're implementing our own internal placeit.net type of service.
libvips v8.7.0 final released! Anything else holding this back? :)
@freezy The forthcoming sharp v0.21.0 will require/depend upon libvips v8.7.0. As I said in https://github.com/lovell/sharp/issues/998#issuecomment-376699203, "happy to help with and accept a PR for this."
I might have a look. However I'm not familiar with the vips API and their documentation seems currently unavailable.
it seems like https://jcupitt.github.io/libvips/ is broken, but https://libvips.github.io/libvips/ works fine, try that one!
libvips moved to a new GitHub org today - we're slowly fixing all the links.
Thanks! Got a first version working, will document and test and submit a PR in the next few days.
@freezy Great, thank you. Please use the teeth branch for features that require libvips v8.7.0.
Yup, noticed. :)
About the API: @lovell proposed an overload of rotate() taking in an object with properties angle and background.
Wouldn't it be simpler to leave it as-is, just add an additional background parameter and vips_rotate when the angle is different than 0, 90, 180 and 270? For example:
rotate() // existing signature, auto-rotate based on EXIF
rotate(90) // existing signature, uses vips_rot
rotate(45, '#ff00ff') // new signature, uses vips_rotate
@freezy Thanks for tackling this. Given that background is optional it should probably be a named parameter.
How about the following:
rotate() // existing signature, auto-rotate based on EXIF
rotate(90) // existing signature, uses vips_rot
rotate(45) // existing signature, uses vips_rotate
rotate(45, { background: '#ff00ff' }) // new signature, uses vips_rotate
Works for me!
So with just handing the angle to vips_rotate it won't change the image's dimensions, i.e. the edges of the image are cut off. Is this intended behavior, or should I look into resizing the image as well?
EDIT: Actually, just needed to rotate after the crop/embed block, since even when not calling any crop/embed API from JavaScript, it seems to crop the image to its original dimensions anyway.
@lovell So when using an RGBA array for the background color, libvips complains:
Error: linear: vector must have 1 or 3 elements
I'm doing the same as you do for embed, passing a 4-dimensional double vector as background parameter. Not setting the alpha channel works. Is this a libvips limitation?
@freezy Is there logic to ensure the channel counts match, e.g. https://github.com/lovell/sharp/blob/master/src/pipeline.cc#L442-L452 ? The error mentions libvips' linear operation - is there also something other than rotation involved in your scenario?
@lovell Yes, actually, I've put that code that is already used twice in the lib into a function (though I haven't replaced the original calls yet). I don't do anything else than rotating.
My alpha function was buggy. I've created #1383 with the correct one. With that, rotation works with transparent background as well. Will clean up stuff, add doc and tests, then you'll get a PR.
Got a PR ready and will submit as soon as #1383 is closed!
Most helpful comment
vips_rotatewill be added in the forthcoming libvips v8.7.0.