Linux圖片處理 -- ddjvu和convert命令

Yanfei90發表於2012-08-18

一、簡介

ddjvu是linux下處理djvu圖片的常用命令,該命令不是linux自帶的shell命令,需要額外進行安裝之後才能夠使用,ddjvu主要實現djvu圖片的格式裝換和切割等功能。convert命令的功能更加的強大,在linux中使用man convert來檢視給命令時,它給出了這樣的解釋:

convert - convert between image formats as well as resize an image, 
          blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

足以說明其功能的多樣性,是linux下處理圖片的常用工具。

二、安裝

1、ddjvu的安裝

     1) 下載djvulibre-x.x.x.x.tar.gz原始碼;

     2) 使用tar命令解壓上面下載的原始碼;

     3) 進入解壓後的目錄,並執行 ./configure,如果成功則進行下一步,否則根據提示進行處理;

     4) 執行make && make install 命令(或者分開執行)

注:安裝完djvulibre之後我們可以發現,系統中增加了不止ddjvu一個命令,其他命令也有很大的用處,想djvudump命令可以方便的得到djvu圖片的資訊等,這些命令可以再需要的時候進行檢視。

2、 convert的安裝

在Redhat / Centos / Fedora中我們直接使用

yum install ImageMagick
而在ubuntu / Debian中我們可以使用

apt-get install ImageMagick

在ubuntu上如果發現存在依賴包的問題,可以使用下面安裝命令:

aptitude install imagemagick

三、使用

ddjvu和convert命令的功能非常的強大,在這裡直接將linux中的幫助文件貼在下面,以便查詢相應的功能:

1、ddjvu

NAME
       ddjvu - Command line DjVu decoder.
SYNOPSIS
       ddjvu -format=fmt [options] [djvufile] [outputfile]
DESCRIPTION
       Decode the DjVu file djvufile, produces the image file outputfile.
       The DjVu data is read from the standard input when argument djvufile is not specified or when it is equal to a single dash.  Similarly, the output data is written to the standard output when argument outputfile is not specified or equal to a single dash.  However a valid output file name is always required when producing  a  TIFF or PDF file.
MAIN OPTIONS
       -format=fmt

              Specify the output file formats.  The recognized file formats are pbm, pgm, ppm, pnm, rle, tiff, and pdf.
              *  Formats  pbm, pgm, and ppm respectively produce a Portable Bitmap (PBM), Portable Graymap (PGM), or Portable Pixmap (PGM) file.  Format pnm produces a PBM, PGM, or PPM output file according to the color content of the output image.
              *  Format rle produces a compact run length encoded bitonal file that is understood by the DjVuLibre commands cjb2 and csepdjvu.
              *  Format tiff produces a Tagged Image Format (TIFF) file.  The resulting file uses the best available lossless compression model.  Enabling lossy  JPEG  compression (see option -quality below) often produces much smaller files.  Commands tiffcp(1) and tiffsplit(1) are useful for manipulating the resulting TIFF files.
              *  Format pdf produces a Portable Document Format (PDF) file.  Each page in the resulting file is represented by an image at the specified  resolution,  using the  best  available lossless compression model.  Enabling lossy JPEG compression (see option -quality below) often produces much smaller files.  An alternate way to produce PDF file consists in first using djvups(1) and convert the resulting PostScript file to PDF.  Which method gives better results depends on the contents of the DJVU file and on the capabilities of the PS to PDF converter.
              When  option  -format  is  not specified, the extension of argument outputfile has no influence on the default output format.  Instead the program behavior is modified to ensure backward compatibility with previous versions of ddjvu.  We recommend to always specify the output format using this option.
       -page=pagespec
              Specify which pages should be decoded.  When this option is not specified, all pages of the documents are decoded and concatenated into the output file.   The page  specification pagespec contains one or more comma-separated page ranges.A page range is either a page number,or two page numbers separated by a dash. For instance, specification 1-10 outputs pages 1 to 10, and specification 1,3,99999-4 outputs pages 1 and 3, followed by all the  document  pages  in  reverse order up to page 4.
       -mode=mod
              Selects which layers of the DjVu image should be rendered.  Valid rendering modes are color, black, mask, foreground, and background.
              *  Rendering  mode  color  is  the default mode.  When the DjVu file is bitonal, bitonal or gray-level output is produced depending on the subsampling factor. Otherwise a color image is produced.
              *  Rendering mode black is useful to extract a meaningful black and white image.  bitonal or gray-level output is produced depending on the  subsampling  factor.
              *  Rendering  modes  mask,  foreground,  and  background  select specific layers of a DjVu image.  These modes can fail if the DjVu image does not contain the selected layer.
       -skip  Instead of aborting when encountering a corrupted page, this option causes ddjvu to simply skip the corrupted page and continue with the next.  This is useful for processing certain damaged files.
