syamilmj / Aqua-Resizer

Resize WordPress images on the fly
502 stars 205 forks source link

Allowing to crop to larger image size than the original image #24

Closed mxmzb closed 11 years ago

mxmzb commented 11 years ago

Sometimes you want to make it "just work" for the end user and not to bother them about the image size or similar. So I've built in the ability to upscale images (only if $upscale is set to true, otherwise the script won't change in behavior).

syamilmj commented 11 years ago

Since the scaling occurs in another separate function, is it possible that we just provide a filter to hook with? Authors can then just use this hook to apply the upscaling if they need it.

You can, of course, provide a little tutorial on how to use the hook & the scaling function this on our wiki :)

Cheers

mxmzb commented 11 years ago

Well. The point is, that you have to hook in the image_resize_dimensions() function anyway, which is WP native. So, the only workaround outside aq_resize() would just be to wrap the filters (see my commit, where I added the filter really at the beginning and removed it when almost everthing is done) before and after every use of aq_resize() (or alternatively add the filter and do not remove it, but this would mean to sabotage the WP concept at this point for all cases).

As it would be nerve-stretching to wrap aq_resize() at each use where you need that I would recommend to write another function to wrap aq_resize(), but all these approaches seem to me really bloated and unhandy. Additionally, I personally would expect from a resize function to have the ability to scale up (such as timthumb does, btw, which was in some way the initiator of Aqua-Resizer, wasn't it? ;) ).

And last but not least: Who reads any wikis? :dancer: :D

syamilmj commented 11 years ago

Valid points ;)

Actually, I've been tinkering on converting the function into a class instead, so that adding additional functionality (just like your case above) would have been more intuitive and less intrusive, but that'd make the script incorrectly labeled as "simple".

I'll sleep over this :)

Cheers

mxmzb commented 11 years ago

I just was about to propose this, but I'm right now really under time pressure, so it would have to wait. Also, this would not mean that the script would become more complex. You could simply write a class and wrap the handling of it into the aq_resize() function which it is now, simply as a wrapper. No problem at all. :+1:

mxmzb commented 11 years ago

PS.: Oh, and when I say "it would have to wait" I mean this of course that I can't do that in the near future, you could ;) But as long I think it's not that bad to have two functions, as the one is still not for the developer using the script and the other didn't change that much. The prefix may work for transition time.

syamilmj commented 11 years ago

I'm going to just go ahead and merge this one. I feel like doing a disservice to the community if I keep holding pull requests to let the script evolve naturally.

Like you said, the class/wrapper could wait! :)

Cheers!

mxmzb commented 11 years ago

Great thing, man! Thank you :) I'm also going to update the readme and wiki a little bit next days :)

syamilmj commented 11 years ago

Cool! I just added you to the collaborators list so you can freely push/merge/edit in the future :)

Cheers

mxmzb commented 11 years ago

Yeah, thanks. Appreciate it! :) Btw. as I see that your content builder has even much more potential ;)

mdmoore commented 11 years ago

I see that upscale was merged but I cant find how to use it in the wiki? The problem im having is if the uploaded image is smaller than the size set in aqua resizer, no image is shown. Does upscale solve that problem? I think I would rather have a stretched image then nothing at all.

senlin commented 11 years ago

same problem here, how to get this to work exactly?

mdmoore commented 11 years ago

@senlin I couldn't find a way to pass add upscale = true to the aq_resize function so I just edited aq_resizer.php so that $upscale = true. This means that upscale will always be true, but for my case thats what I need anyways. Line 24, first line of code.

senlin commented 11 years ago

@imikedesigns hahaha, we came to the same conclusion :) thanks for confirming that this is the way to do it!

mxmzb commented 11 years ago

Well, upscaling works only if You have the $crop option set to true, too. If $crop is set to false, upscaling would basically resizing, which means it's the same as giving a 100x100 pixel image a 200px width and 200px height with CSS or HTML attributes (<img src="http://example.com/path-to-my-100px-100px-img" alt="" width="200" height="200" />).

PS.: Just have seen that setting the $upscale default to true has solved it for You. I'm somehow not aware how this could even fix that. Are You sure the value You passed to the function was true and on the correct parameter position? o.O

senlin commented 11 years ago

in my case $crop is indeed set to true, so maybe that's why it works "out of the box". Definitely good to know that it only works in this way!