創建 ImageMagick Linux 腳本 (Create ImageMagick Linux script)


問題描述

創建 ImageMagick Linux 腳本 (Create ImageMagick Linux script)

I have an imagemagick convert command that I use from the shell and I would like to create a linux exec to run it, so I don't have to always run this.

I am converting a PDF file to JPEG files, and this is what I use: convert ‑density 300 *.pdf  ‑alpha off ‑scale 1500x2000 ‑quality 70 jpegFiles.jpg

What I would like the linux exec file to do is run the above convert and instead of jpegFiles, to have the actual PDF filename. Of course, for every page jpeg file it would have  filename‑0.jpg, filename‑1.jpg, filename‑2.jpg, etc.

I am using Ubuntu. Thank you.

‑‑‑‑‑

參考解法

方法 1:

save this in a file and place it in a dir like $HOME/.bin eg. $HOME/.bin/pdf2jpg

for file in "$@"; do
    convert ‑density 300 "$file" ‑alpha off ‑scale 1500x2000 ‑quality 70 "${file%.*}‑%d.jpg"
done

make it executable

chmod +x $HOME/.bin/pdf2jpg

and add that dir to the PATH variable

echo "PATH=$PATH:$HOME/.bin" >> $HOME/.bash_profile    # assuming you use bash

create a dir named as your pdf along with ‑images suffix and place the files in there

for file in "$@"; do
    dir="${file%.*}‑images"
    mkdir ‑p "$dir"
    convert ‑density 300 "$file" ‑alpha off ‑scale 1500x2000 ‑quality 70 "$dir/${file%.*}‑%d.jpg"
done

(by ChrisNNc00kiemon5ter)

參考文件

  1. Create ImageMagick Linux script (CC BY‑SA 3.0/4.0)

#imagemagick #linux






相關問題

PHP ImageMagick setColorspace 不起作用 (PHP ImageMagick setColorspace not working)

從 Magick++ 圖像從內存 (libharu) 加載圖像 (Load Images from memory (libharu) from Magick++ images)

ImageMagick PDF to JPGs 有時會導致黑色背景 (ImageMagick PDF to JPGs sometimes results in black background)

使用 ImageMagick 改進從平面圖像到 3d 模型的轉換鏈 (Improve this conversion chain from flat images to 3d mockup with ImageMagick)

WampServer 和 Imagemagick,無法識別 imagick php 模塊 (WampServer and Imagemagick, imagick php module not recogized)

PHP Imagick - 顯示多圖像 TIFF 的第一片 (PHP Imagick - display first slice of mutli image TIFF)

打印 imagemagick 將輸出轉換為瀏覽器 (print imagemagick convert output to browser)

創建 ImageMagick Linux 腳本 (Create ImageMagick Linux script)

從照片生成漂亮的直方圖? (generating nice looking histogram from photo?)

iPhone中的imagemagick單色轉換 (imagemagick monochrome convert in iPhone)

為什麼從 PHP 腳本調用 (ImageMagick) convert.exe 會導致頁面無響應? (Why is calling (ImageMagick) convert.exe from PHP script resulting in an unresponsive page?)

如何使用 Python/ImageMagick/Wand 保存多層 PSD (How to save multi-layer PSD with Python/ImageMagick/Wand)







留言討論