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
|
intensities
|
||||||
end
|
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
|
defp strip(file) do
|
||||||
stripped = Briefly.create!(extname: ".jpg")
|
stripped = Briefly.create!(extname: ".jpg")
|
||||||
|
|
||||||
# ImageMagick always reencodes the image, resulting in quality loss, so
|
# ImageMagick always reencodes the image, resulting in quality loss, so
|
||||||
# be more clever
|
# be more clever
|
||||||
case System.cmd("identify", ["-format", "%[orientation]", file]) do
|
case requires_lossy_transformation?(file) do
|
||||||
{"Undefined", 0} ->
|
true ->
|
||||||
# Strip EXIF without touching orientation
|
# Transcode: strip EXIF, embedded profile and reorient image
|
||||||
{_output, 0} = System.cmd("jpegtran", ["-copy", "none", "-outfile", stripped, file])
|
{_output, 0} =
|
||||||
|
System.cmd("convert", [
|
||||||
|
file,
|
||||||
|
"-profile",
|
||||||
|
srgb_profile(),
|
||||||
|
"-auto-orient",
|
||||||
|
"-strip",
|
||||||
|
stripped
|
||||||
|
])
|
||||||
|
|
||||||
{_output, 0} ->
|
_ ->
|
||||||
# Strip EXIF and reorient image
|
# Transmux only: Strip EXIF without touching orientation
|
||||||
{_output, 0} = System.cmd("convert", [file, "-auto-orient", "-strip", stripped])
|
{_output, 0} = System.cmd("jpegtran", ["-copy", "none", "-outfile", stripped, file])
|
||||||
end
|
end
|
||||||
|
|
||||||
stripped
|
stripped
|
||||||
|
@ -85,4 +104,8 @@ defmodule Philomena.Processors.Jpeg do
|
||||||
|
|
||||||
scaled
|
scaled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp srgb_profile do
|
||||||
|
Path.join(File.cwd!(), "priv/icc/sRGB.icc")
|
||||||
|
end
|
||||||
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