Skip to content

Commit

Permalink
PERF: Pass the -ping option to the identify ImageMagick command t…
Browse files Browse the repository at this point in the history
…o speed it up (discourse#25697)

The `-ping` option significantly speeds up the ImageMagick `identify` command per our testing and the [documentation](https://imagemagick.org/script/command-line-options.php#ping):

> -ping
Efficiently determine these image characteristics: image number, the file name, the width and height of the image, whether the image is colormapped or not, the number of colors in the image, the number of bytes in the image, the format of the image (JPEG, PNM, etc.). Use +ping to ensure accurate image properties.

We already pass the `-ping` option in other places where the `identify` command is used, so it makes sense to use the option everywhere.

Internal topic: t/121431.
  • Loading branch information
OsamaSayegh authored Feb 15, 2024
1 parent 4deacc4 commit cfdb461
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def fix_dimensions!
begin
Discourse::Utils.execute_command(
"identify",
"-ping",
"-format",
"%w %h",
path,
Expand Down
2 changes: 1 addition & 1 deletion lib/upload_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def animated?
# Only GIFs, WEBPs and a few other unsupported image types can be animated
OptimizedImage.ensure_safe_paths!(@file.path)

command = ["identify", "-format", "%n\\n", @file.path]
command = ["identify", "-ping", "-format", "%n\\n", @file.path]
frames =
begin
Discourse::Utils.execute_command(*command, timeout: Upload::MAX_IDENTIFY_SECONDS).to_i
Expand Down

0 comments on commit cfdb461

Please sign in to comment.