llocally / timthumb

Automatically exported from code.google.com/p/timthumb
0 stars 0 forks source link

Proposed code updates #165

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hey.  Thanks for timthumb!  Not sure if this is the way to propose a change... 
sorry if I should have contacted you in another way.

1) ...was looking to crop without scale. The wiki 
(http://code.google.com/p/timthumb/wiki/Wishlist) says this wish was granted, 
but it doesn't seem to be an option in r130.

2) Also noticed a request to allow user to specify alignment position (as 
percentage, but I implemented as xy coordinates for my needs).

3) finally, alignment had a bug because the switch statement would, for 
example, "break" on the first "tl" match (setting alignment to the top) and 
never hit the switch code to set alignment to the left.

I've attached my updated version of timthumb.php.  Please diff to see my 
updates.

Thanks,
Kory

Original issue reported on code.google.com by kory.pau...@gmail.com on 24 Feb 2011 at 1:58

Attachments:

GoogleCodeExporter commented 9 years ago
Sorry, I entered this as a defect rather than an enhancement... oops...

So, last night I got to thinking... and, rather than have the zc parameter have 
yet another specific value to do something special (in my case, 4) I decided to 
modify it a bit.  Update attached.

1) Now it detects if zc was specified as a percentage.  0% does no 
scaling--just crops to the specified dimensions. 100% scales completely to the 
new dimensions ... maybe that seems backwards... maybe 100% should leave the 
image at 100% size (no scaling) and 0% could be the new dimensions...!?  I 
dunno... you can decide what makes sense if you want to implement this.  And, 
of course, anything between 0% - 100% can be specified.  ... in my case I 
wanted to zoom in slightly and crop around a specific area of the image.

2) Also, since the zoom % changes how much of the original image fits within 
the new dimension, my change to allow for specification of the top-left 
coordinate for the alignment wasn't working quite right for me.  So I made 
coordinate-specified alignment represent the center location--where the 
zoom/crop should focus.

Original comment by kory.pau...@gmail.com on 24 Feb 2011 at 7:21

Attachments:

GoogleCodeExporter commented 9 years ago
ok ok ok ...

The
 - alignment switch-block bugfix for r130; and
 - the new, alignment-specified-as-coordinates feature
are still in there...
But the zoom implementation from my last post was pretty awkward!
Now:
  1) zc that is specified as a % just resizes the source image--100% means no scaling, 200% makes the source image twice as big, 50% half... etc.  Crop position is determined by new height & width and alignment.  Ex (zooms out to 80% the original size and focuses the center of the new image on pixel 100x50 of the original image):
    ?src=[img]&w=200&h=150&zc=80%&a=100,50
  2) I also made it so zc can be specified as width X height, which just specifies the size of the source rectangle that will be squezed/expanded into the new width & height.  Ex (stretches & zooms in on a 20x20 block at the bottom-right of the image):
    ?src=[img]&w=200&h=100&zc=20x20&a=br

- Kory

Original comment by kory.pau...@gmail.com on 4 Mar 2011 at 3:07

Attachments:

GoogleCodeExporter commented 9 years ago
oh... merged with r131!

Original comment by kory.pau...@gmail.com on 4 Mar 2011 at 3:35

Attachments:

GoogleCodeExporter commented 9 years ago
Here's an example of the alignment switch-block bug I mentioned in #3 of my 1st 
post and bullet #1 of my 3rd post...

This should align to the bottom-right but it only aligns to the bottom because 
the switch breaks before it gets to the block with the $src_x definition:
http://www.binarymoon.co.uk/demo/timthumb-basic/timthumb.php?src=castle1.jpg&w=1
00&h=200&a=br

Original comment by kory.pau...@gmail.com on 4 Mar 2011 at 3:40

GoogleCodeExporter commented 9 years ago
very handy mods there, thank you very much

Original comment by dziki...@gmail.com on 25 Aug 2011 at 10:23

GoogleCodeExporter commented 9 years ago
Hi,

How can i make timthumb to crop by top 100px? (left, right, bottom...?)

Original comment by amthucgi...@gmail.com on 17 May 2013 at 6:45