0

I am trying to run an apply task with the following command:

  jpegtran.exe -copy none -optimize -perfect ./images/file.jpg ./images/file.jpg

I would like to apply it recursively for all images. I have tried the following ant code but jpegtran says invalid arguments.

<target name="optimize.images.jpg">
    <apply executable="jpegtran.exe" dir="${SRC_DIR}/public/assets/" parallel="false" verbose="true" resolveexecutable="true" force="true" vmlauncher="true">
        <arg value="-copy none"/>
        <arg value="-optimize"/>
        <arg value="-perfect"/>
        <srcfile/>
        <targetfile/>
        <fileset dir="${SRC_DIR}/public/assets/images" casesensitive="yes">
            <include name="**/*.jpg"/>
        </fileset>
        <mapper type="identity"/>
    </apply>
</target>

What could be wrong with my ant code?

dextervip
  • 4,999
  • 16
  • 65
  • 93

1 Answers1

-1

One item that needs to be changed is the nested <arg> element for -copy none. Since there is a space in the argument, use the line attribute instead of value. See Apache Ant command line arguments.

<target name="optimize.images.jpg">
  <apply executable="jpegtran.exe" dir="${SRC_DIR}/public/assets/" 
    parallel="false" verbose="true" resolveexecutable="true" force="true" 
    vmlauncher="true">

    <arg line="-copy none"/>
    <arg value="-optimize"/>
    <arg value="-perfect"/>
    <srcfile/>
    <targetfile/>
    <fileset dir="${SRC_DIR}/public/assets/images" casesensitive="yes">
      <include name="**/*.jpg"/>
    </fileset>
    <mapper type="identity"/>
  </apply>
</target>
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
  • I changed it and I got optimize.images.jpg: Applied C:\htdocs\project\public\assets\jpegtran.exe to 6 files and 0 directories. but it didn't has any effect on my files. – dextervip Jul 07 '12 at 00:45
  • @dextervip, I'm glad that changing the nested `` element fixed the problem posted in your question! I have never used `jpegtran.exe`, but have you confirmed that it works when you run it from the command line directly (that is, without using Ant)? – Christopher Peisert Jul 07 '12 at 00:57
  • Yes I just ran and it worked. I don't know if ant is giving corret path of files. – dextervip Jul 07 '12 at 01:03
  • The paths in your `fileset` can be tested by following [these instructions](http://stackoverflow.com/a/1456898/1164465). – Christopher Peisert Jul 07 '12 at 01:07
  • I changed dist attribute from apply task and now works. Thank you – dextervip Jul 07 '12 at 03:07
  • I think this does not work without specifing the `-outfile` argument. – David Nov 26 '15 at 11:42