Compare commits

...

22 Commits

Author SHA1 Message Date
Mark Felder
016376dbf0 Add libheif-tools to the builds 2021-02-20 17:29:18 -06:00
Mark Felder
4b3f7a497f Use System.cmd and match on the exit code 2021-02-20 17:21:03 -06:00
Mark Felder
3c71a5038a Document HeifToJpeg upload filter 2021-02-20 17:08:43 -06:00
Mark Felder
5a358b31fe Custom check here not needed as we aren't using mogrify anymore 2021-02-20 14:41:57 -06:00
Mark Felder
4adb9e8e2c Revert these for now 2021-02-20 14:25:11 -06:00
Mark Felder
b23cf2d149 Wrong name of binary 2021-02-20 14:22:48 -06:00
Mark Felder
14e52188af No need to bump Mogrify at this time 2021-02-20 14:21:39 -06:00
Mark Felder
daba3b8522 Change to using heic-convert which is more common than mogrify supporting these files 2021-02-20 14:21:08 -06:00
Mark Felder
9e0e2fb6b4 Fix test name, credo 2021-02-16 09:32:03 -06:00
Mark Felder
28253c4e4a Should be private 2021-02-16 09:27:40 -06:00
Mark Felder
889341d0d7 Validate we can convert heic to jpeg 2021-02-16 09:14:40 -06:00
Mark Felder
b40581c4e8 Cleanup extra temp file 2021-02-16 09:10:37 -06:00
Mark Felder
13b57f2cb3 Add startup check to ensure we can convert the heic files 2021-02-15 22:40:02 +00:00
Mark Felder
d265c2c0f1 Using the error now 2021-02-15 21:32:48 +00:00
Mark Felder
c6480eaf24 Better error when using Mogrify
Hardcoding that the command isn't available is wrong. We check it on startup.
2021-02-15 15:28:58 -06:00
Mark Felder
390b4471f2 Clearer assignment name 2021-02-15 15:23:14 -06:00
Mark Felder
d3cf505b42 Oopsy 2021-02-15 21:20:48 +00:00
Mark Felder
8aff687053 Rename to make it more obvious 2021-02-15 21:16:21 +00:00
Mark Felder
05c96187e6 Work around inability to change format of files without an extension 2021-02-15 21:01:04 +00:00
Mark Felder
43bde2d4e7 Update Mogrify to 0.8.0
Better error handling with save/2 and create/2
2021-02-15 20:59:20 +00:00
Mark Felder
e531a0dd57 Add filter for HEIF (.heic) files to convert them to JPEGs 2021-02-12 17:48:26 -06:00
Mark Felder
f2c5c763c3 heic file also not supported well by ExifTool yet 2021-02-12 17:48:06 -06:00
6 changed files with 90 additions and 4 deletions

View File

@ -69,7 +69,7 @@ unit-testing:
alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
script:
- apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
- apt-get update && apt-get install -y libheif-examples libimage-exiftool-perl ffmpeg
- mix deps.get
- mix ecto.create
- mix ecto.migrate
@ -103,7 +103,7 @@ unit-testing-rum:
<<: *global_variables
RUM_ENABLED: "true"
script:
- apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
- apt-get update && apt-get install -y libheif-examples libimage-exiftool-perl ffmpeg
- mix deps.get
- mix ecto.create
- mix ecto.migrate
@ -239,7 +239,7 @@ amd64-musl:
cache: *release-cache
variables: *release-variables
before_script: &before-release-musl
- apk add git gcc g++ musl-dev make cmake file-dev
- apk add git gcc g++ musl-dev make cmake file-dev libheif-tools
- echo "import Mix.Config" > config/prod.secret.exs
- mix local.hex --force
- mix local.rebar --force

View File

@ -53,6 +53,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Ability to define custom HTTP headers per each frontend
- MRF (`NoEmptyPolicy`): New MRF Policy which will deny empty statuses or statuses of only mentions from being created by local users
- New users will receive a simple email confirming their registration if no other emails will be dispatched. (e.g., Welcome, Confirmation, or Approval Required)
- Added Pleroma.Upload.Filter.HeifToJpeg to automate converting .heic files from Apple devices to JPEGs which can be viewed in browsers. Requires heic-convert tool from libheif.
<details>
<summary>API Changes</summary>

View File

@ -162,7 +162,8 @@ defmodule Pleroma.ApplicationRequirements do
filter_commands_statuses = [
check_filter(Pleroma.Upload.Filters.Exiftool, "exiftool"),
check_filter(Pleroma.Upload.Filters.Mogrify, "mogrify"),
check_filter(Pleroma.Upload.Filters.Mogrifun, "mogrify")
check_filter(Pleroma.Upload.Filters.Mogrifun, "mogrify"),
check_filter(Pleroma.Upload.Filters.HeifToJpeg, "heic-convert")
]
preview_proxy_commands_status =

View File

@ -0,0 +1,44 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.HeifToJpeg do
@behaviour Pleroma.Upload.Filter
alias Pleroma.Upload
@type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
@type conversions :: conversion() | [conversion()]
@spec filter(Pleroma.Upload.t()) :: {:ok, :atom} | {:error, String.t()}
def filter(
%Pleroma.Upload{name: name, path: path, tempfile: tempfile, content_type: "image/heic"} =
upload
) do
try do
name = name |> String.replace_suffix(".heic", ".jpg")
path = path |> String.replace_suffix(".heic", ".jpg")
convert(tempfile)
{:ok, :filtered, %Upload{upload | name: name, path: path, content_type: "image/jpeg"}}
rescue
e in ErlangError ->
{:error, "#{__MODULE__}: #{inspect(e)}"}
end
end
def filter(_), do: {:ok, :noop}
defp convert(tempfile) do
with_extension = tempfile <> ".heic"
jpeg = tempfile <> ".jpg"
File.rename!(tempfile, with_extension)
args = [with_extension, jpeg]
{_, 0} = System.cmd("heif-convert", args)
File.rm!(with_extension)
File.rename!(jpeg, tempfile)
end
end

BIN
test/fixtures/image.heic vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,40 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload.Filter.HeifToJpegTest do
use Pleroma.DataCase, async: true
alias Pleroma.Upload.Filter
test "apply HeicToJpeg filter" do
assert Pleroma.Utils.command_available?("heif-convert")
File.cp!(
"test/fixtures/image.heic",
"test/fixtures/heictmp"
)
upload = %Pleroma.Upload{
name: "image.heic",
content_type: "image/heic",
path: Path.absname("test/fixtures/image.heic"),
tempfile: Path.absname("test/fixtures/heictmp")
}
{:ok, :filtered, result} = Filter.HeifToJpeg.filter(upload)
assert result.content_type == "image/jpeg"
assert result.name == "image.jpg"
assert String.ends_with?(result.path, "jpg")
assert {:ok,
%Majic.Result{
content:
"JPEG image data, JFIF standard 1.02, resolution (DPI), density 96x96, segment length 16, progressive, precision 8, 1024x768, components 3",
encoding: "binary",
mime_type: "image/jpeg"
}} == Majic.perform(result.path, pool: Pleroma.MajicPool)
on_exit(fn -> File.rm!("test/fixtures/heictmp") end)
end
end