0

I was wondering if there is an api call that lets me resize an image and respect the aspect ratio. Right now I am using image_resize to successfully resize an image to a given width and height but it ignores aspect ratio and distorts the images. Is there an api call that will allow me to do this and maintain original aspect ratio?

  • 1
    Do you explain the situation for needing to resize images on save rather than using image styles to resize on display? – mpdonadio May 24 '12 at 13:04
  • @MPD. Yes that is a good point. Your method is what was suggested to me by a coworker, I just thought it would be simpler to resize it when saved opposed to having it themed each time it is outputted. I am going to go with your way though, ty – dm03514 May 24 '12 at 13:18
  • 1
    The image won't be rescaled each time it gets viewed. The derivative image gets saved to the filesystem for future use. Bypassing the theme system generally causes problems at some point in the future. – mpdonadio May 24 '12 at 13:22
1

image_scale() will do this if you just provide a width or a height rather than both.

| improve this answer | |
1

This is again a case where using code seems to only come up for the sake of it. This doesn't even involve the use of a module : everything needed is in core and manageable via the UI :

Go to admin/config/media/image-styles/list (provided the Image module is enabled), choose a style or create one and you can then use it in Views or in admin/structure/types/manage/your_ct/display.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.