Last active
August 29, 2015 14:23
-
-
Save sam/d2fe7b46c45322ef4838 to your computer and use it in GitHub Desktop.
Chris Campbell's method of resizing an image while retaining quality (employed in ImgScalr).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def resize(current: Long, target: Long, iteration: Long = 1): Unit = { | |
val step = Math.max(current - (current / 7), target) | |
printf("[%04d] RESIZE FROM %d TO %d\n", iteration, current, step) | |
if(step > target) | |
resize(step, target, iteration + 1) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> resize(5000,180) | |
[0001] RESIZE FROM 5000 TO 4286 | |
[0002] RESIZE FROM 4286 TO 3674 | |
[0003] RESIZE FROM 3674 TO 3150 | |
[0004] RESIZE FROM 3150 TO 2700 | |
[0005] RESIZE FROM 2700 TO 2315 | |
[0006] RESIZE FROM 2315 TO 1985 | |
[0007] RESIZE FROM 1985 TO 1702 | |
[0008] RESIZE FROM 1702 TO 1459 | |
[0009] RESIZE FROM 1459 TO 1251 | |
[0010] RESIZE FROM 1251 TO 1073 | |
[0011] RESIZE FROM 1073 TO 920 | |
[0012] RESIZE FROM 920 TO 789 | |
[0013] RESIZE FROM 789 TO 677 | |
[0014] RESIZE FROM 677 TO 581 | |
[0015] RESIZE FROM 581 TO 498 | |
[0016] RESIZE FROM 498 TO 427 | |
[0017] RESIZE FROM 427 TO 366 | |
[0018] RESIZE FROM 366 TO 314 | |
[0019] RESIZE FROM 314 TO 270 | |
[0020] RESIZE FROM 270 TO 232 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment