Say I had an image which is 200x200, is it possible to resize it to be 500x500 but not upscale the image only pad it. I have tried a few things but couldn't seem to get it to work it either didn't resize to be 500x500 or it would upscale the image (stretch).
I'm afraid not out of the box. ImageProcessor.Web handles only one resize instruction per request.
You could however extend the solution by creating your own IWebGraphicsProcessor called Pad which would do it. There's tons of example code on GitHub to show you how this works.
Maybe you could contribute that back to the core if you took that approach. :)
I've modified the source of ImageProcessor now so it behaves how I mentioned above. Would be cool to run it passed you, if you fancied it (see if it's worthy of going back into the core after some tidying up :) )?
I didn't take the route of creating my own IWebGraphicsProcessor, instead I ended up editing the Resizer class and used the upscale flag to decide whether the source image should be resized or just the canvas when using ResizeMode.Pad. This seemed like the correct way to me (settings wise). Apologies if it is wrong, happy to hear your feedback if so :)
Have you had a chance to have a look at my change yet? Would love to get this functionality in image processor some way or other :) happy to relook at it if you don't think Ive gone about it in the best way or if it causes a breaking change.
Changing the behaviour of upscale will cause a breaking change so I'll have to approach it differently. I'm thinking of adding an additional value to the ResizeMode enum - BoxPad or something and setting the logic like that. Keep your code online please so I can steal what maths you've done.
Resize pad with max image size
Hey,
Say I had an image which is 200x200, is it possible to resize it to be 500x500 but not upscale the image only pad it. I have tried a few things but couldn't seem to get it to work it either didn't resize to be 500x500 or it would upscale the image (stretch).
This is an example of two things I've tried:
5069a.jpg?mode=pad&width=500&height=500&anchor=top&bgcolor=fff
?mode=pad&width=500&height=500&anchor=top&bgcolor=fff&upscale=false
Cheers :)
Tom
Hi Tom.
I'm afraid not out of the box. ImageProcessor.Web handles only one resize instruction per request.
You could however extend the solution by creating your own
IWebGraphicsProcessor
called Pad which would do it. There's tons of example code on GitHub to show you how this works.Maybe you could contribute that back to the core if you took that approach. :)
Hope that helps.
James
Hey James,
Thank you for getting back to me :)
I've modified the source of ImageProcessor now so it behaves how I mentioned above. Would be cool to run it passed you, if you fancied it (see if it's worthy of going back into the core after some tidying up :) )?
Cheers,
Tom
Hi Tom,
Yeah, I'd absolutely love to look at your code. Is it in a fork on Github?
Cheers
James
Hey James,
Yeah you can find it here:
https://github.com/TomSteer/ImageProcessor
I didn't take the route of creating my own
IWebGraphicsProcessor
, instead I ended up editing theResizer
class and used the upscale flag to decide whether the source image should be resized or just the canvas when usingResizeMode.Pad
. This seemed like the correct way to me (settings wise). Apologies if it is wrong, happy to hear your feedback if so :)Many Thanks,
Tom
Hey James,
Have you had a chance to have a look at my change yet? Would love to get this functionality in image processor some way or other :) happy to relook at it if you don't think Ive gone about it in the best way or if it causes a breaking change.
Cheers,
Tom
Hi Tom, sorry for not getting back sooner.
Changing the behaviour of upscale will cause a breaking change so I'll have to approach it differently. I'm thinking of adding an additional value to the ResizeMode enum - BoxPad or something and setting the logic like that. Keep your code online please so I can steal what maths you've done.
Cheers!
James
Just a heads up, the next release will have BoxPad. :)
Awesome! Nice one James :)
is working on a reply...