Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Thumbnail Logic

Name: Anonymous 2011-12-21 7:31

Hi there /prog/

I'm currently trying to improve my image resizing algorithm.  First, I re-size the picture's height and width by 50%.  If the new width and height is > max_width and max_height, I set the thumbnail's width to max_width and the height to max_height.

Obviously this will create very poor quality thumbnails of my images.

What could I do to improve this process?

Name: Anonymous 2011-12-21 7:32

>>1
Whoops, I meant to say "will occasionally create poor quality thumbnails."

Name: Anonymous 2011-12-21 8:16

Nice try, Leah.

Name: Anonymous 2011-12-21 8:21

what language?

Name: Anonymous 2011-12-21 8:22

is the max_width and max_height the same number?

Name: Anonymous 2011-12-21 8:55

Divide the image's width by its height to get the aspect ratio. If this number is less than the aspect ratio of your maximum dimensions, divide 1 by it and swap width and height in the rest of this algorithm. Multiply your maximum width with this ratio to get the new height. Resize the image to the maximum height and the new width.

Name: Anonymous 2011-12-21 9:03

>>6
s/less than/greater than/

Name: Anonymous 2011-12-21 9:04

>>6

write that out in an equation

Name: Anonymous 2011-12-21 9:06

Goddamn.

>>6
s/maximum height and new width/maximum width and new height/

Name: Anonymous 2011-12-21 9:09

>>9
s?

Name: Anonymous 2011-12-21 9:11

>>8
Pseudocode ok?

image_ratio = image_width / image_height
max_ratio = max_width / max_height

if image_ratio < max_ratio
    resize image to width = max_width and height = max_width * image_ratio
else
    resize image to height = max_height and width = max_height * image_ratio^-1

Name: Anonymous 2011-12-21 9:11

Name: Anonymous 2011-12-21 9:16

>>10
Get out!

Name: Anonymous 2011-12-21 9:16

>>11
not OP, but testing this

Name: Anonymous 2011-12-21 9:20

>>11
just tested your code with this
Width=450
Height=300
max_width=100
max_height=50
image_ratio=1.5
max_ratio=2

1.5<2 so
width=100
and
height=100*1.5 = 150

The new height is greater than the max_height.
doesnt work

Name: Anonymous 2011-12-21 9:21

>>13
I don't use linux. I typically have work to do.

Name: Anonymous 2011-12-21 9:26

>>15
Yea, just discovered this, swap width and height in the calculation of the ratios.

Name: Anonymous 2011-12-21 9:33

>>17,15

; max_width = 100
; max_height = 50
; image_width = 450
; image_height = 300
; max_ratio = max_height / max_width; max_ratio # height and width swapped
    0.5
; image_ratio = image_height / image_width; image_ratio
    ~0.66666666666666666667
; # 0.667 > 0.5 so height = max_height and width =
; max_height * image_ratio^-1
    75
; # 75 < max_width

Name: Anonymous 2011-12-21 9:35

>>18
Also, 50/75 = ~0.667, so the thumbnail has the same ratio as the original image.

Name: Anonymous 2011-12-21 9:38

>>18
>>19
nice work bro. Too bad OP is probably gone.
will be storing this for future reference though.

Name: Anonymous 2011-12-21 9:38

>>16
You may think that I have been trolled but I am impervious to your mac crap!

Name: Anonymous 2011-12-21 9:51

>lol

Name: Anonymous 2011-12-21 14:12

>>18
lol bitch, you stole my idea using `;` as indentation! I hate you!

Name: >>1323467077 2011-12-21 14:53

>>23
Actually, that's my idea.

Name: Anonymous 2011-12-21 15:03

>>24
burn in hell, thief.

Name: Anonymous 2011-12-21 15:14

>>23,24,25
WTF?

uiueo@eee ~ $ calc
C-style arbitrary precision calculator (version 2.12.1.5)
Calc is open software. For license details type:  help copyright
[Type "exit" to exit, or "help" for help.]

; x = 2 + 2; x
    4
;

Name: Anonymous 2011-12-21 15:26

>>25
The proprietary ``;'' format of indentation is my patent. Go away.

Name: Anonymous 2011-12-21 16:07

>>27
*``;    ''

Name: Anonymous 2011-12-21 18:14

The best way is to resize thumbnails squarely.


void compute_thumb_size(unsigned int width, unsigned int height,
 unsigned int thumb_size, unsigned int *new_width, unsigned int *new_height) {
 if(width > height && width > thumb_size) {
  *new_width = thumb_size;
  *new_height = height * thumb_size / width;
 } else if (height > thumb_thumb_size
  *new_width = height * thumb_size / width;
  *new_height = thumb_size;
 } else {
  *new_width = width;
  *new_height = height;
 }
}

Name: Anonymous 2011-12-21 18:26

It is easily seen that the only numbers between 0 and 2, including 0 but excluding 2, are 0 and 1. Thus the remainder left by any number on division by 2 is either 0 or 1. Hence the quotient ring Z/2Z, where 2Z is the ideal in Z generated by 2, has only the elements [0] and [1], where these are the images of 0 and 1 under the canonical quotient map. Since [1] must be the unit of this ring, every element of this ring except [0] is a unit, and the ring is a field

Don't change these.
Name: Email:
Entire Thread Thread List