2016/05/20

轉檔 Convert multi JPG PNG GIF image files into a single PDF file easily by ImageMagick on OSX Linux Cygwin

I found a simple approach "ImageMagick" could
我發現「ImageMagick」軟體能完成以下事項:
Apple convert JPG PNG PDF to PDF by ImageMagick on OSX
Besides, ImageMagick also works on other Unix systems, and even on cygwin.
此外,「ImageMagick」也能在其他的 Unix 或 Cygwin 內使用。

安裝 Install ImageMagick through Homebrew


開啟一個終端機後,輸入以下命令安裝 ImageMagick。
Launch a terminal and install ImageMagick through Homebrew:
sunjose$ brew install imagemagick
==> Installing dependencies for imagemagick: xz, libtool, jpeg, libpng, l
==> Installing imagemagick dependency: xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.1.yosemite.bottle.ta
######################################################################## 100.0%
==> Pouring xz-5.2.1.yosemite.bottle.tar.gz
🍺 /usr/local/Cellar/xz/5.2.1: 59 files, 1.7M
==> Installing imagemagick dependency: libtool
==> Downloading https://homebrew.bintray.com/bottles/libtool-2.4.6.yosemite.bott
######################################################################## 100.0%
==> Pouring libtool-2.4.6.yosemite.bottle.tar.gz
==> Caveats
In order to prevent conflicts with Apple's own libtool we have prepended a "g"
so, you have instead: glibtool and glibtoolize.

==> Summary
🍺 /usr/local/Cellar/libtool/2.4.6: 69 files, 3.8M
==> Installing imagemagick dependency: jpeg
==> Downloading https://homebrew.bintray.com/bottles/jpeg-8d.yosemite.bottle.2.t
######################################################################## 100.0%
==> Pouring jpeg-8d.yosemite.bottle.2.tar.gz
🍺 /usr/local/Cellar/jpeg/8d: 18 files, 776K
==> Installing imagemagick dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.17.yosemite.bott
######################################################################## 100.0%
==> Pouring libpng-1.6.17.yosemite.bottle.tar.gz
🍺 /usr/local/Cellar/libpng/1.6.17: 17 files, 1.2M
==> Installing imagemagick dependency: libtiff
==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.0.4.yosemite.bott
######################################################################## 100.0%
==> Pouring libtiff-4.0.4.yosemite.bottle.tar.gz
🍺 /usr/local/Cellar/libtiff/4.0.4: 257 files, 3.9M
==> Installing imagemagick dependency: freetype
==> Downloading https://homebrew.bintray.com/bottles/freetype-2.6_1.yosemite.bot
######################################################################## 100.0%
==> Pouring freetype-2.6_1.yosemite.bottle.tar.gz
🍺 /usr/local/Cellar/freetype/2.6_1: 60 files, 2.6M
==> Installing imagemagick
==> Downloading https://homebrew.bintray.com/bottles/imagemagick-6.9.1-9.yosemit
######################################################################## 100.0%
==> Pouring imagemagick-6.9.1-9.yosemite.bottle.tar.gz
🍺 /usr/local/Cellar/imagemagick/6.9.1-9: 1447 files, 22M


轉檔 convert multi .jpg, .gif, or .png image files into a single .pdf file by ImageMagick


After installed ImageMagick, you can use "convert" command to convert mult .jpg image files in a Terminal.
安裝「ImageMagick」後,你可以在終端機使用「convert」命令轉換數個 .jpg 圖片檔。
sunjose$ convert *.jpg output.pdf
sunjose$ ls
Document-page-001.jpg Document-page-003.jpg Document-page-005.jpg
Document-page-002.jpg Document-page-004.jpg Document-page-006.jpg
output.pdf


If the resulting PDF is a bit too big and you would like to convert .png files, you can change file format as png and try "quality" option to reduce quality.
如果結果的檔案有點大、你也想轉換成 .png 檔,你可以改變檔案格式成 png 並加入 quality 的選項以降低圖片品質。
sunjose$ convert -quality 60 *.png output.pdf

