h5bp / ant-build-script

Ant build script intended for use with HTML5 Boilerplate. You may find something useful here, but this project is archived.
MIT License
985 stars 204 forks source link

Include pngquant in image optimization process #37

Open cmalven opened 12 years ago

cmalven commented 12 years ago

A site I'm currently working on makes very heavy use of transparent PNGs, and I've found that by running pngquant on the entire project I can get tremendous savings in file size.

I'm sure you see where I'm going with this. I'd love to have the build script do this for me. It seems like it would be pretty simple, and I've already taken an unsuccessful stab at it:

<echo message="Now, we run pngquant on the .png files for much smaller files..."/>

<apply executable="${basedir}/${dir.build.tools}/pngquant.exe" dest="./${dir.publish}/${dir.images}/" osfamily="unix">
    <fileset dir="./${dir.source}/${dir.images}/" includes="**/*.png"  excludes="${images.bypass}, ${images.default.bypass}"/>
    <arg value="-ext .png -force"/>
    <arg value="256"/>
    <targetfile/>
    <srcfile/>
    <mapper type="identity"/>
</apply>

-ext .png -force forces a replace of the existing files, and 256 sets the amount of colors to use. These are the only args I've ever needed for pngquant.

The "pngquant.exe" is in the place it should be. In fact, the build script is finding it and displaying the "help" for it, but then the script just hangs which makes me think my settings somewhere else are incorrect. I know nothing about working with Ant, and the documentation is pretty intimidating (the Ant documentation, not the HTML5BP docs, which are great).

Anybody have any ideas?

cmalven commented 12 years ago

Okay, I'm getting somewhere.

Removing the -ext .png -force arg successfully processes the images and copies them to the publish folder. However, it actually process the images in the original img directory, and leaves them there! Which is not good at all, because it means that we're modifying the original project.

Also, each pngquant pass in the build script outputs this to the terminal:

[apply]   error:  cannot open /Users/blah/project/publish/img/contact-form-bg-left.png for reading
[apply] Result: 2
roblarsen commented 12 years ago

(back from a crummy weekend)

I found this:

https://github.com/znerd/pngquant-ant-task

Might be of use.

I'll try to take a look after I clean up #36

roblarsen commented 11 years ago

I'm going to look at adding this as an optional task, but in a later release.