diff --git a/app.py b/app.py index e47c471..66a2b93 100644 --- a/app.py +++ b/app.py @@ -96,55 +96,30 @@ def allowed_file(filename): return '.' in filename def get_image_dimensions(filepath): - """Get image dimensions using appropriate tool based on file type.""" + """Get image dimensions using ImageMagick.""" try: - if filepath.lower().endswith('.arw'): - app.logger.info(f"Getting dimensions for ARW file: {filepath}") - # Utiliser exiftool pour obtenir les dimensions de l'aperçu JPEG - cmd = ['exiftool', '-s', '-s', '-s', '-PreviewImageLength', '-PreviewImageWidth', filepath] - app.logger.info(f"Running exiftool command: {' '.join(cmd)}") - result = subprocess.run(cmd, capture_output=True, text=True) - - if result.returncode == 0 and result.stdout.strip(): - app.logger.info(f"Exiftool output: {result.stdout}") - # Essayer de parser les dimensions - dimensions = result.stdout.strip().split('\n') - if len(dimensions) == 2: - try: - height = int(dimensions[0]) - width = int(dimensions[1]) - app.logger.info(f"Successfully parsed dimensions: {width}x{height}") - return width, height - except ValueError: - app.logger.warning("Could not parse dimensions from exiftool output") - pass - else: - app.logger.warning(f"Exiftool failed or no output: {result.stderr}") - - # Si on n'a pas pu obtenir les dimensions de l'aperçu, utiliser les dimensions connues - app.logger.info("Using known dimensions for Sony A7 IV") - return 7008, 4672 # Dimensions connues pour Sony A7 IV + app.logger.info(f"Getting dimensions for non-ARW file: {filepath}") + command = ['magick', 'identify', filepath] + app.logger.info(f"Running ImageMagick command: {' '.join(command)}") + result = subprocess.run(command, capture_output=True, text=True, check=True) + + # Parse dimensions from output + output = result.stdout.strip() + match = re.search(r'\s(\d+)x(\d+)\s', output) + if match: + width, height = map(int, match.groups()) + return width, height else: - app.logger.info(f"Getting dimensions for non-ARW file: {filepath}") - cmd = ['convert', 'identify', filepath] - app.logger.info(f"Running ImageMagick command: {' '.join(cmd)}") - result = subprocess.run(cmd, capture_output=True, text=True) - if result.returncode != 0: - raise Exception(f"Error getting image dimensions: {result.stderr}") + raise ValueError(f"Could not parse dimensions from output: {output}") - app.logger.info(f"ImageMagick output: {result.stdout}") - # Parse the output to get dimensions - match = re.search(r'\s(\d+)x(\d+)\s', result.stdout) - if match: - width = int(match.group(1)) - height = int(match.group(2)) - app.logger.info(f"Successfully parsed dimensions: {width}x{height}") - return width, height - else: - raise Exception("Could not parse image dimensions") + except subprocess.CalledProcessError as e: + error_msg = f"Error getting image dimensions: {e.stderr}" + app.logger.error(error_msg) + raise ValueError(error_msg) except Exception as e: - app.logger.error(f"Error getting image dimensions: {str(e)}") - return None, None + error_msg = f"Error getting image dimensions: {str(e)}" + app.logger.error(error_msg) + raise ValueError(error_msg) def get_available_formats(): """Get all formats supported by ImageMagick.""" @@ -311,7 +286,7 @@ def build_imagemagick_command(filepath, output_path, width, height, percentage, raise Exception("No preview image found in RAW file") # Commande ImageMagick pour redimensionner le JPEG extrait - magick_cmd = ['convert', temp_jpeg] + magick_cmd = ['magick', temp_jpeg] if width.isdigit() and height.isdigit(): resize_value = f"{width}x{height}" if keep_ratio else f"{width}x{height}!" @@ -331,7 +306,7 @@ def build_imagemagick_command(filepath, output_path, width, height, percentage, else: app.logger.info(f"Processing non-ARW file: {filepath}") # Pour les autres formats, utiliser directement ImageMagick - command = ['convert', filepath] + command = ['magick', filepath] if width.isdigit() and height.isdigit(): resize_value = f"{width}x{height}" if keep_ratio else f"{width}x{height}!" diff --git a/templates/resize.html b/templates/resize.html index 30addc8..6a1def5 100644 --- a/templates/resize.html +++ b/templates/resize.html @@ -141,7 +141,7 @@

{{ _('Resize Image: %(filename)s', filename=filename) }}

-
+
{{ _('Resize by Pixels') }}