Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: hyde/hyde
...
head fork: vincentbernat/hyde
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 08, 2012
@vincentbernat vincentbernat jpegtran plugin (like jpegoptim plugin)
This plugin may seem redundant with jpegoptim one. jpegtran allows one
to produce progressive JPEG while jpegoptim does not. On the other
hand, jpegtran only does losless compression while jpegoptim allows
one to set a maximum quality setting.
90bce28
Showing with 66 additions and 0 deletions.
  1. +66 −0 hyde/ext/plugins/jpegtran.py
View
66 hyde/ext/plugins/jpegtran.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+"""
+jpegtran plugin
+
+Almost like jpegoptim except it uses jpegtran. jpegtran allows to make
+progressive JPEG. Unfortunately, it only does lossless compression. If
+you want both, you need to combine this plugin with jpegoptim one.
+"""
+
+from hyde.plugin import CLTransformer
+from hyde.fs import File
+
+class JPEGTranPlugin(CLTransformer):
+ """
+ The plugin class for JPEGTran
+ """
+
+ def __init__(self, site):
+ super(JPEGTranPlugin, self).__init__(site)
+
+ @property
+ def plugin_name(self):
+ """
+ The name of the plugin.
+ """
+ return "jpegtran"
+
+ def option_prefix(self, option):
+ return "-"
+
+ def binary_resource_complete(self, resource):
+ """
+ If the site is in development mode, just return.
+ Otherwise, run jpegtran to compress the jpg file.
+ """
+
+ try:
+ mode = self.site.config.mode
+ except AttributeError:
+ mode = "production"
+
+ if not resource.source_file.kind == 'jpg':
+ return
+
+ if mode.startswith('dev'):
+ self.logger.debug("Skipping jpegtran in development mode.")
+ return
+
+ supported = [
+ "optimize",
+ "progressive",
+ "restart",
+ "arithmetic",
+ "perfect",
+ "copy",
+ ]
+ source = File(self.site.config.deploy_root_path.child(
+ resource.relative_deploy_path))
+ target = File.make_temp('')
+ jpegtran = self.app
+ args = [unicode(jpegtran)]
+ args.extend(self.process_args(supported))
+ args.extend(["-outfile", unicode(target), unicode(source)])
+ self.call_app(args)
+ target.copy_to(source)
+ target.delete()

No commit comments for this range

Something went wrong with that request. Please try again.