Wordpress-Timthumb-alternative icon indicating copy to clipboard operation
Wordpress-Timthumb-alternative copied to clipboard

Allow 'width' or 'height' blank (or '0') values

Open augustoms opened this issue 12 years ago • 11 comments
trafficstars

To allow resize based on one dimension (like WordPress currently works)

augustoms avatar Feb 22 '13 17:02 augustoms

I second that. It would be most helpful as I have just found out that the script currently does not do that. Unfortunately that means it's back to TimThumb for me for now.

bubblun avatar May 17 '13 15:05 bubblun

Well, I haven't tested this but I believe you can already do that.... If for example you want to resize an image based on its height, you can use something like this: height: 300 width: 9999 (just a really high value) crop: false

so basically something like this should do the trick:

<?php matthewruddy_image_resize( $url, 9999, 300, false ); ?>

aristath avatar May 18 '13 11:05 aristath

@aristath I tried the above but the script is actually resizing the image to 9999 x whatever. Can anyone else confirm that the above works?

proframework avatar Jun 06 '13 23:06 proframework

Here's a fork with proportional cropping enabled (when width or height are set to null or false): https://github.com/proframework/Wordpress-Timthumb-alternative/blob/master/resize.php

proframework avatar Jun 08 '13 18:06 proframework

This is an amazing script. Thank you. I also would really like to see this ability. @proframework your fork didn't work for me. I've dived in to trying to tweak it myself with no luck so far. Anyone else get it working?

coryshaw avatar Aug 01 '13 02:08 coryshaw

@coryshaw, the same here. I just copy the code and test (changing, for eg, the height number to false, and a black image appears).

@proframework : I'm doing something wrong? what's the correctly way to use your updated script?

augustoms avatar Aug 29 '13 18:08 augustoms

Hmm, my fork above is working well for me. All I have to do is set the width or height to "false", and proportional sizing will kick in.

So it would be something like this..

https://gist.github.com/proframework/6382826

First we check if width or height is set to false (using a shortcode).

Then we check if the width or height are empty (or false), if so, we turn off cropping.

Then if you do this:

[image width="false" height="300"]

It will resize the image proportionally.

Hope this helps.. Tom

proframework avatar Aug 29 '13 20:08 proframework

Hello @proframework ! Thanks for your attention!

So, I can't understand what I'm doing wrong. Look my steps:

  • include your forked code;
  • in my template file, I call the function like this: $img_des = matthewruddy_image_resize( 'http://www....com/file.jpg', 200, false, true, false ); echo '<img src="'. $img_des['url'].' alt="" />;
  • the result is a black image

I'm running it in a local server (OSX + MAMP).

augustoms avatar Aug 30 '13 00:08 augustoms

Hi there,

Maybe try this..

$img_des = matthewruddy_image_resize( 'http://www....com/file.jpg', 200, false, false ); echo '<img src="'. $img_des['url'].' alt="" />;

proframework avatar Aug 30 '13 00:08 proframework

@proframework ! now it runs! the problem was my function markup! thank you very much!

augustoms avatar Aug 30 '13 01:08 augustoms

Glad I could help :)

proframework avatar Aug 31 '13 00:08 proframework