#!/usr/bin/env python # Make vertical text rollovers with this plugin # Copyright (C) 2006 Tom Lechner # # 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 2 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, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. from gimpfu import * import time # take text blocks delimited by 3 spaces. each block gets its own # vertical version and vertical highlighted version # via the alien glow plugin def python_vertical_rollovers(text,fontsize,color,hcolor,save,dosnippet,snippetfile): #if !text : get text from current layer? # take text, # make normal with 2 spaces between words # guillotine textchunks=text.split(" "); images=[] font=pdb.gimp_context_get_font() gapdims=pdb.gimp_text_get_extents_fontname(" ", fontsize, #size 0, #GIMP_PIXELS font) for c in range(0,len(textchunks)): dims=pdb.gimp_text_get_extents_fontname(textchunks[c], fontsize, #size 0, #GIMP_PIXELS font) width=dims[0] height=dims[1] iwidth=width + gapdims[0] iheight=height + gapdims[0] newimage=pdb.gimp_image_new(iwidth,iheight,0) #GIMP_RGB) #layer=pdb.gimp_layer_new(newimage,iwidth,iheight,0,c,100,0) #pdb.gimp_context_set_foreground((128,128,128,128)) #pdb.gimp_drawable_fill(layer,0); #pdb.gimp_image_add_layer(newimage,layer,0) pdb.gimp_context_set_foreground(color) textlayer=pdb.gimp_text_fontname( newimage, None, #layer, (iwidth-width)/2,(iheight-height)/2, textchunks[c], -1, #border TRUE, #anitalias fontsize, #size 0, #GIMP_PIXELS font) pdb.gimp_layer_resize_to_image_size(textlayer) print "Layer:",textlayer, " text:",textlayer #pdb.gimp_image_add_layer(newimage,textlayer,0) pdb.gimp_display_new(newimage) pdb.gimp_selection_none(newimage) pdb.gimp_image_rotate(newimage,2) images.append(newimage) pngdefs=pdb.file_png_get_defaults() for c in range(0,len(images)): drawable=images[c].active_layer if (save) : pdb.gimp_image_set_filename(images[c],"v-"+textchunks[c]+".png") pdb.file_png_save2( images[c], drawable, "v-"+textchunks[c]+".png", "v-"+textchunks[c]+".png", pngdefs[0], #interlace pngdefs[1], #comp pngdefs[2], #bkgd pngdefs[3], #gama pngdefs[4], #offs pngdefs[5], #phys pngdefs[6], #time pngdefs[7], #comment pngdefs[8] #svtrans ) pdb.gimp_edit_copy(drawable) newimage=pdb.gimp_image_duplicate(images[c]) drawable=newimage.active_layer pdb.script_fu_alien_glow_logo_alpha( #0, newimage, drawable, gapdims[0]*2, #**** hcolor, #glow color ) sel=pdb.gimp_edit_paste(drawable,0) pdb.gimp_floating_sel_anchor(sel) #layers=pdb.gimp_image_get_layers(images[c]) #print "----",len(layers), layers[1],images[c].layers[2],drawable layer=newimage.layers[2] pdb.gimp_drawable_set_visible(layer,0) pdb.gimp_image_merge_visible_layers(newimage,1) drawable=newimage.layers[0] pdb.gimp_display_new(newimage) if (save) : pdb.gimp_image_set_filename(newimage,"v-"+textchunks[c]+"-h.png") pdb.file_png_save2( newimage, drawable, "v-"+textchunks[c]+"-h.png", "v-"+textchunks[c]+"-h.png", pngdefs[0], #interlace pngdefs[1], #comp pngdefs[2], #bkgd pngdefs[3], #gama pngdefs[4], #offs pngdefs[5], #phys pngdefs[6], #time pngdefs[7], #comment pngdefs[8] #svtrans ) if (dosnippet==False) : return try: f=open(snippetfile,'w') except IOError: print "Problem opening",snippetfile+", not saving code." return print range(len(images)-1,-1,-1) for c in range(len(images)-1,-1,-1): print c width= images[c].width height=images[c].height print 'Go to '+textchunks[c]+'
\n' f.write('Go to '+textchunks[c]+'
\n' ) register( "python_fu_vertical_rollover", "Make vertical text rollovers", "Chop up text on each 2 space boundary. Make each chunk vertical text, then save as plain "+ "and highlighted png rollovers in v-[text].png and v-[text]-h.png. Optionally write an "+ "html code fragment that has most of the rollover stuff. You must manually modify the"+ "links that each button should point to.", "Tom Lechner", "Tom Lechner", "2006", "/Xtns/Python-Fu/Vertical rollovers", "RGB*", [ (PF_STRING, "text", "Text", ""), #(PF_FONT, "font", "Font", "Sans"), (PF_INT, "fontsize", "Font Size", 13), (PF_COLOR, "color", "Text Color", (0,0,0)), (PF_COLOR, "hcolor", "Highlight Color", (0x76,0xb3,0xd0)), (PF_BOOL, "save", "Save to files automatically", True), (PF_BOOL, "html", "Write rollover code", True), (PF_STRING, "htmlfile", "Rollover code file", "rollovercode.html") ], [], python_vertical_rollovers) main()