Use exiftool to strip image EXIF data (preserving orientation)
This commit is contained in:
parent
4ce2702886
commit
6cbcfc98d3
@ -36,6 +36,15 @@ the following:
|
|||||||
* ``ffmpegthumbnailer`` executable in ``$PATH``
|
* ``ffmpegthumbnailer`` executable in ``$PATH``
|
||||||
|
|
||||||
|
|
||||||
|
EXIF Stripping
|
||||||
|
--------------
|
||||||
|
|
||||||
|
When ``STRIP_IMAGE_EXIF`` is enabled, all images uploaded will be
|
||||||
|
processed through exiftool to strip all EXIF data except the orientation
|
||||||
|
tag.
|
||||||
|
Requires the ``exiftool`` script in ``$PATH``.
|
||||||
|
|
||||||
|
|
||||||
INSTALL
|
INSTALL
|
||||||
-------
|
-------
|
||||||
::
|
::
|
||||||
|
42
fhost.py
42
fhost.py
@ -68,6 +68,11 @@ app.config["FHOST_UPLOAD_BLACKLIST"] = "tornodes.txt"
|
|||||||
app.config["NSFW_DETECT"] = False
|
app.config["NSFW_DETECT"] = False
|
||||||
app.config["NSFW_THRESHOLD"] = 0.608
|
app.config["NSFW_THRESHOLD"] = 0.608
|
||||||
|
|
||||||
|
app.config["STRIP_IMAGE_EXIF"] = True
|
||||||
|
|
||||||
|
if app.config["STRIP_IMAGE_EXIF"]:
|
||||||
|
import subprocess
|
||||||
|
|
||||||
if app.config["NSFW_DETECT"]:
|
if app.config["NSFW_DETECT"]:
|
||||||
from nsfw_detect import NSFWDetector
|
from nsfw_detect import NSFWDetector
|
||||||
nsfw = NSFWDetector()
|
nsfw = NSFWDetector()
|
||||||
@ -185,12 +190,7 @@ def in_upload_bl(addr):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def store_file(f, addr):
|
def check_existing(digest, data, addr):
|
||||||
if in_upload_bl(addr):
|
|
||||||
return "Your host is blocked from uploading files.\n", 451
|
|
||||||
|
|
||||||
data = f.stream.read()
|
|
||||||
digest = sha256(data).hexdigest()
|
|
||||||
existing = File.query.filter_by(sha256=digest).first()
|
existing = File.query.filter_by(sha256=digest).first()
|
||||||
|
|
||||||
if existing:
|
if existing:
|
||||||
@ -212,7 +212,20 @@ def store_file(f, addr):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return existing.geturl()
|
return existing.geturl()
|
||||||
else:
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def store_file(f, addr):
|
||||||
|
if in_upload_bl(addr):
|
||||||
|
return "Your host is blocked from uploading files.\n", 451
|
||||||
|
|
||||||
|
data = f.stream.read()
|
||||||
|
digest = sha256(data).hexdigest()
|
||||||
|
|
||||||
|
exists = check_existing(digest, data, addr)
|
||||||
|
if exists != None:
|
||||||
|
return exists
|
||||||
|
|
||||||
guessmime = mimedetect.from_buffer(data)
|
guessmime = mimedetect.from_buffer(data)
|
||||||
|
|
||||||
if not f.content_type or not "/" in f.content_type or f.content_type == "application/octet-stream":
|
if not f.content_type or not "/" in f.content_type or f.content_type == "application/octet-stream":
|
||||||
@ -241,6 +254,21 @@ def store_file(f, addr):
|
|||||||
if not ext:
|
if not ext:
|
||||||
ext = ".bin"
|
ext = ".bin"
|
||||||
|
|
||||||
|
if app.config["STRIP_IMAGE_EXIF"] and mime.startswith("image/"):
|
||||||
|
p = subprocess.Popen(["exiftool",
|
||||||
|
"-stay_open", "true",
|
||||||
|
"-all=",
|
||||||
|
"-tagsfromfile", "@",
|
||||||
|
"-Orientation",
|
||||||
|
"-" ], stdout = subprocess.PIPE, stdin = subprocess.PIPE)
|
||||||
|
p.stdin.write(data)
|
||||||
|
p.stdin.close()
|
||||||
|
data = p.stdout.read()
|
||||||
|
digest = sha256(data).hexdigest()
|
||||||
|
exists = check_existing(digest, data, addr)
|
||||||
|
if exists != None:
|
||||||
|
return exists
|
||||||
|
|
||||||
spath = getpath(digest)
|
spath = getpath(digest)
|
||||||
|
|
||||||
with open(spath, "wb") as of:
|
with open(spath, "wb") as of:
|
||||||
|
Loading…
Reference in New Issue
Block a user