It is currently Sun Aug 23, 2026 3:12 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: simple scripting assistance
PostPosted: Tue Nov 15, 2016 12:06 pm  (#1) 
Offline
New Member

Joined: Nov 15, 2016
Posts: 4
I am trying to put together an easy script to take an image, crop it to a preset image size and export as a .gif file. I have zero knowledge of coding. does anyone have any suggestions?

ultimately, I will have use for 2 dedicated size output options. this is for a specific production use. Any input is greatly appreciated.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: simple scripting assistance
PostPosted: Tue Nov 15, 2016 12:46 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I'll ask a question in an effort to get you to specify the requirement fully...

Do you mean "crop"? If so, then do you expect to have to specify the location of the crop as well as it's size, or are both position and size fixed?


Top
 Post subject: Re: simple scripting assistance
PostPosted: Tue Nov 15, 2016 12:50 pm  (#3) 
Offline
New Member

Joined: Nov 15, 2016
Posts: 4
this is an attempt to automate a process for my team.

We need to open a saved image, or paste into new from clipboard, crop to 270x65 and export as an indexed color .gif file.

the same process will be for a second file with 78x40 as those requests come up.

I know the steps to get there using the tools, but if I can set up some sort of script where my co-workers can click a button and everything is done except for naming the actual file, that would be a huge time savings.


Top
 Post subject: Re: simple scripting assistance
PostPosted: Tue Nov 15, 2016 1:32 pm  (#4) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16167
kd2494 wrote:
this is an attempt to automate a process for my team.

We need to open a saved image, or paste into new from clipboard, crop to 270x65 and export as an indexed color .gif file.

the same process will be for a second file with 78x40 as those requests come up.

I know the steps to get there using the tools, but if I can set up some sort of script where my co-workers can click a button and everything is done except for naming the actual file, that would be a huge time savings.


I believe Kevin wants to know if you intend to crop a certain area of the image because he will need the coordinates of that size to crop correctly each time. You see you will need the original x and y offsets to use the new user input x and y values.
Are you cropping from the center? Are you just resizing the image?

_________________
Image


Top
 Post subject: Re: simple scripting assistance
PostPosted: Tue Nov 15, 2016 1:39 pm  (#5) 
Offline
New Member

Joined: Nov 15, 2016
Posts: 4
my apologies. yes, we will mostly be resizing the image to the dimensions I entered above.


Top
 Post subject: Re: simple scripting assistance
PostPosted: Tue Nov 15, 2016 3:50 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Oct 06, 2010
Posts: 4050
Are you expecting to maintain the aspect ratio of these images?

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: simple scripting assistance
PostPosted: Tue Nov 15, 2016 3:53 pm  (#7) 
Offline
New Member

Joined: Nov 15, 2016
Posts: 4
90% of the time, aspect ratio will not be an issue. we will also not likely be using rasterized text. For those instances, there are enough of us on the team that are more versed in photo editing to handle those. My team has some photoshop savvy people on it. the rest of them are less knowledgeable so I am looking for something automated that they can copy/paste/run script and the only thing that is left to do is give it a file name.


Top
 Post subject: Re: simple scripting assistance
PostPosted: Wed Nov 16, 2016 4:30 am  (#8) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I'll have one more attempt at getting you to specify your requirements in sufficient detail, although others here with better psychic abilities maybe able to guess what you want better than I can...

The process is????
  1. Start with an image open in GIMP
  2. Select to run the script from a menu item/keyboard shortcut
  3. On the script dialog
    1. Select which size image you want to make from a list of options
    2. Enter the name of the file you want to create
  4. Run the script

Kevin


Top
 Post subject: Re: simple scripting assistance
PostPosted: Wed Nov 16, 2016 4:43 am  (#9) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2613
Yes, lots of maybe's

Cobbled together from a couple of scripts I use for scaling/saving screenshots.
This works (just) taking the OP requirements at face value. New image size is in line 9. New file takes the layer name. The only choice is the output folder and only once for any particular session.
What it does not do: lots & lots of things, eg. does not mark the image as clean.

I am sure all the clever guys will pull this into a thousand shards :)

edit: I can start that process myself: script works for me in linux, but crashes in Windows. Such is life

I put the missing escape in "\\" for windows, still crashes.

edit again: strangely, this works in a WinXP (virtual machine) with Gimp 2.8.4
I wonder what has changed from that old version?

edit again: Well the only way I can get my script working is by specifying an output path. (line 16) Obviously makes the export location dialog box redundant though.

#!/usr/bin/env python
#
from gimpfu import *

def save_to_files(timg, layer, outputFolder):


    pdb.gimp_context_set_interpolation(INTERPOLATION_LANCZOS)
    pdb.gimp_image_scale(timg, 270, 65)
    pdb.gimp_image_convert_indexed(timg, 0, 0, 256, 0, 0, "" )
   
    try:
       
        # Save as GIF
#        pdb.file_gif_save(timg, layer, outputFolder + "\\" + layer.name + ".gif", "raw_filename" ,0, 0, 0, 0 )
        pdb.file_gif_save(timg, layer, "c:\\Users\\Public\\Pictures\\" + layer.name +  ".gif" , "raw_filename" ,0, 0, 0, 0 )

    except Exception as err:
        gimp.message("Unexpected error: " + str(err))
   
register(
    "python_fu_save_to_files",
    "Save to files",
    "Save the current layer into a GIF file",
    "",
    "Open source",
    "2016",
    "<Image>/Tools/Save to GIF",
    "*",
    [
        (PF_DIRNAME, "outputFolder", "Output directory", ""),
    ],
    [],
    save_to_files)

main()


Last edited by rich2005 on Wed Nov 16, 2016 12:33 pm, edited 2 times in total.

Top
 Post subject: Re: simple scripting assistance
PostPosted: Wed Nov 16, 2016 6:43 am  (#10) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16167
rich2005 wrote:
Yes, lots of maybe's

Cobbled together from a couple of scripts I use for scaling/saving screenshots.
This works (just) taking the OP requirements at face value. New image size is in line 9. New file takes the layer name. The only choice is the output folder and only once for any particular session.
What it does not do: lots & lots of things, eg. does not mark the image as clean.

I am sure all the clever guys will pull this into a thousand shards :)

edit: I can start that process myself: script works for me in linux, but crashes in Windows. Such is life

I put the missing escape in "\\" for windows, still crashes.

edit again: strangely, this works in a WinXP (virtual machine) with Gimp 2.8.4
I wonder what has changed from that old version?

#!/usr/bin/env python
#
from gimpfu import *

def save_to_files(timg, layer, outputFolder):


    pdb.gimp_context_set_interpolation(INTERPOLATION_LANCZOS)
    pdb.gimp_image_scale(timg, 270, 65)
    pdb.gimp_image_convert_indexed(timg, 0, 0, 256, 0, 0, "" )
   
    try:
       
        # Save as GIF
        gimp.pdb.file_gif_save(timg, layer, outputFolder + "\\" + layer.name + ".gif", "raw_filename" ,0, 0, 0, 0 )

    except Exception as err:
        gimp.message("Unexpected error: " + str(err))
   
register(
    "python_fu_save_to_files",
    "Save to files",
    "Save the current layer into a GIF file",
    "",
    "Open source",
    "2016",
    "<Image>/Tools/Save to GIF",
    "*",
    [
        (PF_DIRNAME, "outputFolder", "Output directory", ""),
    ],
    [],
    save_to_files)

main()

Shouldn't this
#!/usr/bin/env python
be
#!/usr/bin python
for Windows applications?

_________________
Image


Top
 Post subject: Re: simple scripting assistance
PostPosted: Wed Nov 16, 2016 6:45 am  (#11) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16167
paynekj wrote:
I'll have one more attempt at getting you to specify your requirements in sufficient detail, although others here with better psychic abilities maybe able to guess what you want better than I can...

The process is????
  1. Start with an image open in GIMP
  2. Select to run the script from a menu item/keyboard shortcut
  3. On the script dialog
    1. Select which size image you want to make from a list of options
    2. Enter the name of the file you want to create
  4. Run the script

Kevin

Exactly what i believe they want except now you need to save as an indexed GIF file Kevin. :)
I would also leave width and height to the discretion of the user so in case sizes change the script won't need to be updated for it. Just a thought.

_________________
Image


Top
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group