Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small fixes

  • Loading branch information...
commit a14eb0190339a3e1806c44967a8ed47f21458b38 1 parent be6a23f
Marat Dyatko authored
View
43 smush/optimiser/formats/gif.py
@@ -47,32 +47,6 @@ def _is_animated(self, input):
"""
return self.animated_gif_optimiser._is_acceptable_image(input)
-
- def _keep_smallest_file(self, input, output):
- """
- Compares the sizes of two files, and discards the larger one
- """
- input_size = os.path.getsize(input)
- output_size = os.path.getsize(output)
-
- # if the image was optimised (output is smaller than input), overwrite the input file with the output
- # file.
- if (output_size < input_size):
- try:
- shutil.copyfile(output, input)
- self.files_optimised += 1
- self.bytes_saved += (input_size - output_size)
- except IOError:
- logging.error("Unable to copy %s to %s: %s" % (output, input, IOError))
- sys.exit(1)
-
- if self.iterations == 1 and not self.is_animated:
- self.converted_to_png = True
-
- # delete the output file
- os.unlink(output)
-
-
def _get_command(self):
"""
Returns the next command to apply
@@ -96,20 +70,3 @@ def _get_command(self):
self.iterations += 1
return command
-
- def _list_only(self, input, output):
- """
- Always keeps input, but still compares the sizes of two files
- """
- input_size = os.path.getsize(input)
- output_size = os.path.getsize(output)
-
- if (output_size > 0 and output_size < input_size):
- self.files_optimised += 1
- self.bytes_saved += (input_size - output_size)
- self.array_optimised_file.append(input)
- if self.iterations == 1 and not self.is_animated:
- self.convert_to_png = True
-
- # delete the output file
- os.unlink(output)
View
6 smush/optimiser/formats/jpg.py
@@ -16,10 +16,12 @@ def __init__(self, **kwargs):
# the command to execute this optimiser
if strip_jpg_meta:
self.commands = ('jpegtran -outfile "__OUTPUT__" -optimise -copy none "__INPUT__"',
- 'jpegtran -outfile "__OUTPUT__" -optimise -progressive "__INPUT__"')
+ 'jpegtran -outfile "__OUTPUT__" -optimise -progressive "__INPUT__"',
+ 'jpegoptim -f --strip-all "__OUTPUT__"')
else:
self.commands = ('jpegtran -outfile "__OUTPUT__" -optimise -copy all "__INPUT__"',
- 'jpegtran -outfile "__OUTPUT__" -optimise -progressive -copy all "__INPUT__"')
+ 'jpegtran -outfile "__OUTPUT__" -optimise -progressive -copy all "__INPUT__"',
+ 'jpegoptim -f --strip-all "__OUTPUT__"')
# format as returned by 'identify'
self.format = "JPEG"
View
8 smush/smush.py
@@ -175,7 +175,7 @@ def main():
strip_jpg_meta = False
exclude = ['.bzr', '.git', '.hg', '.svn']
list_only = False
- min_percent = 5
+ min_percent = 3
identify_mime = False
save_optimized = None
@@ -240,6 +240,8 @@ def usage():
Usage: """ + sys.argv[0] + """ [options] FILES...
+ Example: """ + sys.argv[0] + """ --strip-meta --list-only --save-optimized=DIR --recursive DIR
+
FILES can be a space-separated list of files or directories to optimise
**WARNING**: Existing images files will be OVERWRITTEN with optimised
@@ -252,9 +254,9 @@ def usage():
-s, --strip-meta Strip all meta-data from JPEGs
--exclude=EXCLUDES Comma separated value for excluding files
--identify-mime Fast identify image files via mimetype
-
+
--list-only Perform a trial run with no changes made
- --min-percent=INT Minimum percent of optimisation to warn about
+ --min-percent=INT Minimum percent of optimisation to warn about (default is > 3%)
--save-optimized=DIR Directory to save optimised files
"""
Please sign in to comment.
Something went wrong with that request. Please try again.