Commits

Marc Worrell committed 1379e41

Fix for black background when previewing transparent images as jpeg.

Comments (0)

Files changed (2)

src/support/tests/z_media_preview_tests.erl

 cmd_args_jpeg_test() ->
     Props = [{width,100}, {height,66}, {mime,"image/jpeg"}, {orientation,1}],
     Filters = [{crop,center}, {width,80}, {height,80}],
-    {_W,_H,Args} = z_media_preview:cmd_args(Props, Filters),
+    {_W,_H,Args} = z_media_preview:cmd_args(Props, Filters, "image/jpeg"),
     CmdArgs = lists:flatten(z_utils:combine(32, Args)),
     ?assertEqual("-background \"white\" -layers \"flatten\"   -gravity West -extent 122x80 -thumbnail 122x80\\! -gravity NorthWest -crop 80x80+21+0 +repage -colorspace \"RGB\"   -unsharp 0.3x0.7  -quality 99",
                  CmdArgs).
 cmd_args_gif_test() ->
     Props = [{width,100}, {height,66}, {mime,"image/gif"}, {orientation,1}],
     Filters = [{crop,center}, {width,80}, {height,80}],
-    {_W,_H,Args} = z_media_preview:cmd_args(Props, Filters),
+    {_W,_H,Args} = z_media_preview:cmd_args(Props, Filters, "image/gif"),
     CmdArgs = lists:flatten(z_utils:combine(32, Args)),
     ?assertEqual("-coalesce   -gravity West -extent 122x80 -thumbnail 122x80\\! -gravity NorthWest -crop 80x80+21+0 +repage -colorspace \"RGB\"   -quality 99",
                  CmdArgs).

src/support/z_media_preview.erl

     can_generate_preview/1,
 	out_mime/2,
     string2filter/2,
-    cmd_args/2,
+    cmd_args/3,
     calc_size/7
 ]).
 
             {mime, Mime} = proplists:lookup(mime, FileProps),
             case can_generate_preview(Mime) of
                 true ->
-                    {EndWidth, EndHeight, CmdArgs} = cmd_args(FileProps, Filters),
+                    OutMime = z_media_identify:guess_mime(OutFile),
+                    {EndWidth, EndHeight, CmdArgs} = cmd_args(FileProps, Filters, OutMime),
                     z_utils:assert(EndWidth  < ?MAX_WIDTH, image_too_wide),
                     z_utils:assert(EndHeight < ?MAX_HEIGHT, image_too_high),
                     Args1   = lists:flatten(z_utils:combine(32, CmdArgs)),
 
 
 %% @doc Map filters to commandline options
-cmd_args(FileProps, Filters) ->
+cmd_args(FileProps, Filters, OutMime) ->
     {width, ImageWidth}   = proplists:lookup(width, FileProps),
     {height, ImageHeight} = proplists:lookup(height, FileProps),
     {mime, Mime0} = proplists:lookup(mime, FileProps),
                              end
                end,
     Filters4 = case proplists:get_value(background, Filters3) of
-                    undefined -> default_background(Mime) ++ Filters3;
+                    undefined -> default_background(OutMime) ++ Filters3;
                     _ -> Filters3
                end,