Compare commits
22 Commits
feature/sa
...
feat/heif-
Author | SHA1 | Date | |
---|---|---|---|
|
016376dbf0 | ||
|
4b3f7a497f | ||
|
3c71a5038a | ||
|
5a358b31fe | ||
|
4adb9e8e2c | ||
|
b23cf2d149 | ||
|
14e52188af | ||
|
daba3b8522 | ||
|
9e0e2fb6b4 | ||
|
28253c4e4a | ||
|
889341d0d7 | ||
|
b40581c4e8 | ||
|
13b57f2cb3 | ||
|
d265c2c0f1 | ||
|
c6480eaf24 | ||
|
390b4471f2 | ||
|
d3cf505b42 | ||
|
8aff687053 | ||
|
05c96187e6 | ||
|
43bde2d4e7 | ||
|
e531a0dd57 | ||
|
f2c5c763c3 |
@ -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
|
||||
|
@ -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>
|
||||
|
@ -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 =
|
||||
|
44
lib/pleroma/upload/filter/heif_to_jpeg.ex
Normal file
44
lib/pleroma/upload/filter/heif_to_jpeg.ex
Normal 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
BIN
test/fixtures/image.heic
vendored
Normal file
Binary file not shown.
40
test/pleroma/upload/filter/heif_to_jpeg_test.exs
Normal file
40
test/pleroma/upload/filter/heif_to_jpeg_test.exs
Normal 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
|
Loading…
Reference in New Issue
Block a user