Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
radiopanik
panikweb
Commits
1cb58f08
Commit
1cb58f08
authored
Aug 22, 2013
by
fred
Browse files
fix thumbnailing to non squares
parent
f210ddce
Changes
1
Hide whitespace changes
Inline
Side-by-side
panikweb/paniktags/templatetags/thumbnails.py
View file @
1cb58f08
...
...
@@ -31,11 +31,20 @@ def thumbnail(image, size='100x100'):
if
abs
(
(
1.0
*
x
/
y
)
-
(
1.0
*
image
.
size
[
0
]
/
image
.
size
[
1
])
)
>
0.1
:
# aspect ratio change, crop the image first
if
image
.
size
[
0
]
>
image
.
size
[
1
]:
# landscape
box
=
[
0
,
0
,
int
(
image
.
size
[
1
]
*
(
1.0
*
x
/
y
)),
image
.
size
[
1
]]
box
=
[
0
,
0
,
int
(
image
.
size
[
1
]
*
(
1.0
*
y
/
x
)),
image
.
size
[
1
]]
else
:
box
=
[
0
,
0
,
image
.
size
[
0
],
int
(
image
.
size
[
0
]
*
(
1.0
*
y
/
x
))]
if
box
[
2
]
>
image
.
size
[
0
]:
box
=
[
int
(
t
*
(
1.0
*
image
.
size
[
0
]
/
box
[
2
]))
for
t
in
box
]
if
box
[
3
]
>
image
.
size
[
1
]:
box
=
[
int
(
t
*
(
1.0
*
image
.
size
[
1
]
/
box
[
3
]))
for
t
in
box
]
if
image
.
size
[
0
]
>
image
.
size
[
1
]:
# landscape
box
[
0
]
=
(
image
.
size
[
0
]
-
box
[
2
])
/
2
# keep the middle
else
:
box
=
[
0
,
0
,
image
.
size
[
0
],
int
(
image
.
size
[
0
]
*
(
1.0
*
x
/
y
))]
box
[
1
]
=
(
image
.
size
[
1
]
-
box
[
3
])
/
4
# keep mostly the top
image
=
image
.
crop
(
box
)
image
=
image
.
resize
([
x
,
y
],
Image
.
ANTIALIAS
)
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment