Skip to content

Instantly share code, notes, and snippets.

@tabrindle
Created September 12, 2013 13:34
Show Gist options
  • Save tabrindle/6537410 to your computer and use it in GitHub Desktop.
Save tabrindle/6537410 to your computer and use it in GitHub Desktop.
#! /usr/bin/python
# Author: Trevor A Brindle
# Copyright: Trevor A Brindle (2012), licensed under the GPL v 3.0
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gimpfu import *
def plugin_main(timg, tdrawable, appName, ipadRetinaRes, ipadNonRetinaRes, iphone4, iphone5, iphone):
pdb.gimp_image_undo_group_start(timg)
firstimagechangetotext = timg.duplicate()
text_layer = firstimagechangetotext.layers[1]
pdb.gimp_text_layer_set_text(text_layer, appName)
testwidth = timg.width
testheight = timg.height
if testwidth < testheight:
portrait = TRUE
else:
portrait = FALSE
newimage = firstimagechangetotext.duplicate()
newimage.flatten()
ipadRetinaRes = newimage.duplicate()
ipadNonRetinaRes = newimage.duplicate()
retinaiphoneimage = newimage.duplicate()
tallretinaiphoneimage = newimage.duplicate()
iphoneimage = newimage.duplicate()
if ipadRetinaRes:
#print("ipadRetinaRes")
if portrait:
#print("portrait")
new_width = 1536
new_height = 2008
filename = "Default-Portrait@2x.png"
pdb.gimp_image_scale(ipadRetinaRes, new_width, new_height)
pdb.file_png_save_defaults(ipadRetinaRes, ipadRetinaRes.active_layer, filename, filename)
else:
#print("landscape")
new_width = 2048
new_height = 1496
filename = "Default-Landscape@2x.png"
pdb.gimp_image_scale(ipadRetinaRes, new_width, new_height)
pdb.file_png_save_defaults(ipadRetinaRes, ipadRetinaRes.active_layer, filename, filename)
if ipadNonRetinaRes:
#print("ipadNonRetinaRes")
if portrait:
#print("portrait")
new_width = 768
new_height = 1004
filename = "Default-Portrait.png"
npimage = pdb.gimp_image_scale(ipadNonRetinaRes, new_width, new_height)
pdb.file_png_save_defaults(ipadNonRetinaRes, ipadNonRetinaRes.active_layer, filename, filename)
else:
#print("landscape")
new_width = 1024
new_height = 748
filename = "Default-Landscape.png"
pdb.gimp_image_scale(ipadNonRetinaRes, new_width, new_height)
pdb.file_png_save_defaults(ipadNonRetinaRes, ipadNonRetinaRes.active_layer, filename, filename)
if iphone4:
#print("ipadNonRetinaRes")
if portrait:
temp_width = 734
temp_height = 960
final_width = 640
final_height = 960
offx = 0
offy = 0
filename = "Default@2x~iphone.png"
pdb.gimp_image_scale(retinaiphoneimage, temp_width, temp_height)
pdb.gimp_image_crop(retinaiphoneimage, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(retinaiphoneimage, retinaiphoneimage.active_layer, filename, filename)
if iphone5:
#print("ipadNonRetinaRes")
if portrait:
temp_width = 869
temp_height = 1136
final_width = 640
final_height = 1136
offx = 0
offy = 0
filename = "Default-568h@2x.png"
pdb.gimp_image_scale(tallretinaiphoneimage, temp_width, temp_height)
pdb.gimp_image_crop(tallretinaiphoneimage, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(tallretinaiphoneimage, tallretinaiphoneimage.active_layer, filename, filename)
if iphone:
#print("ipadNonRetinaRes")
if portrait:
temp_width = 367
temp_height = 480
final_width = 320
final_height = 480
offx = 0
offy = 0
filename = "Default~iphone.png"
pdb.gimp_image_scale(iphoneimage, temp_width, temp_height)
pdb.gimp_image_crop(iphoneimage, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(iphoneimage, iphoneimage.active_layer, filename, filename)
pdb.gimp_image_undo_group_end(timg)
register(
"brindle_ios_spashscreen_gen",
"Input a template file, specify text and generate multiple Splash Screens for different resolutions",
"Help Info",
"Trevor A Brindle",
"Trevor A Brindle 2012 GPL v3.0",
"2012",
"<Image>/Filters/_iOS SplashScreen Generator...",
"",
[
(PF_STRING, "appName", "Name of Application (Max 18 Characters)", ""),
(PF_TOGGLE, "ipadRetinaRes", "Retina iPad", TRUE),
(PF_TOGGLE, "ipadNonRetinaRes", "Non-Retina iPad", TRUE),
(PF_TOGGLE, "iphone4", "Retina iPhone", TRUE),
(PF_TOGGLE, "iphone5", "Very Tall Retina iPhone", TRUE),
(PF_TOGGLE, "iphone", "Non-Retina iPhone", TRUE),
],
[],
plugin_main
)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment