#!/usr/bin/env python # # Copyright (c) 2011 The Novice Oof # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # #------------------------------------------------------------------------------ # import math from gimpfu import * import os def python_facebook_tag_banner(timg, tdrawable, hsize, format): #def some utility functions def selectNone(image): pdb.gimp_selection_none(image) def selectRect(image,x,y,xsize,ysize): #... op, feather, radius pdb.gimp_rect_select(image,x,y,xsize,ysize,0,False,0) def copyRect(layer,x,y,xsize,ysize): srcimg = layer.image selectNone(srcimg) selectRect(srcimg,x,y,xsize,ysize) pdb.gimp_edit_copy(layer) srcimg = tdrawable.image width = srcimg.width height = srcimg.height #checking the source image is saved somewhere if srcimg.filename == None: gimp.message("Source image not saved anywhere, cowardly refusing to save images anywhere") return False # verify the dimensions of the if not(abs(width/float(height)-7.2)<0.1): print width,height gimp.message("Need an image with an aspect ratio of 7.2, instead of "+str(width/float(height))) return False dw = int(round(width/5.0)) image_size = (hsize,int(400/527.*hsize)) # how big the final image is scale_factor =(int(hsize*400/527.),int(hsize*278/527.)) #how big to scale the usable area # dupe the image workimg = srcimg.duplicate() selectNone(workimg) # flatten or merge? flat_layer = workimg.flatten() #flat_layer = pdb.gimp_image_merge_visible_layers(workimg,0) for i in range(5): # set up a working image img = gimp.Image(image_size[0],image_size[1],RGB) copyRect(flat_layer,i*dw,0,dw,height) # create new layer layer = gimp.Layer(img, "Copy1", image_size[0], image_size[1], RGBA_IMAGE, 100, NORMAL_MODE) #100 for opacity img.add_layer(layer,0) pdb.gimp_edit_fill(layer, BACKGROUND_FILL) # grab the relevant part of the image paste = pdb.gimp_edit_paste(layer,False) paste.scale(scale_factor[0],scale_factor[1]) pdb.gimp_layer_set_offsets(paste,0,0) pdb.gimp_floating_sel_anchor(paste) # save the image f = os.path.splitext(srcimg.filename)[0]+str(i+1)+"."+format if format=="png": pdb.file_png_save_defaults(img,layer,f,f) if format=="jpg": # using jpeg defaults, Ubuntu 10.10 pdb.file_jpeg_save(img,layer,f,f,0.9,0.0,1,0,"Made with Facebook Tag Banner Generator by The Novice Oof",0,0,0,0) # clean up img.clean_all() gimp.delete(img) #clean up workimg.clean_all() gimp.delete(workimg) #------------------------------------------ register( "python_fu_facebook_tag_banner", "Generates a series of images suitable for tag banners on facebook from one ~7.2 aspect ratio image, saved as a series of pngs", "In: A 7.2 aspect ratio'd image. Out: A series of images ready to upload", "thenoviceoof", "thenoviceoof", "2011/1", "/Filters/Web/F_acebook Tag Banner...", "RGB*, GRAY*", [ (PF_SLIDER,"hsize","Output Image Width (in px, total)",360,(200,500,20)), (PF_RADIO,"format","File Format","png",(("_png","png"), ("_jpg","jpg"))), ], [], python_facebook_tag_banner) main()