Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
cda19eeb
Commit
cda19eeb
authored
Feb 01, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
safeimage: py3
parent
0b4d19f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
25 deletions
+22
-25
bt5/erp5_safeimage/ExtensionTemplateItem/portal_components/extension.erp5.ERP5ZoomifyImage.py
...Item/portal_components/extension.erp5.ERP5ZoomifyImage.py
+22
-25
No files found.
bt5/erp5_safeimage/ExtensionTemplateItem/portal_components/extension.erp5.ERP5ZoomifyImage.py
View file @
cda19eeb
...
...
@@ -16,9 +16,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from
__future__
import
print_function
import
io
import
os
,
sys
,
shutil
,
tempfile
from
six.moves
import
cStringIO
as
StringIO
from
zLOG
import
LOG
,
ERROR
,
INFO
,
WARNING
from
OFS.Image
import
File
,
Image
import
os
,
transaction
...
...
@@ -44,7 +43,7 @@ class ZoomifyBase:
_v_tileGroupMappings
=
{}
qualitySetting
=
80
tileSize
=
256
my_file
=
String
IO
()
my_file
=
io
.
Bytes
IO
()
def
openImage
(
self
):
""" load the image data """
...
...
@@ -62,15 +61,15 @@ class ZoomifyBase:
width
,
height
=
(
self
.
originalWidth
,
self
.
originalHeight
)
self
.
_v_scaleInfo
=
[(
width
,
height
)]
while
(
width
>
self
.
tileSize
)
or
(
height
>
self
.
tileSize
):
width
,
height
=
(
width
/
2
,
height
/
2
)
width
,
height
=
(
width
/
/
2
,
height
/
/
2
)
self
.
_v_scaleInfo
.
insert
(
0
,
(
width
,
height
))
totalTiles
=
0
tier
,
rows
,
columns
=
(
0
,
0
,
0
)
for
tierInfo
in
self
.
_v_scaleInfo
:
rows
=
height
/
self
.
tileSize
rows
=
height
//
self
.
tileSize
if
height
%
self
.
tileSize
>
0
:
rows
+=
1
columns
=
width
/
self
.
tileSize
columns
=
width
//
self
.
tileSize
if
width
%
self
.
tileSize
>
0
:
columns
+=
1
totalTiles
+=
rows
*
columns
...
...
@@ -87,7 +86,7 @@ class ZoomifyBase:
width
,
height
=
(
self
.
originalWidth
,
self
.
originalHeight
)
self
.
_v_scaleInfo
=
[(
width
,
height
)]
while
(
width
>
self
.
tileSize
)
or
(
height
>
self
.
tileSize
):
width
,
height
=
(
width
/
2
,
height
/
2
)
width
,
height
=
(
width
/
/
2
,
height
/
/
2
)
self
.
_v_scaleInfo
.
insert
(
0
,
(
width
,
height
))
# tile and tile group information
self
.
preProcess
()
...
...
@@ -146,7 +145,7 @@ class ZoomifyBase:
xmlOutput
=
'<IMAGE_PROPERTIES WIDTH="%s" HEIGHT="%s" NUMTILES="%s" NUMIMAGES="1" VERSION="1.8" TILESIZE="%s" />'
xmlOutput
=
xmlOutput
%
(
str
(
self
.
originalWidth
),
str
(
self
.
originalHeight
),
str
(
numberOfTiles
),
str
(
self
.
tileSize
))
return
xmlOutput
return
xmlOutput
.
encode
()
def
saveXMLOutput
(
self
):
""" save xml metadata about the tiles """
...
...
@@ -176,15 +175,14 @@ class ZoomifyBase:
lr_y
=
ul_y
+
self
.
tileSize
else
:
lr_y
=
self
.
originalHeight
print
(
"Going to open image"
)
imageRow
=
image
.
crop
([
0
,
ul_y
,
self
.
originalWidth
,
lr_y
])
saveFilename
=
root
+
str
(
tier
)
+
'-'
+
str
(
row
)
+
ext
if
imageRow
.
mode
!=
'RGB'
:
imageRow
=
imageRow
.
convert
(
'RGB'
)
imageRow
.
save
(
os
.
path
.
join
(
tempfile
.
gettempdir
(),
saveFilename
),
'JPEG'
,
quality
=
100
)
print
(
"os path exist : %r"
%
os
.
path
.
exists
(
os
.
path
.
join
(
tempfile
.
gettempdir
(),
saveFilename
))
)
# see https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#jpeg-saving
# for quality, Values above 95 should be avoided;
'JPEG'
,
quality
=
95
)
if
os
.
path
.
exists
(
os
.
path
.
join
(
tempfile
.
gettempdir
(),
saveFilename
)):
self
.
processRowImage
(
tier
=
tier
,
row
=
row
)
row
+=
1
...
...
@@ -192,9 +190,8 @@ class ZoomifyBase:
def
processRowImage
(
self
,
tier
=
0
,
row
=
0
):
""" for an image, create and save tiles """
print
(
'*** processing tier: '
+
str
(
tier
)
+
' row: '
+
str
(
row
))
tierWidth
,
tierHeight
=
self
.
_v_scaleInfo
[
tier
]
rowsForTier
=
tierHeight
/
self
.
tileSize
rowsForTier
=
tierHeight
//
self
.
tileSize
if
tierHeight
%
self
.
tileSize
>
0
:
rowsForTier
+=
1
root
,
ext
=
os
.
path
.
splitext
(
self
.
_v_imageFilename
)
...
...
@@ -261,7 +258,7 @@ class ZoomifyBase:
# a bug was discovered when a row was exactly 1 pixel in height
# this extra checking accounts for that
if
imageHeight
>
1
:
tempImage
=
imageRow
.
resize
((
imageWidth
/
2
,
imageHeight
/
2
),
tempImage
=
imageRow
.
resize
((
imageWidth
/
/
2
,
imageHeight
/
/
2
),
PIL_Image
.
ANTIALIAS
)
tempImage
.
save
(
os
.
path
.
join
(
tempfile
.
gettempdir
(),
root
+
str
(
tier
)
+
'-'
+
str
(
row
)
+
ext
))
...
...
@@ -269,9 +266,9 @@ class ZoomifyBase:
rowImage
=
None
if
tier
>
0
:
if
row
%
2
!=
0
:
self
.
processRowImage
(
tier
=
(
tier
-
1
),
row
=
((
row
-
1
)
/
2
))
self
.
processRowImage
(
tier
=
(
tier
-
1
),
row
=
((
row
-
1
)
/
/
2
))
elif
row
==
rowsForTier
-
1
:
self
.
processRowImage
(
tier
=
(
tier
-
1
),
row
=
(
row
/
2
))
self
.
processRowImage
(
tier
=
(
tier
-
1
),
row
=
(
row
/
/
2
))
def
ZoomifyProcess
(
self
,
imageNames
):
""" the method the client calls to generate zoomify metadata """
...
...
@@ -335,7 +332,7 @@ class ZoomifyZopeProcessor(ZoomifyBase):
def
openImage
(
self
):
""" load the image data """
return
PIL_Image
.
open
(
self
.
_v_imageObject
.
name
)
return
PIL_Image
.
open
(
self
.
_v_imageObject
)
def
createDefaultViewer
(
self
):
""" add the default Zoomify viewer to the Zoomify metadata """
...
...
@@ -411,7 +408,7 @@ class ZoomifyZopeProcessor(ZoomifyBase):
tileFileName
=
self
.
getTileFileName
(
scaleNumber
,
column
,
row
)
tileContainerName
=
self
.
getAssignedTileContainerName
(
tileFileName
=
tileFileName
)
tileImageData
=
String
IO
()
tileImageData
=
io
.
Bytes
IO
()
image
.
save
(
tileImageData
,
'JPEG'
,
quality
=
self
.
qualitySetting
)
tileImageData
.
seek
(
0
)
if
hasattr
(
self
.
_v_saveFolderObject
,
tileContainerName
):
...
...
@@ -529,7 +526,7 @@ class ERP5ZoomifyZopeProcessor(ZoomifyZopeProcessor):
param2
=
0
my_text
=
'%s %s %s %s %s %s
\
n
'
%
(
tile_group_id
,
tile_title
,
algorithm
,
param1
,
param2
,
num
)
self
.
my_file
.
write
(
my_text
)
self
.
my_file
.
write
(
my_text
.
encode
()
)
num
=
num
-
1
...
...
@@ -543,7 +540,7 @@ class ERP5ZoomifyZopeProcessor(ZoomifyZopeProcessor):
if
w
!=
0
and
h
!=
0
:
tile_group_id
=
self
.
getAssignedTileContainerName
()
tile_group
=
self
.
document
[
tile_group_id
]
tileImageData
=
String
IO
()
tileImageData
=
io
.
Bytes
IO
()
image
.
save
(
tileImageData
,
'JPEG'
,
quality
=
self
.
qualitySetting
)
tileImageData
.
seek
(
0
)
if
tile_group
is
None
:
...
...
@@ -556,11 +553,11 @@ class ERP5ZoomifyZopeProcessor(ZoomifyZopeProcessor):
def
saveXMLOutput
(
self
):
"""save the xml file"""
my_
string
=
String
IO
()
my_
string
.
write
(
self
.
getXMLOutput
())
my_
string
.
seek
(
0
)
my_
file
=
io
.
Bytes
IO
()
my_
file
.
write
(
self
.
getXMLOutput
())
my_
file
.
seek
(
0
)
self
.
document
.
newContent
(
portal_type
=
'Embedded File'
,
id
=
'ImageProperties.xml'
,
file
=
my_
string
,
id
=
'ImageProperties.xml'
,
file
=
my_
file
,
filename
=
'ImageProperties.xml'
)
return
...
...
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