Skip to content
This repository has been archived by the owner on Nov 23, 2018. It is now read-only.

Include pngquant in image optimization process #37

Open
cmalven opened this issue Mar 11, 2012 · 3 comments
Open

Include pngquant in image optimization process #37

cmalven opened this issue Mar 11, 2012 · 3 comments

Comments

@cmalven
Copy link

cmalven commented Mar 11, 2012

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
Copy link
Author

cmalven commented Mar 11, 2012

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
Copy link
Member

(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
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants