Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Size limit for download as jpg #4172

Merged
merged 10 commits into from
Sep 24, 2015
5 changes: 5 additions & 0 deletions components/common/resources/ome/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@
<property name="mutable" value="false"/>
<property name="visibility" value="all"/>
</bean>
<bean class="ome.system.Preference" id="omero.client.download_as_jpg.max_size">
<property name="db" value="false"/>
<property name="mutable" value="false"/>
<property name="visibility" value="all"/>
</bean>
<!-- End preference list -->
</list>
</property>
Expand Down
14 changes: 14 additions & 0 deletions components/tools/OmeroPy/src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,20 @@ def getInterpolateSetting(self):
return (self.getConfigService().getConfigValue(
"omero.client.viewer.interpolate_pixels") or 'true')

def getDownloadAsJpgMaxSizeSetting(self):
"""
Returns default max size of images that can be downloaded as
jpg, png or tiff, expressed as number of pixels.
Default is 144000000 (12k * 12k image)

:return: Integer
"""
size = self.getConfigService().getConfigValue(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here, it is breaking change for 5.1 series. It should go in try catch block to guarantee compatibility with < 5.1.4 server. see #4191

"omero.client.download_as_jpg.max_size")
if size:
return int(size)
return 144000000

def getWebclientHost(self):
"""
Returns default initial zoom level set on the server.
Expand Down
2 changes: 2 additions & 0 deletions components/tools/OmeroWeb/omeroweb/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def load_server_settings(self, conn, request):
conn.getInitialZoomLevel()
request.session['server_settings']['interpolate_pixels'] = \
toBoolean(conn.getInterpolateSetting())
request.session['server_settings']['download_as_jpg_max_size'] = \
conn.getDownloadAsJpgMaxSizeSetting()

def get_public_user_connector(self):
"""
Expand Down
6 changes: 6 additions & 0 deletions components/tools/OmeroWeb/omeroweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,12 @@ def leave_none_unset_int(s):
" 'webtest/webclient_plugins/center_plugin.overlay.js.html',"
" 'channel_overlay_panel']``. "
"The javascript loads data into ``$('#div_id')``.")],
"omero.web.download_jpg.max_size":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that can be removed now

["DOWNLOAD_JPG_MAX_SIZE",
144000000,
int,
("Disable download as jpg, png & tiff for images"
"where sizeX * sizeY exceeds this limit")],
}

DEPRECATED_SETTINGS_MAPPINGS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,27 @@ def getPlateId(self):
elif self.acquisition:
return self.acquisition._obj.plate.id.val

def canExportAsJpg(self, request, objDict=None):
"""
Can't export as Jpg, Png, Tiff if bigger than approx 12k * 12k.
Limit set by OOM error in omeis.providers.re.RGBIntBuffer
"""
can = True
try:
limit = request.session['server_settings'][
'download_as_jpg_max_size']
except:
limit = 144000000
if self.image:
if (self.image.getSizeX() * self.image.getSizeY()) > limit:
can = False
elif objDict is not None:
if 'image' in objDict:
for i in objDict['image']:
if (i.getSizeX() * i.getSizeY()) > limit:
can = False
return can

def canDownload(self, objDict=None):
"""
Returns False if any of selected object cannot be downloaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,53 +148,96 @@
{% endif %}

{% if image %}
<li>
{% with ex=canExportAsJpg %}
<li {% if not ex %}class="disabled"{% endif %}>
<a
{% if share and not share.share.isOwned %}
<a href="{% url 'web_render_image_download' share_id=share.share.id iid=image.id %}"
title="Download as JPEG">
href="{% url 'web_render_image_download' share_id=share.share.id iid=image.id %}"
{% else %}
<a href="{% url 'web_render_image_download' image.id %}" title="Download as JPEG">
href="{% url 'web_render_image_download' image.id %}"
{% endif %}
{% if not ex %}
class="disabled" title="Image is too big to download as JPEG"
{% else %}
title="Download as JPEG"
{% endif %}
>
Export as JPEG
</a>
</li>
<li>
<li {% if not ex %}class="disabled"{% endif %}>
<a
{% if share and not share.share.isOwned %}
<a href="{% url 'web_render_image_download' share_id=share.share.id iid=image.id %}?format=png"
title="Download as PNG">
href="{% url 'web_render_image_download' share_id=share.share.id iid=image.id %}?format=png"
{% else %}
<a href="{% url 'web_render_image_download' image.id %}?format=png" title="Download as PNG">
href="{% url 'web_render_image_download' image.id %}?format=png"
{% endif %}
{% if not ex %}
class="disabled" title="Image is too big to download as PNG"
{% else %}
title="Download as PNG"
{% endif %}
>
Export as PNG
</a>
</li>
<li>
<li {% if not ex %}class="disabled"{% endif %}>
<a
{% if share and not share.share.isOwned %}
<a href="{% url 'web_render_image_download' share_id=share.share.id iid=image.id %}?format=tif"
title="Download as TIFF">
href="{% url 'web_render_image_download' share_id=share.share.id iid=image.id %}?format=tif"
{% else %}
href="{% url 'web_render_image_download' image.id %}?format=tif"
{% endif %}
{% if not ex %}
class="disabled" title="Image is too big to download as TIFF"
{% else %}
<a href="{% url 'web_render_image_download' image.id %}?format=tif" title="Download as TIFF">
title="Download as TIFF"
{% endif %}
>
Export as TIFF
</a>
</li>
{% endwith %}
{% else %}
{% if filesetInfo %}
<li>
{% with ex=canExportAsJpg %}
<li {% if not ex %}class="disabled"{% endif %}>
<a href="#"
onClick="return OME.openPopup('{% url 'download_placeholder' %}?ids={{ link_string }}&format=jpeg&index={{ index }}');"
title="Download as JPEGs (zip)">Export as JPEG</a>
{% if not ex %}
class="disabled" title="Images are too big to download as JPEGs"
{% else %}
title="Download as JPEGs (zip)"
{% endif %}
>
Export as JPEG
</a>
</li>
<li>
<li {% if not ex %}class="disabled"{% endif %}>
<a href="#"
onClick="return OME.openPopup('{% url 'download_placeholder' %}?ids={{ link_string }}&format=png&index={{ index }}');"
title="Download as PNGs (zip)">Export as PNG</a>
{% if not ex %}
class="disabled" title="Images are too big to download as PNGs"
{% else %}
title="Download as PNGs (zip)"
{% endif %}
>
Export as PNG
</a>
</li>
<li>
<li {% if not ex %}class="disabled"{% endif %}>
<a href="#"
onClick="return OME.openPopup('{% url 'download_placeholder' %}?ids={{ link_string }}&format=tif&index={{ index }}');"
title="Download as TIFFs (zip)">Export as TIFF</a>
{% if not ex %}
class="disabled" title="Images are too big to download as TIFFs"
{% else %}
title="Download as TIFFs (zip)"
{% endif %}
>
Export as TIFF
</a>
</li>
{% endwith %}
{% endif %}
{% endif %}
</ul>
Expand Down
3 changes: 3 additions & 0 deletions components/tools/OmeroWeb/omeroweb/webclient/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ def load_metadata_details(request, c_type, c_id, conn=None, share_id=None,
else:
template = "webclient/annotations/metadata_general.html"
manager.annotationList()
context['canExportAsJpg'] = manager.canExportAsJpg(request)
figScripts = manager.listFigureScripts()
form_comment = CommentAnnotationForm(initial=initial)
context['manager'] = manager
Expand Down Expand Up @@ -1568,6 +1569,7 @@ def batch_annotate(request, conn=None, **kwargs):
ratings = manager.getGroupedRatings(allratings)

figScripts = manager.listFigureScripts(objs)
canExportAsJpg = manager.canExportAsJpg(request, objs)
filesetInfo = None
iids = []
if 'well' in objs and len(objs['well']) > 0:
Expand Down Expand Up @@ -1605,6 +1607,7 @@ def batch_annotate(request, conn=None, **kwargs):
'batch_ann': True,
'index': index,
'figScripts': figScripts,
'canExportAsJpg': canExportAsJpg,
'filesetInfo': filesetInfo,
'annotationBlocked': annotationBlocked,
'userRatingAvg': userRatingAvg,
Expand Down
3 changes: 3 additions & 0 deletions etc/omero.properties
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,9 @@ omero.client.ui.menu.dropdown.everyone.enabled=true
# Client viewers interpolate pixels by default.
omero.client.viewer.interpolate_pixels=true

# Clients disable download as jpg/png/tiff above max pixel count.
omero.client.download_as_jpg.max_size=144000000

#############################################
## Ice overrides
##
Expand Down