Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
2629698d
Commit
2629698d
authored
Mar 09, 1999
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added JPG size sniffing support.
parent
e85699dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
3 deletions
+27
-3
lib/python/OFS/Image.py
lib/python/OFS/Image.py
+27
-3
No files found.
lib/python/OFS/Image.py
View file @
2629698d
...
...
@@ -102,13 +102,14 @@
##############################################################################
"""Image object"""
__version__
=
'$Revision: 1.5
7
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.5
8
$'
[
11
:
-
2
]
import
Globals
,
string
,
struct
,
mimetypes
,
content_types
from
Globals
import
HTMLFile
,
MessageDialog
from
PropertyManager
import
PropertyManager
from
AccessControl.Role
import
RoleManager
from
SimpleItem
import
Item_w__name__
from
cStringIO
import
StringIO
from
Globals
import
Persistent
from
Acquisition
import
Implicit
from
DateTime
import
DateTime
...
...
@@ -342,16 +343,39 @@ class Image(File):
self
.
content_type
=
content_type
self
.
data
=
Pdata
(
data
)
self
.
size
=
len
(
data
)
# handle GIFs
if
(
self
.
size
>=
10
)
and
self
.
data
[:
6
]
in
(
'GIF87a'
,
'GIF89a'
):
if
(
self
.
size
>=
10
)
and
data
[:
6
]
in
(
'GIF87a'
,
'GIF89a'
):
w
,
h
=
struct
.
unpack
(
"<HH"
,
self
.
data
[
6
:
10
])
self
.
width
=
str
(
int
(
w
))
self
.
height
=
str
(
int
(
h
))
# handle JPEGs
elif
(
self
.
size
>=
2
)
and
(
data
[:
2
]
==
'
\
377
\
330
'
):
jpeg
=
StringIO
(
data
)
jpeg
.
read
(
2
)
b
=
jpeg
.
read
(
1
)
try
:
while
(
b
and
ord
(
b
)
!=
0xDA
):
while
(
ord
(
b
)
!=
0xFF
):
b
=
jpeg
.
read
(
1
)
while
(
ord
(
b
)
==
0xFF
):
b
=
jpeg
.
read
(
1
)
if
(
ord
(
b
)
>=
0xC0
and
ord
(
b
)
<=
0xC3
):
jpeg
.
read
(
3
)
h
,
w
=
struct
.
unpack
(
">HH"
,
jpeg
.
read
(
4
))
break
else
:
jpeg
.
read
(
int
(
struct
.
unpack
(
">H"
,
jpeg
.
read
(
2
))[
0
])
-
2
)
b
=
jpeg
.
read
(
1
)
self
.
width
=
str
(
int
(
w
))
self
.
height
=
str
(
int
(
h
))
except
:
pass
# handle PNGs
if
(
self
.
size
>=
16
)
and
(
self
.
data
[:
8
]
==
'
\
x89
PNG
\
r
\
n
\
x1a
\
n
'
):
el
if
(
self
.
size
>=
16
)
and
(
self
.
data
[:
8
]
==
'
\
x89
PNG
\
r
\
n
\
x1a
\
n
'
):
w
,
h
=
struct
.
unpack
(
">LL"
,
self
.
data
[
8
:
16
])
self
.
width
=
str
(
int
(
w
))
self
.
height
=
str
(
int
(
h
))
def
__str__
(
self
):
width
=
self
.
width
and
(
'width="%s" '
%
self
.
width
)
or
''
...
...
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