RESOLUTION OPTIONS
       The following options control the resolution of the output image.  The default resolution is the native resolution of the DjVu file, equivalent to selecting -1.
       -n     Specify an integer sub-sampling factor.  The dimensions of the full output image will be n times smaller than the DjVu image size.  The legal values for argument n range from 1 to 12.  Option -1, for instance, produces an output image whose resolution is equal to the resolution of the input DjVu image file.
       -subsample=n
              This is equivalent to option -n.
       -scale=mag
              Specify a magnification factor relative to the resolution stored in the DjVu image.  Specifying magnification of 100 produces an image suitable for displaying on  a  100  dpi device such as a computer screen.  The magnification factor mag can also be interpreted as the resolution of the output image expressed in dot per inch.
       -size=wxh
              Specify the size of the full output image.  Rendering the full DjVu image would create an output image whose width and height would not exceed w  and  h.   To change the aspect ratio, you must also use option -aspect=no.
       -aspect=yesno
              This  option  indicates whether the image aspect ratio should be preserved.  The defaults is to preserve the aspect ration. This option permits changes in the aspect ratio when used in combination with option -size.
OTHER OPTIONS
       -verbose

              Display informational messages describing the structure of the DjVu image and the format of the output file.
       -segment=wxh+x+y
              Specify an image segment to render.  Program ddjvu conceptually renders the full page using the specified resolution, and then extracts a sub-image of width w and  height h, starting at position (x,y) relative to the bottom left corner of the page.  Both operations of course happen simultaneously.  Rendering a small sub-image is much faster than rendering the complete image.  The output file will always have size wxh when this option is specified.
       -quality=factor
              Enables lossy compression in TIFF and PDF files.  Without this option, TIFF or PDF output files always use lossless compression or no  compression.   Argument factor  specifies  a  JPEG  quantization factor ranging from 25 to 150. See command cjpeg(1) for more information on JPEG quantization factors.  Value 80 is a good starting point.
       -quality=uncompressed
              Completely disables compression in TIFF and PDF files.  Although the resulting files are often huge, this is sometimes useful for maximal  compatibility  with hastily written software.

DEPRECATED OPTIONS
       Various  options  have  been  maintained  to  ensure  backward compatibility with previous versions of ddjvu.  When option -format is not specified, the program only decodes the first page of the document and the default resolution becomes -scale=100.  Options -size, -scale, -segment, and -page accept an argument separated  by  a space.  Options -foreground, -background, and -black are shorthands for the -mode=mod option.  Please do not rely on these features.
EXAMPLES
       Command: ddjvu -format=tiff myfile.djvu myfile.tif
       decodes all pages and produces a multipage TIFF file.
       Command: ddjvu -format=ppm -page=1 -size=100x100 myfile.djvu -
       produces a thumbnail for the first page of a document and outputs it as a PPM file on the standard output.

2、convert

NAME
       convert - convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.
SYNOPSIS
       convert [input-options] input-file [output-options] output-file
OVERVIEW
       The  convert  program  is  a member of the ImageMagick(1) suite of tools.  Use it to convert between image formats as well as resize an image, blur, crop, despeckle,
       dither, draw on, flip, join, re-sample, and much more.
DESCRIPTION
       Image Settings:
         
