Skip to content

Instantly share code, notes, and snippets.

@xenolito
Last active June 20, 2024 08:56
Show Gist options
  • Save xenolito/df26acd88e23e3b24c6f3a98ebaa1f75 to your computer and use it in GitHub Desktop.
Save xenolito/df26acd88e23e3b24c6f3a98ebaa1f75 to your computer and use it in GitHub Desktop.

Revisions

  1. xenolito revised this gist Jun 20, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion imagemagick_cli.md
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ On the following example, will output files autonumber starting from 5 (05,06,07
    `convert *.png -quality 100 document.pdf`

    ### Batch convert to webp to different output directory
    `mogrify -format webp -quality 80 -resize 1940 -path ./resized *.JPG`
    `mogrify -format webp -quality 80 -resize 1940 -path ./resized *.jpg`

    ### Convert png to ICO
    `convert apple-touch-favicon.png favicon.ico`
  2. xenolito revised this gist Jun 7, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions imagemagick_cli.md
    Original file line number Diff line number Diff line change
    @@ -41,3 +41,6 @@ On the following example, will output files autonumber starting from 5 (05,06,07

    ### Batch convert to webp to different output directory
    `mogrify -format webp -quality 80 -resize 1940 -path ./resized *.JPG`

    ### Convert png to ICO
    `convert apple-touch-favicon.png favicon.ico`
  3. xenolito revised this gist Apr 13, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions imagemagick_cli.md
    Original file line number Diff line number Diff line change
    @@ -38,3 +38,6 @@ On the following example, will output files autonumber starting from 5 (05,06,07

    ### Convert images to pdf
    `convert *.png -quality 100 document.pdf`

    ### Batch convert to webp to different output directory
    `mogrify -format webp -quality 80 -resize 1940 -path ./resized *.JPG`
  4. xenolito created this gist Mar 13, 2023.
    40 changes: 40 additions & 0 deletions imagemagick_cli.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    ### 5) IMAGES: RESIZING WITH IMAGE MAGICK CLI:

    #### Resize and compress by 85% and autonumeral (%02d -> two digits)
    `magick *.jpg -resize 1440 -quality 85 ./resized/AH_000003-%02d.jpg`


    #### Rotate 90 degrees if height > width
    `convert input.jpg -rotate 90< output.jpg`

    #### Save the output file with the same filename as original (after rotating the image on this example)
    `-set filename:f` --> key we want to set
    `'%t'` --> value we assign to the previous key. %t is a shortcut to retrieve the filename. The long form is `%[basename]`

    `magick planos/*.jpg -rotate '-90<' -set filename:f '%t' planos/'%[filename:f].png'`

    #### Save the output file containing the directory name on its filename. The input file must contain the direcoty on its path, so you must be one level up...

    ```
    $~/Desktop >
    magick AH_000007/*.jpg -resize 1440 -quality 85 -set filename:myname '%d' AH_000007/resized/'%[filename:myname]-%02d.jpg'
    ```

    The output file names will be something like:
    `AH_000007-01.jpg`
    `AH_000007-02.jpg`
    `AH_000007-....jpg`


    #### Resize and output to a different folder with same file names
    `mogrify -resize 1440 -quality 85 -path ./resized *.jpg`


    #### Output filename autonumber starting from a specific value.
    Using the -scene [number] flag, where [number] is the number where the automatic count starts from.
    On the following example, will output files autonumber starting from 5 (05,06,07...)
    `magick AH_000032/*.jpg -resize 1440 -quality 85 -scene 5 -set filename:myname '%d' AH_000032/resized/'%[filename:myname]-%02d.jpg'`


    ### Convert images to pdf
    `convert *.png -quality 100 document.pdf`