feat(phase1): implement OpenCV image processing pipeline
- Create ImageProcessor service with EXIF orientation detection - Implement smart cropping via OpenCV contour detection (10% padding) - Add text orientation detection using Hough line transform - Resize and compress images to 1200px with 85% JPEG quality - Generate 200px square thumbnails with center crop - Fallback to Pillow if OpenCV fails - Comprehensive test suite: 28 tests all passing - File size validation (reject >10MB) - Graceful error handling for corrupted/invalid images - Update requirements.txt with opencv-python, piexif, python-magic
This commit is contained in:
56
venv/lib/python3.12/site-packages/piexif/_remove.py
Normal file
56
venv/lib/python3.12/site-packages/piexif/_remove.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import io
|
||||
|
||||
from ._common import *
|
||||
from piexif import _webp
|
||||
|
||||
def remove(src, new_file=None):
|
||||
"""
|
||||
py:function:: piexif.remove(filename)
|
||||
|
||||
Remove exif from JPEG.
|
||||
|
||||
:param str filename: JPEG
|
||||
"""
|
||||
output_is_file = False
|
||||
if src[0:2] == b"\xff\xd8":
|
||||
src_data = src
|
||||
file_type = "jpeg"
|
||||
elif src[0:4] == b"RIFF" and src[8:12] == b"WEBP":
|
||||
src_data = src
|
||||
file_type = "webp"
|
||||
else:
|
||||
with open(src, 'rb') as f:
|
||||
src_data = f.read()
|
||||
output_is_file = True
|
||||
if src_data[0:2] == b"\xff\xd8":
|
||||
file_type = "jpeg"
|
||||
elif src_data[0:4] == b"RIFF" and src_data[8:12] == b"WEBP":
|
||||
file_type = "webp"
|
||||
|
||||
if file_type == "jpeg":
|
||||
segments = split_into_segments(src_data)
|
||||
exif = get_exif_seg(segments)
|
||||
if exif:
|
||||
new_data = src_data.replace(exif, b"")
|
||||
else:
|
||||
new_data = src_data
|
||||
elif file_type == "webp":
|
||||
try:
|
||||
new_data = _webp.remove(src_data)
|
||||
except ValueError:
|
||||
new_data = src_data
|
||||
except e:
|
||||
print(e.args)
|
||||
raise ValueError("Error occurred.")
|
||||
|
||||
if isinstance(new_file, io.BytesIO):
|
||||
new_file.write(new_data)
|
||||
new_file.seek(0)
|
||||
elif new_file:
|
||||
with open(new_file, "wb+") as f:
|
||||
f.write(new_data)
|
||||
elif output_is_file:
|
||||
with open(src, "wb+") as f:
|
||||
f.write(new_data)
|
||||
else:
|
||||
raise ValueError("Give a second argument to 'remove' to output file")
|
||||
Reference in New Issue
Block a user