You can also get ImageMagick to read images based on a list of numbers. For example..
你也可以使「ImageMagick」依照順序讀取圖片,例如:
  • Convert test-0.png to test-9.png to input_10.pdf.
    轉檔 test-0.png 至 test-9.png 成為 input_10.pdf。
    sunjose$ convert 'test-%01d.png[0-9]' input_10.pdf
  • Convert test-10.png to test-20.png to input_10.pdf.
    轉檔 test-10.png 至 test-20.png 成為 input_10.pdf。
    sunjose$ convert 'test-%02d.png[10-20]' input_20.pdf

轉檔 Convert a pdf file to mulit .jpg, .gif, or .png files by ImageMagick


You also could convert a pdf file into mulit .jpg, .gif, or .png files by ImageMagick directly.
你也可以直接透過「ImageMagick」將一個 .pdf 檔轉換成數個 .jpg、.gif 或 .png 圖片檔。
sunjose$ ls
input.pdf
sunjose$ convert input.pdf test.png
sunjose$ ls *.png
test-0.png test-17.png test-24.png test-31.png test-39.png test-46.png test-7.png
test-10.png test-18.png test-25.png test-32.png test-3.png test-47.png test-8.png
test-11.png test-19.png test-26.png test-33.png test-40.png test-48.png test-9.png
test-12.png test-1.png test-27.png test-34.png test-41.png test-49.png
test-13.png test-20.png test-28.png test-35.png test-42.png test-4.png
test-14.png test-21.png test-29.png test-36.png test-43.png test-50.png
test-15.png test-22.png test-2.png test-37.png test-44.png test-5.png
test-16.png test-23.png test-30.png test-38.png test-45.png test-6.png
sunjose$


You also could convert a pdf file into mulit .jpg, .gif, or .png files with 2 decimal digits by ImageMagick.
你也可以透過「ImageMagick」將一個 .pdf 檔轉換成數個二位數十進位編號的 .jpg、.gif 或 .png 圖片檔。
sunjose$ ls
input.pdf
sunjose$ convert input.pdf 'test-%02d.jpg'
sunjose$ ls *.jpg
test-00.jpg test-08.jpg test-16.jpg test-24.jpg test-32.jpg test-40.jpg test-48.jpg
test-01.jpg test-09.jpg test-17.jpg test-25.jpg test-33.jpg test-41.jpg test-49.jpg
test-02.jpg test-10.jpg test-18.jpg test-26.jpg test-34.jpg test-42.jpg test-50.jpg
test-03.jpg test-11.jpg test-19.jpg test-27.jpg test-35.jpg test-43.jpg
test-04.jpg test-12.jpg test-20.jpg test-28.jpg test-36.jpg test-44.jpg
test-05.jpg test-13.jpg test-21.jpg test-29.jpg test-37.jpg test-45.jpg
test-06.jpg test-14.jpg test-22.jpg test-30.jpg test-38.jpg test-46.jpg
test-07.jpg test-15.jpg test-23.jpg test-31.jpg test-39.jpg test-47.jpg


轉換特定頁面 Convert the specific pages of a pdf file to mulit .jpg, .gif, or .png image files by ImageMagick


You could convert the specific page of a pdf file to mulit .jpg, .gif, or .png image files. For example.
你也能轉換 .pdf 檔的特定頁面成數個 .jpg、.gif 或 .png 圖片檔。例如:
  • Convert the first page of pdf file.
    轉換 .pdf 檔的第一頁(封面)。
    sunjose$ convert input.pdf'[0]' first_page_of_pdf.jpg
  • Convert the second to fourth page of pdf file.
    轉換 .pdf 檔的第二頁至第四頁。
    sunjose$ convert animation.gif'[1-3]' second_to_fourth_frames.gif

沒有留言:

張貼留言