Skip to content

Commit

Permalink
Disregard stderr output from identify command. Fixes issue #206
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Scherpenisse committed Sep 8, 2011
1 parent 21dd694 commit 6c59701
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/support/z_media_identify.erl
Expand Up @@ -161,11 +161,11 @@ identify_file_os(unix, File, OriginalFilename) ->
%% @doc Try to identify the file using image magick
identify_file_imagemagick(ImageFile) ->
CleanedImageFile = z_utils:os_filename(ImageFile ++ "[0]"),
Result = os:cmd("identify -quiet " ++ CleanedImageFile),
Result = os:cmd("identify -quiet " ++ CleanedImageFile ++ " 2>/dev/null"),
% ["test/a.jpg","JPEG","3440x2285","3440x2285+0+0","8-bit","DirectClass","2.899mb"]
% sometimes:
% test.jpg[0]=>test.jpg JPEG 2126x1484 2126x1484+0+0 DirectClass 8-bit 836.701kb 0.130u 0:02
Line1 = first_non_warning(string:tokens(Result, "\r\n")),
Line1 = hd(string:tokens(Result, "\r\n")),
Words = string:tokens(Line1, " "),
WordCount = length(Words),
Words1 = if
Expand Down Expand Up @@ -194,16 +194,6 @@ identify_file_imagemagick(ImageFile) ->
{error, "unknown result from 'identify': '"++Line1++"'"}
end.

% Even with '-quiet' we still can get pdf warnings, strip them.
first_non_warning([]) ->
[];
first_non_warning([Line|Lines]) ->
case string:strip(Line, left) of
[] -> first_non_warning(Lines);
"****" ++ _ -> first_non_warning(Lines);
_ -> Line
end.


%% @spec mime(String) -> MimeType
%% @doc Map the type returned by ImageMagick to a mime type
Expand Down

0 comments on commit 6c59701

Please sign in to comment.