Skip to content

Instantly share code, notes, and snippets.

@tabrindle
Created September 12, 2013 13:34
Show Gist options
  • Save tabrindle/6537401 to your computer and use it in GitHub Desktop.
Save tabrindle/6537401 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, androidldpi, androidmdpi, androidhdpi, androidxhdpi):
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()
androidldpi = newimage.duplicate()
androidmdpi = newimage.duplicate()
androidhdpi = newimage.duplicate()
androidxhdpi = newimage.duplicate()
if androidldpi:
if portrait:
#print("portrait")
temp_width = 245
temp_height = 320
final_width = 200
final_height = 320
offx = 0
offy = 0
filename = "android-ldpi-portrait.png"
pdb.gimp_image_scale(androidldpi, temp_width, temp_height)
pdb.gimp_image_crop(androidldpi, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(androidldpi, androidldpi.active_layer, filename, filename)
else:
#print("landscape")
temp_width = 320
temp_height = 245
final_width = 320
final_height = 200
offx = 0
offy = 0
filename = "android-ldpi-landscape.png"
pdb.gimp_image_scale(androidldpi, temp_width, temp_height)
pdb.gimp_image_crop(androidldpi, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(androidldpi, androidldpi.active_layer, filename, filename)
if androidmdpi:
if portrait:
#print("portrait")
temp_width = 367
temp_height = 480
final_width = 320
final_height = 480
offx = 0
offy = 0
filename = "android-mdpi-portrait.png"
pdb.gimp_image_scale(androidmdpi, temp_width, temp_height)
pdb.gimp_image_crop(androidmdpi, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(androidmdpi, androidmdpi.active_layer, filename, filename)
else:
#print("landscape")
temp_width = 480
temp_height = 367
final_width = 480
final_height = 320
offx = 0
offy = 0
filename = "android-mdpi-landscape.png"
pdb.gimp_image_scale(androidmdpi, temp_width, temp_height)
pdb.gimp_image_crop(androidmdpi, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(androidmdpi, androidmdpi.active_layer, filename, filename)
if androidhdpi:
if portrait:
#print("portrait")
temp_width = 612
temp_height = 800
final_width = 480
final_height = 800
offx = 0
offy = 0
filename = "android-hdpi-portrait.png"
pdb.gimp_image_scale(androidhdpi, temp_width, temp_height)
pdb.gimp_image_crop(androidhdpi, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(androidhdpi, androidhdpi.active_layer, filename, filename)
else:
#print("landscape")
temp_width = 800
temp_height = 612
final_width = 800
final_height = 480
offx = 0
offy = 0
filename = "android-hdpi-landscape.png"
pdb.gimp_image_scale(androidhdpi, temp_width, temp_height)
pdb.gimp_image_crop(androidhdpi, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(androidhdpi, androidhdpi.active_layer, filename, filename)
if androidxhdpi:
if portrait:
#print("portrait")
temp_width = 979
temp_height = 1280
final_width = 720
final_height = 1280
offx = 0
offy = 0
filename = "android-xhdpi-portrait.png"
pdb.gimp_image_scale(androidxhdpi, temp_width, temp_height)
pdb.gimp_image_crop(androidxhdpi, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(androidxhdpi, androidxhdpi.active_layer, filename, filename)
else:
#print("landscape")
temp_width = 1280
temp_height = 979
final_width = 1280
final_height = 720
offx = 0
offy = 0
filename = "android-xhdpi-landscape.png"
pdb.gimp_image_scale(androidxhdpi, temp_width, temp_height)
pdb.gimp_image_crop(androidxhdpi, final_width, final_height, offx, offy)
pdb.file_png_save_defaults(androidxhdpi, androidxhdpi.active_layer, filename, filename)
pdb.gimp_image_undo_group_end(timg)
register(
"brindle_android_spashscreen_gen",
"Input a template file, specify text and generate multiple Splash Screens for different resolutions of Android Devices",
"Help Info",
"Trevor A Brindle",
"Trevor A Brindle 2012 GPL v3.0",
"2012",
"<Image>/Filters/_Android SplashScreen Generator...",
"",
[
(PF_STRING, "appName", "Name of Application (Max 18 Characters)", ""),
(PF_TOGGLE, "androidldpi", "android-ldpi", TRUE),
(PF_TOGGLE, "androidmdpi", "android-mdpi", TRUE),
(PF_TOGGLE, "androidhdpi", "android-hdpi", TRUE),
(PF_TOGGLE, "androidxhdpi", "android-xhdpi", TRUE),
],
[],
plugin_main
)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment