Skip to content

Commit

Permalink
fix unsupported image file treatment. add experimental support for MP…
Browse files Browse the repository at this point in the history
…O files
  • Loading branch information
victordomingos committed Apr 6, 2020
1 parent b30b76d commit 36dd152
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 29 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Python 3.6+ installation. We try to keep the external dependencies at a minimum,
in order to keep compatibility with different platforms, including Pythonista
on iOS. At this moment, we require:

- Pillow>=5.1.0
- piexif>=1.1.2
- Pillow>=6.2.2
- piexif>=1.1.3

The easiest way to install it in a single step, including any dependencies, is
by using this command:
Expand All @@ -35,11 +35,6 @@ by using this command:
pip3 install pillow optimize-images
```

However, if you are on a Mac with Python 3.6 and macOS X 10.11 El Capitan or
earlier, you should use Pillow 5.0.0 instead (use instead:
`pip3 install pillow==5.0.0 optimize-images`). In case you have already
migrated to Python 3.7, you should be fine with Pillow 5.1.0 or later.

If you are able to swap Pillow with the faster version
[Pillow-SIMD](https://github.com/uploadcare/pillow-simd), you should be able
to get a considerably faster speed. For that reason, we provide, as a
Expand Down
9 changes: 8 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
Version history:
================

---
v.1.3.5 - 07-04-2020
* Fixed a small bug in unsupported image format treatment.
* Added experimental support for MPO images, which are now treated as JPEG
image files (if multiple pictures are present in one MPO file, only the first
one will be processed).

---
v.1.3.4 - 19-02-2020
* Ignore unsupported image formats (contributed by Petro (liashchynskyi@GitHub).
* Added brief instructions (and a script for macOS) for Pillow-SIMD installation, as a faster alternative to Pillow.
* Added brief instructions (and a script for macOS) for Pillow-SIMD
installation, as a faster alternative to Pillow.

---
v.1.3.3 - 06-08-2019
Expand Down
13 changes: 6 additions & 7 deletions docs/docs_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Python 3.6+ installation. We try to keep the external dependencies at a minimum,
in order to keep compatibility with different platforms, including Pythonista
on iOS. At this moment, we require:

- Pillow>=5.1.0
- piexif==1.0.13
- Pillow>=6.2.2
- piexif==1.1.3

The easiest way to install it in a single step, including any dependencies, is
by using this command:
Expand All @@ -60,11 +60,6 @@ by using this command:
pip3 install pillow optimize-images
```

However, if you are on a Mac with Python 3.6 and macOS X 10.11 El Capitan or
earlier, you should use Pillow 5.0.0 instead (use instead:
`pip3 install pillow==5.0.0 optimize-images`). In case you have already
migrated to Python 3.7, you should be fine with Pillow 5.1.0 or later.

If you are able to swap Pillow with the faster version
[Pillow-SIMD](https://github.com/uploadcare/pillow-simd), you should be able
to get a considerably faster speed. For that reason, we provide, as a
Expand Down Expand Up @@ -180,6 +175,10 @@ choose to reduce the number of colors using an adaptive palette. Be aware
that by using this option image quality may be affected in a very
noticeable way.

Since version 1.3.5, Optimize Images also offers experimental support for MPO
images, which are now treated as single picture JPEG image files (if multiple
pictures are present in one MPO file, only the first one will be processed).


### DISCLAIMER
**Please note that the operation is done DESTRUCTIVELY, by replacing the
Expand Down
15 changes: 8 additions & 7 deletions docs/docs_PT.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ superior. Procuramos manter no mínimo as dependências externas, de modo a
manter a compatibilidade com diferentes plataformas, incluindo Pythonista em
iOS. Neste momento, requer:

- Pillow==5.1.0
- piexif==1.0.13
- Pillow==6.2.2
- piexif==1.1.3

A forma mais simples de instalar num único passo esta aplicação, incluindo
quaisquer requisitos, é através deste comando:
Expand All @@ -62,11 +62,6 @@ quaisquer requisitos, é através deste comando:
pip3 install pillow optimize-images
```

Nota: Se está a utilizar um Mac com Python 3.6 e macOS X 10.11 El Capitan ou
anterior, deverá usar antes a versão Pillow 5.0.0. No caso de já ter migrado
para Python 3.7, não deverá ter problemas com o Pillow 5.1.0 ou mesmo uma
versão mais recente.

Caso tenha a possibilidade de substituir o Pillow pela versão mais rápida
[Pillow-SIMD](https://github.com/uploadcare/pillow-simd), deverá conseguir
notar um desempenho consideravelmente superior. É por isso que, por cortesia,
Expand Down Expand Up @@ -202,6 +197,12 @@ dos ficheiros se optar por reduzir o número de cores utilizando uma paleta
adaptativa. Tenha em consideração que ao usar esta opção a qualidade de
imagem poderá ser afetada de forma bastante notória.

Desde a versão 1.3.5, a aplicação Optimize Images oferece suporte experimental
para imagens no formato MPO, as quais são tratadas como ficheiros JPEG de imagem
única (caso um ficheiro MPO contenha várias imagens, apenas a primeira será
processada).


### ADVERTÊNCIA
**Por favor, tenha em consideração que a operação deste programa é feita DE
MODO DESTRUTIVO, substituindo os ficheiros originais pelos ficheiros
Expand Down
2 changes: 1 addition & 1 deletion optimize_images/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.4'
__version__ = '1.3.5'
24 changes: 22 additions & 2 deletions optimize_images/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"""
import os

import piexif

try:
from PIL import Image
except ImportError:
Expand Down Expand Up @@ -62,10 +64,28 @@ def do_optimization(t: Task) -> TaskResult:
# should skip unsupported formats?)
if img.format.upper() == 'PNG':
return optimize_png(t)
elif (img.format.upper() == 'JPEG'):
elif img.format.upper() in ('JPEG', 'MPO'):
return optimize_jpg(t)
else:
pass
try:
had_exif = True if piexif.load(t.src_path)['Exif'] else False
except piexif.InvalidImageDataError: # Not a supported format
had_exif = False
except ValueError: # No exif info
had_exif = False
return TaskResult(img=t.src_path,
orig_format=img.format.upper(),
result_format=img.format.upper(),
orig_mode=img.mode,
result_mode=img.mode,
orig_colors=0,
final_colors=0,
orig_size=os.path.getsize(t.src_path),
final_size=0,
was_optimized=False,
was_downsized=False,
had_exif=had_exif,
has_exif=had_exif)


def main():
Expand Down
4 changes: 2 additions & 2 deletions requirements_development.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bleach==3.1.0
bleach==3.1.4
certifi==2019.6.16
cffi==1.12.3
chardet==3.0.4
Expand All @@ -7,7 +7,7 @@ docutils==0.14
future==0.17.1
idna==2.8
piexif==1.1.3
Pillow==6.2.1
Pillow==6.2.2
pkginfo==1.5.0.1
pycparser==2.19
Pygments==2.4.2
Expand Down
4 changes: 2 additions & 2 deletions requirements_for_desktop.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Pillow>=5.1.0
piexif>=1.1.2
Pillow>=6.2.2
piexif>=1.1.3

0 comments on commit 36dd152

Please sign in to comment.