@@ -6345,8 +6345,9 @@ defmodule Image do
63456345 size due to the removal of most EXIF and all
63466346 IPTC and XMP metadata.
63476347
6348- Note that the minimized metadata is only materialized when
6349- the minimized image is saved to a file.
6348+ > #### Note {: .info}
6349+ >
6350+ > the minimized metadata is only materialized when the minimized image is saved.
63506351
63516352 ### Arguments
63526353
@@ -6363,16 +6364,28 @@ defmodule Image do
63636364
63646365 @ spec minimize_metadata ( image :: Vimage . t ( ) ) :: { :ok , Vimage . t ( ) } | { :error , error_message ( ) }
63656366 def minimize_metadata ( % Vimage { } = image ) do
6366- with { :ok , exif } <- exif ( image ) ,
6367- { :ok , image } <- remove_metadata ( image ) do
6368- Vimage . mutate ( image , fn mut_img ->
6369- if exif [ :copyright ] , do: Exif . put_metadata ( mut_img , :copyright , exif [ :copyright ] )
6370- if exif [ :artist ] , do: Exif . put_metadata ( mut_img , :artist , exif [ :artist ] )
6371- :ok
6372- end )
6367+ case exif ( image ) do
6368+ { :ok , exif } ->
6369+ image
6370+ |> remove_metadata! ( )
6371+ |> put_copyright_and_artist ( exif )
6372+
6373+ { :error , "No such field" } ->
6374+ remove_metadata ( image )
6375+
6376+ other ->
6377+ other
63736378 end
63746379 end
63756380
6381+ defp put_copyright_and_artist ( image , exif ) do
6382+ Vimage . mutate ( image , fn mut_img ->
6383+ if exif [ :copyright ] , do: Exif . put_metadata ( mut_img , :copyright , exif [ :copyright ] )
6384+ if exif [ :artist ] , do: Exif . put_metadata ( mut_img , :artist , exif [ :artist ] )
6385+ :ok
6386+ end )
6387+ end
6388+
63766389 @ doc """
63776390 Minimize metadata by keeping only the artist
63786391 and copyright (if available).
0 commit comments