Skip to content

Instantly share code, notes, and snippets.

@error454
Created May 2, 2014 23:52
Show Gist options
  • Save error454/3e15c7fd26f9a875a419 to your computer and use it in GitHub Desktop.
Save error454/3e15c7fd26f9a875a419 to your computer and use it in GitHub Desktop.
Steam Achievement Image Converter
-- Author: Zachary Burke
-- License: MIT
--
-- Steam Achievement Image Converter
--
-- /-----------\ ----> Color JPG
-- (Color PNG) ----> |This script|
-- \-----------/ ----> Grayscale JPG
--
-- Each Steam Achievement requires two 64x64 JPG files. One image for the unachieved state and the
-- other for the achieved state. It is recommended that the achieved state be in color while the
-- unachieved state be grayscale.
--
-- This script goes through all PNG files in a folder and generates the two required JPG files
-- for each image.
-- REQUIREMENTS:
-- * ImageMagick installed and in your path. The "convert" command is used. Note that windows
-- also has a convert command in the path that is not at all the same thing!
--
lfs = require "lfs"
--
-- Return true if the given file is a png
--
function fileIsPNG ( sFilename )
if sFilename then
return string.match ( string.lower ( sFilename ), ".png" ) ~= nil
end
return false
end
--
-- Returns filename, ext for a given file
--
function getFileNameAndExtension ( sFilename )
if sFilename then
-- match (anything not a .).(anything not a .)
for k, v in string.gmatch ( sFilename, "([^\.]+)\.([^\.]+)" ) do
return k, v
end
end
return nil, nil
end
--
-- Loop through all files in the current folder
--
for file in lfs.dir('.') do
--
-- For each PNG found:
-- 1. Convert it to a .jpg with the same filename
-- 2. Convert it to a desaturated .jpg with the appended text "_off"
-- ex. level1.png -> level1_off.jpg
--
if fileIsPNG ( file ) then
local sName, sExt = getFileNameAndExtension ( file )
if sName and sExt then
-- 1.
os.execute ( 'convert "' .. file .. '" "' .. sName .. '.jpg"' )
-- 2.
os.execute ( 'convert "' .. file .. '" -colorspace Gray "' .. sName .. '_off.jpg"' )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment