Search code examples
phpsmartyimage-scalingimage-size

Resizing images in smarty?


In smarty there is the imagesize function which you can pass it a height and a width and it will scale it down until the first dimension property is meet.

E.g. if you have an image that is 5000x3000

and you pass the function width=500 height=150

you will end up with an image that is 500x300

You can also pass the function crop=true and it will crop the image at the dimension that does not fit to make it fit the dimensions, but that cuts off part of the image.

I am wondering if there is a way to make it scale the image down until both dimensions are met, It then fills the remaining area with a transparent background centering the image.

so you would end up with your actual image scaling down to 350x150 it would then fill the left and right with 75 pixels of transparency so your whole file is 500x150

if an image is passed that is smaller than the given dimensions the same process would take place with the transparent pixels filling in the remaining space.

Does smarty have this ability? or is there a way to make it work?


Solution

  • No, there is no such function.

    The only function there is, is html_image, which will automatically insert width and height to the img-tag depending on the actual image size.

    But none the other way around.

    You can however write your own plugin, which could give smarty the ability to scale images.