影像

已棄用

此任務已棄用,因為 Java Advanced Image API 依賴在 Java 9 中已移除的內部類別。請改用 ImageIO 任務。

說明

對一組檔案套用一系列影像操作。

需要 Sun 的 Java Advanced Image API

已使用資料型態的概觀
ImageOperation class diagram A diagram of Ant DataType classes used by Image task. org.apache.tools.ant.types.DataType ImageOperation instructions : Vector addRotate(Rotate : instr) addDraw(Draw : instr) addText(Text : instr) addScale(Scale : instr) The setType() method forces type to one of the values of java.awt.geom.Arc2D: open = Arc2D.OPEN pie = Arc2D.PIE chord = Arc2D.CHORD Parameter is not case-sensitive. BasicShape stroke_width : int = 0 fill : String = "transparent" stroke : String = "black" TransformOperation executeTransformOperation(PlanarImage img) : PlanarImage addRectangle(Rectangle instr) <<interface>> DrawOperation executeDrawOperation() : PlanarImage The implementing class uses ColorMapper to evaluate the color. Only the values defined in ColorMapper are used. ColorMapper COLOR_BLACK : String = "black" COLOR_BLUE : String = "blue" COLOR_CYAN : String = "cyan" COLOR_DARKGRAY : String = "darkgray" COLOR_GRAY : String = "gray" COLOR_LIGHTGRAY : String = "lightgray" COLOR_DARKGREY : String = "darkgrey" COLOR_GREY : String = "grey" COLOR_LIGHTGREY : String = "lightgrey" COLOR_GREEN : String = "green" COLOR_MAGENTA : String = "magenta" COLOR_ORANGE : String = "orange" COLOR_PINK : String = "pink" COLOR_RED : String = "red" COLOR_WHITE : String = "white" COLOR_YELLOW : String = "yellow" Text string : String = "" font : String = "Arial" point : int = 10 bold : boolean = false color : String = "black" italic : boolean = false Rotate angle : float = 0.0F Scale width : String = "100%" height : String = "100%" keepProportions : boolean = false Draw xloc : int = 0 yloc : int = 0 addEllipse(Ellipse elip) addArc(Arc arc) Rectangle height : int = 0 width : int = 0 archeight : int = 0 arcwidth : int = 0 Ellipse height : int = 0 width : int = 0 Arc height : int = 0 width : int = 0 start : int = 0 stop : int = 0 type : enumerated = open

參數

屬性 說明 必要
failonerror 布林值。如果為 false,會將錯誤記錄到輸出,但會繼續執行。 否;預設為 true
srcdir 包含影像的目錄。 是,除非使用巢狀檔案集
encoding 影像編碼類型。
有效值(不分大小寫):jpgjpegtiftiff
否;預設為 jpeg
overwrite 布林值。設定是否在命名衝突時覆寫檔案。 否;預設為 false
gc 布林值。在處理完每張影像後啟用垃圾回收。 否;預設為 false
destdir 儲存結果影像的目錄。 否;預設為 srcdir 的值
includes 必須包含的檔案模式清單,以逗號或空格分隔。 否;預設為全部 (**)
includesfile 檔案名稱。此檔案的每一行都會視為包含模式
excludes 必須排除的檔案模式清單,以逗號或空格分隔。 否;如果 defaultexcludesno,預設為預設排除或無
excludesfile 檔案名稱。此檔案的每一行都會視為排除模式
defaultexcludes 表示是否應使用預設排除 (yes|no)。 否;預設為 yes
caseSensitive 布林值。設定檔案系統的大小寫敏感性。 否;預設為 false
followSymlinks 布林值。設定是否應追蹤符號連結。 否;預設為 true

指定為巢狀元素的參數

此任務會形成一個隱含的 FileSet,並支援 <fileset> 的大多數屬性,以及巢狀的 <include><exclude><patternset> 元素。

下列 ImageOperation 物件可以指定為巢狀元素:RotateScaleDraw

Rotate

將 Rotate ImageOperation 加入鏈結。

參數
屬性 說明 必要
角度 浮點數值。設定旋轉角度(以度為單位)。 否;預設為 0.0F

縮放

新增縮放 ImageOperation 至鏈。

參數
屬性 說明 必要
比例 設定控制比例的維度。有效值為
  • ignore—獨立處理維度。
  • height—根據寬度保持比例。
  • width—根據高度保持比例。
  • cover—保持比例並符合提供的維度。
  • fit—保持比例並覆蓋提供的維度。
否;預設為 ignore
寬度 設定影像寬度,可以是整數(畫素)或 %。 否;預設為 100%
高度 設定影像高度,可以是整數(畫素)或 %。 否;預設為 100%

繪製

新增繪製 ImageOperation 至鏈。DrawOperation DataType 物件可以巢狀在 Draw 物件內。

參數
屬性 說明 必要
xloc 繪製巢狀影像元素的 X 座標。 否;預設為 0
yloc 繪製巢狀影像元素的 Y 座標。 否;預設為 0

有關巢狀元素的說明,請參閱 ImageIO 任務 的文件。

對應程式

自 Apache Ant 1.8.0 起

您可以使用巢狀 對應程式 元素定義檔名轉換。<image> 使用的預設對應程式是 身分對應程式

您也可以使用 filenamemapper 類型取代 mapper 元素。

範例

建立我的影像縮圖,並確保它們都符合 160×160 畫素大小,無論影像為直幅或橫幅。

<image destdir="samples/low" overwrite="yes">
    <fileset dir="samples/full">
        <include name="**/*.jpg"/>
    </fileset>
    <scale width="160" height="160" proportions="fit"/>
</image>

src 中所有 PNG 檔案建立縮圖,大小為 40 畫素,並保持比例,並儲存 src

<image srcdir="src" includes="*.png">
    <scale proportions="width" width="40"/>
</image>

與上述相同,但將結果儲存在 dest 中。

<image srcdir="src" destdir="dest" includes="*.png">
    <scale proportions="width" width="40"/>
</image>

與上述相同,但將結果儲存在檔名以 scaled- 為前綴的檔案中。

<image srcdir="src" destdir="dest" includes="*.png">
    <scale proportions="width" width="40"/>
    <globmapper from="*" to="scaled-*"/>
</image>