Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marat Dyatko committed Jul 9, 2012
1 parent be6a23f commit a14eb01
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 48 deletions.
43 changes: 0 additions & 43 deletions smush/optimiser/formats/gif.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,32 +47,6 @@ def _is_animated(self, input):
""" """
return self.animated_gif_optimiser._is_acceptable_image(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): def _get_command(self):
""" """
Returns the next command to apply Returns the next command to apply
Expand All @@ -96,20 +70,3 @@ def _get_command(self):
self.iterations += 1 self.iterations += 1


return command 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)
6 changes: 4 additions & 2 deletions smush/optimiser/formats/jpg.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ def __init__(self, **kwargs):
# the command to execute this optimiser # the command to execute this optimiser
if strip_jpg_meta: if strip_jpg_meta:
self.commands = ('jpegtran -outfile "__OUTPUT__" -optimise -copy none "__INPUT__"', 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: else:
self.commands = ('jpegtran -outfile "__OUTPUT__" -optimise -copy all "__INPUT__"', 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' # format as returned by 'identify'
self.format = "JPEG" self.format = "JPEG"
Expand Down
8 changes: 5 additions & 3 deletions smush/smush.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def main():
strip_jpg_meta = False strip_jpg_meta = False
exclude = ['.bzr', '.git', '.hg', '.svn'] exclude = ['.bzr', '.git', '.hg', '.svn']
list_only = False list_only = False
min_percent = 5 min_percent = 3
identify_mime = False identify_mime = False
save_optimized = None save_optimized = None


Expand Down Expand Up @@ -240,6 +240,8 @@ def usage():
Usage: """ + sys.argv[0] + """ [options] FILES... 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 FILES can be a space-separated list of files or directories to optimise
**WARNING**: Existing images files will be OVERWRITTEN with optimised **WARNING**: Existing images files will be OVERWRITTEN with optimised
Expand All @@ -252,9 +254,9 @@ def usage():
-s, --strip-meta Strip all meta-data from JPEGs -s, --strip-meta Strip all meta-data from JPEGs
--exclude=EXCLUDES Comma separated value for excluding files --exclude=EXCLUDES Comma separated value for excluding files
--identify-mime Fast identify image files via mimetype --identify-mime Fast identify image files via mimetype
--list-only Perform a trial run with no changes made --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 --save-optimized=DIR Directory to save optimised files
""" """


Expand Down

0 comments on commit a14eb01

Please sign in to comment.