Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
augustoms opened this issue Feb 22, 2013 · 11 comments
Open

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

augustoms opened this issue Feb 22, 2013 · 11 comments

Comments

@augustoms
Copy link

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

@bubblun
Copy link

bubblun commented May 17, 2013

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.

@aristath
Copy link

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 ); ?>

@proframework
Copy link

@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
Copy link

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

@coryshaw
Copy link

coryshaw commented Aug 1, 2013

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?

@augustoms
Copy link
Author

@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?

@proframework
Copy link

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

@augustoms
Copy link
Author

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).

@proframework
Copy link

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="" />;

@augustoms
Copy link
Author

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

@proframework
Copy link

Glad I could help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants