Skip to content

Commit

Permalink
handle thumbnails also in py2.6 with Wand instead of MagickPy + older…
Browse files Browse the repository at this point in the history
… version of w3lib (#18)
  • Loading branch information
RouxRC committed May 7, 2017
1 parent be204f8 commit 6d30a74
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions gazouilleur/lib/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
# Check image dependencies if Manet screenshots activated
if hasattr(config, 'URL_MANET'):
try:
import magickpy
import wand
except (NameError, ImportError) as e:
logerr("Could not load module%s.\nERROR: This module is required to activate the Manet screenshots set with URL_MANET in `gazouilleur/config.py`: %s\nERROR: Please check your install or run `pip install MagickPy` in gazouilleur's virtualenv.\n" % (str(e).replace('No module named', ''), config.URL_STATS))
logerr("Could not load module%s.\nERROR: This module is required to activate the Manet screenshots set with URL_MANET in `gazouilleur/config.py`: %s\nERROR: Please check your install or run `pip install Wand` in gazouilleur's virtualenv.\n" % (str(e).replace('No module named', ''), config.URL_STATS))
exit(1)

try:
Expand Down
12 changes: 7 additions & 5 deletions gazouilleur/lib/webmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os, re, time
from hashlib import sha512
from magickpy import Image
from wand.image import Image
from urllib import quote_plus
from w3lib.html import replace_entities
from twisted.web import client
Expand Down Expand Up @@ -84,12 +84,14 @@ def save_screenshot(self, version, retries=3):
loggerr("%s: %s %s" % (self.name, type(e), e), self.channel, "WebMonitor-shot")
else:
try:
i = Image.read(str(name))
w = 200.0
h = round(i.height * w / i.width)
i2 = i.makeResize(long(w), long(h), 5, 1)
thumbname = "%s-small.png" % name[:-4]
i2.write(str(thumbname))
with Image(filename=name) as i:
iW, iH = i.size
h = round(iH * w / iW)
with i.clone() as i2:
i2.resize(int(w), int(h))
i2.save(filename=thumbname)
os.chmod(thumbname, 0o644)
del img, i, i2
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ zope.interface
twisted==15.1.0
stevedore
virtualenvwrapper
w3lib
w3lib==1.12.0

# Mongo
pymongo==3.0.3
Expand All @@ -24,4 +24,4 @@ pypump==0.5.0
# pip install numpy
# matplotlib
# pystache
# MagickPy
# Wand

0 comments on commit 6d30a74

Please sign in to comment.