mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 05:37:59 +01:00
Add initial handling of ICC color profiles
This commit is contained in:
parent
7686f4c2d6
commit
f26d138a05
2 changed files with 30 additions and 7 deletions
|
@ -23,19 +23,38 @@ defmodule Philomena.Processors.Jpeg do
|
|||
intensities
|
||||
end
|
||||
|
||||
defp requires_lossy_transformation?(file) do
|
||||
with {output, 0} <-
|
||||
System.cmd("identify", ["-format", "%[orientation]\t%[profile:icc]", file]),
|
||||
[orientation, profile] <- String.split(output, "\t") do
|
||||
orientation != "Undefined" or profile != ""
|
||||
else
|
||||
_ ->
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
defp strip(file) do
|
||||
stripped = Briefly.create!(extname: ".jpg")
|
||||
|
||||
# ImageMagick always reencodes the image, resulting in quality loss, so
|
||||
# be more clever
|
||||
case System.cmd("identify", ["-format", "%[orientation]", file]) do
|
||||
{"Undefined", 0} ->
|
||||
# Strip EXIF without touching orientation
|
||||
{_output, 0} = System.cmd("jpegtran", ["-copy", "none", "-outfile", stripped, file])
|
||||
case requires_lossy_transformation?(file) do
|
||||
true ->
|
||||
# Transcode: strip EXIF, embedded profile and reorient image
|
||||
{_output, 0} =
|
||||
System.cmd("convert", [
|
||||
file,
|
||||
"-profile",
|
||||
srgb_profile(),
|
||||
"-auto-orient",
|
||||
"-strip",
|
||||
stripped
|
||||
])
|
||||
|
||||
{_output, 0} ->
|
||||
# Strip EXIF and reorient image
|
||||
{_output, 0} = System.cmd("convert", [file, "-auto-orient", "-strip", stripped])
|
||||
_ ->
|
||||
# Transmux only: Strip EXIF without touching orientation
|
||||
{_output, 0} = System.cmd("jpegtran", ["-copy", "none", "-outfile", stripped, file])
|
||||
end
|
||||
|
||||
stripped
|
||||
|
@ -85,4 +104,8 @@ defmodule Philomena.Processors.Jpeg do
|
|||
|
||||
scaled
|
||||
end
|
||||
|
||||
defp srgb_profile do
|
||||
Path.join(File.cwd!(), "priv/icc/sRGB.icc")
|
||||
end
|
||||
end
|
||||
|
|
BIN
priv/icc/sRGB.icc
Normal file
BIN
priv/icc/sRGB.icc
Normal file
Binary file not shown.
Loading…
Reference in a new issue