-adjoin                               join images into a single multi-image file
         -affine matrix                    affine transform matrix
         -antialias                          remove pixel-aliasing
         -authenticate value         decrypt image with this password
         -background color          background color
         -bias value                      add bias when convolving an image
         -black-point-compensation            use black point compensation
         -blue-primary point       chromaticity blue primary point
         -bordercolor color         border color
         -caption string               assign a caption to an image
         -cdl filename                 color correct with a color decision list
         -channel type                 apply option to select image channels
         -colors value                  preferred number of colors in the image
         -colorspace type           alternate image colorspace
         -comment string           annotate image with comment
         -compose operator      set image composite operator
         -compress type             type of pixel compression when writing the image
         -decipher filename       convert cipher pixels to plain pixels
         -define format:option                    define one or more image format options
         -delay value                   display the next image after pausing
         -density geometry         horizontal and vertical density of the image
         -depth value                   image depth
         -display server              get image or font from this X server
         -dispose method          layer disposal method
         -dither method               apply error diffusion to image
         -encipher filename       convert plain pixels to cipher pixels
         -encoding type               text encoding type
          -endian type                   endianness (MSB or LSB) of the image
         -family name                  render text with this font family
         -fill color                          color to use when filling a graphic primitive
         -filter type                        use this filter when resizing an image
         -flatten                            flatten a sequence of images
         -font name                     render text with this font
         -format "string"              output formatted image characteristics
         -fuzz distance                colors within this distance are considered equal
         -gravity type                    horizontal and vertical text placement
         -green-primary point    chromaticity green primary point
         -intent type                      type of rendering intent when managing the image color
         -interlace type                type of image interlacing scheme
         -interpolate method      pixel color interpolation method
         -label string                    assign a label to an image
         -limit type value              pixel cache resource limit
         -loop iterations               add Netscape loop extension to your GIF animation
         -mask filename             associate a mask with the image
         -matte                              store matte channel if the image has one
         -mattecolor color           frame color
         -monitor                          monitor progress
         -orient type                      image orientation
         -origin geometry             image origin
         -page geometry             size and location of an image canvas (setting)
         -ping                                 efficiently determine image attributes
         -pointsize value             font point size
         -preview type                  image preview type
         -quality value                 JPEG/MIFF/PNG compression level
         -quiet                               suppress all warning messages
         -red-primary point         chromaticity red primary point
         -regard-warnings          pay attention to warning messages
         -sampling-factor geometry                 horizontal and vertical sampling factor
         -scene value                   image scene number
         -seed value                    seed a new sequence of pseudo-random numbers
         -size geometry               width and height of image
         -stretch type                    render text with this font stretch
         -stroke color                   graphic primitive stroke color
         -strokewidth value        graphic primitive stroke width
         -style type                       render text with this font style
         -support factor              resize support: > 1.0 is blurry, < 1.0 is sharp
         -texture filename          name of texture to tile onto the image background
         -tile-offset geometry     tile offset
         -treedepth value           color tree depth
         -transparent-color color                transparent color
         -undercolor color          annotation bounding box color
         -units type                      the units of image resolution
          -verbose                        print detailed information about the image
         -view                               FlashPix viewing transforms
         -virtual-pixel method                      virtual pixel access method
         -weight type                   render text with this font weight
         -white-point point         chromaticity white point
       Image Operators:
         -adaptive-blur geometry                adaptively blur pixels; decrease effect near edges
         -adaptive-resize geometry            adaptively resize image with data dependent triangulation
         -adaptive-sharpen geometry        adaptively sharpen pixels; increase effect near edges
         -annotate geometry text                 annotate the image with text
         -auto-orient                   automatically orient image
         -black-threshold value                    force all pixels below the threshold into black
         -blur geometry             reduce image noise and reduce detail levels
         -border geometry        surround image with a border of color
         -charcoal radius          simulate a charcoal drawing
         -chop geometry           remove pixels from the image interior
         -clip                               clip along the first path from the 8BIM profile
         -clip-mask filename  associate a clip mask with the image
         -clip-path id                  clip along a named path from the 8BIM profile
         -colorize value            colorize the image with the fill color
         -contrast                      enhance or reduce the image contrast
         -contrast-stretch geometry               improve contrast by `stretching' the intensity range
         -convolve coefficients                       apply a convolution kernel to the image
         -cycle amount           cycle the image colormap
         -despeckle                reduce the speckles within an image
         -draw string               annotate the image with a graphic primitive
         -edge radius             apply a filter to detect edges in the image
         -emboss radius       emboss an image
         -enhance                   apply a digital filter to enhance a noisy image
         -equalize                    perform histogram equalization to an image
         -evaluate operator value                    evaluate an arithmetic, relational, or logical expression
         -extent geometry       set the image size
         -extract geometry      extract area from image
         -fft                                 implements the discrete Fourier transform (DFT)
         -flip                               flip image vertically
         -floodfill geometry color                      floodfill the image with color
         -flop                             flop image horizontally
          -frame geometry      surround image with an ornamental border
         -function name          apply a function to the image
         -gamma value           level of gamma correction
         -gaussian-blur geometry                    reduce image noise and reduce detail levels
         -geometry geometry        preferred size or location of the image
         -identify                      identify the format and characteristics of the image
         -ift                                implements the inverse discrete Fourier transform (DFT)
         -implode amount            implode image pixels about the center
         -lat geometry            local adaptive thresholding
         -layers method        optimize or compare image layers
         -level value               adjust the level of image contrast
         -linear-stretch geometry                     improve contrast by `stretching with saturation' the intensity range
         -median radius        apply a median filter to the image
         -modulate value       vary the brightness, saturation, and hue
         -monochrome          transform image to black and white
         -morphology method kernel               apply a morphology method to the image
         -motion-blur geometry                         simulate motion blur
         -negate                      replace each pixel with its complementary color
         -noise radius            add or reduce noise in an image
         -normalize                 transform image to span the full range of colors
         -opaque color           change this color to the fill color
         -ordered-dither NxN                              add a noise pattern to the image with specific amplitudes
         -paint radius             simulate an oil painting
         -polaroid angle         simulate a Polaroid picture
         -posterize levels       reduce the image to a limited number of color levels
         -print string                interpret string and print to console
         -profile filename      add, delete, or apply an image profile
         -quantize colorspace       reduce colors in this colorspace
         -radial-blur angle     radial blur the image
         -raise value               lighten/darken image edges to create a 3-D effect
         -random-threshold low,high                random threshold the image
         -recolor matrix          translate, scale, shear, or rotate image colors
         -region geometry             apply options to a portion of the image
         -render                      render vector graphics
         -repage geometry            size and location of an image canvas
         -resample geometry       change the resolution of an image
         -resize geometry              resize the image
         -roll geometry                    roll an image vertically or horizontally
         -rotate degrees                 apply Paeth rotation to the image
         -sample geometry            scale image with pixel sampling
         -scale geometry                scale the image
         -segment values               segment an image
         -selective-blur geometry                         selectively blur pixels within a contrast threshold
         -sepia-tone threshold                             simulate a sepia-toned photo
         -set property value            set an image property
         -shade degrees                 shade the image using a distant light source
         -shadow geometry            simulate an image shadow
         -sharpen geometry            sharpen the image
         -shave geometry                shave pixels from the image edges
         -shear geometry                 slide one edge of the image along the X or Y axis
         -sigmoidal-contrast geometry                 lightness rescaling using sigmoidal contrast enhancement
         -sketch geometry              simulate a pencil sketch
         -solarize threshold            negate all pixels above the threshold level
         -splice geometry                splice the background color into the image
         -spread amount                 displace image pixels by a random amount
         -strip                                     strip image of all profiles and comments
         -swirl degrees          swirl image pixels about the center
         -threshold value       threshold the image
         -thumbnail geometry         create a thumbnail of the image
         -tile filename             tile image when filling a graphic primitive
         -tint value                   tint the image with the fill color
         -transform                 affine transform image
         -transparent color    make this color transparent within the image
         -transpose                 flip image vertically and rotate 90 degrees
         -transverse                flop image horizontally and rotate 270 degrees
         -trim                             trim image edges
         -type type                    image type
         -unique-colors          discard all but one of any pixel color
         -unsharp geometry          sharpen the image
         -vignette geometry            soften the edges of the image in vignette style
         -wave geometry                alter an image along a sine wave
         -white-threshold value     force all pixels above the threshold into white
       Image Sequence Operators:
         -affinity filename         transform image colors to match this set of colors
         -append                       append an image sequence
         -clut                               apply a color lookup table to the image
         -coalesce                     merge a sequence of images
         -combine                      combine a sequence of images
         -composite                   composite image
         -crop geometry            cut out a rectangular region of the image
         -deconstruct                 break down an image sequence into constituent parts
         -evaluate-sequence operator           evaluate an arithmetic, relational, or logical expression
         -flatten                           flatten a sequence of images
         -fx expression              apply mathematical expression to an image channel(s)
         -hald-clut                       apply a Hald color lookup table to the image
         -morph value               morph an image sequence
         -mosaic                        create a mosaic from an image sequence
         -process arguments                           process the image with a custom image filter
         -separate                      separate an image channel into a grayscale image
         -write filename             write images to this file
       Image Stack Operators:
         -clone index                  clone an image
         -delete index                 delete the image from the image sequence
         -insert index                  insert last image into the image sequence
         -swap indexes              swap two images in the image sequence
       Miscellaneous Options:
         -debug events              display copious debugging information
         -help                               print program options
         -log format                     format of debugging information
         -list type                          print a list of supported option arguments
         -version                           print version information
       By default, the image format of `file' is determined by its magic number.  To specify a particular image format, precede the filename with an image format name and a colon (i.e. ps:image) or specify the image type as the filename suffix (i.e. image.ps).  Specify 'file' as '-' for standard input or output.

相關文章