RSS/Atom feed Twitter
Site is read-only, email is disabled

Exact crop question

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

7 of 7 messages available
Toggle history

Please log in to manage your subscriptions.

Exact crop question Zachary Leung 22 Apr 06:15
  Exact crop question David Gowers 22 Apr 06:39
   Exact crop question Zachary Leung 22 Apr 10:57
    Exact crop question David Gowers 22 Apr 15:55
     Exact crop question saulgoode@flashingtwelve.brickfilms.com 23 Apr 03:55
    Exact crop question Kevin Cozens 22 Apr 16:58
     Exact crop question Zachary Leung 23 Apr 03:24
Zachary Leung
2008-04-22 06:15:21 UTC (about 16 years ago)

Exact crop question

Hi everyone,

I'm wondering if there's an automated way to crop my images of all the white areas on the outside.

Basically I've produced quite a few MATLAB plots exported as JPEGs. There's a lot of white around the sides, and the figure is in the center. Is there an automated way to crop exactly the white parts around the figure away? That would save me time from having to zoom in to each picture and do the cropping manually.

Thanks!

Zac

David Gowers
2008-04-22 06:39:24 UTC (about 16 years ago)

Exact crop question

Hi Zac!

On Tue, Apr 22, 2008 at 1:45 PM, Zachary Leung wrote:

Hi everyone,

I'm wondering if there's an automated way to crop my images of all the white areas on the outside.

Basically I've produced quite a few MATLAB plots exported as JPEGs. There's a lot of white around the sides, and the figure is in the center. Is there an automated way to crop exactly the white parts around the figure away? That would save me time from having to zoom in to each picture and do the cropping manually.

Autocrop (Image->Autocrop) does this.

David

Zachary Leung
2008-04-22 10:57:40 UTC (about 16 years ago)

Exact crop question

Hi David,

Thanks for answering my question so quickly.

I realized that I should have phrased my question more carefully. What I want is to be able to autocrop all the images matching a pattern, say "movie*.jpg". How do I do that?

I tried something below, but that didn't work. =(

Thanks!

Zac

gimp -i -b '(plug_in_autocrop "movie00000.jpg")'

(define (zac-autocrop filename) (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image)))) (plug_in_autocrop RUN-NONINTERACTIVE image drawable) (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename) (gimp-image-delete image)))

On Tue, Apr 22, 2008 at 12:39 PM, David Gowers wrote:

Hi Zac!

On Tue, Apr 22, 2008 at 1:45 PM, Zachary Leung wrote:

Hi everyone,

I'm wondering if there's an automated way to crop my images of all the white areas on the outside.

Basically I've produced quite a few MATLAB plots exported as JPEGs. There's a lot of white around the sides, and the figure is in the center. Is there an automated way to crop exactly the white parts around the figure away? That would save me time from having to zoom in to each picture and do the cropping manually.

Autocrop (Image->Autocrop) does this.

David

David Gowers
2008-04-22 15:55:24 UTC (about 16 years ago)

Exact crop question

Hi Zachary,

On Tue, Apr 22, 2008 at 6:27 PM, Zachary Leung wrote:

Hi David,

Thanks for answering my question so quickly.

I realized that I should have phrased my question more carefully. What I want is to be able to autocrop all the images matching a pattern, say "movie*.jpg". How do I do that?

script-fu is something I do not use, so I will give my example implementation in a form that you could call from the PyGimp console.

def autocrop_many (pattern): import glob
filenames = glob.glob (pattern)
for filename in filenames:
#the following is a direct translation of your script-fu. image = pdb.gimp_file_load (filename, filename) drawable = image.active_layer
pdb.plug_in_autocrop (image, drawable) pdb.gimp_file_save (image, drawable, filename, filename) pdb.gimp_image_delete (image) # this line may not be needed

If you paste the above into a PyGimp console, then call it like autocrop_many ('/path/to/files/movie*') it should do what you want.

If you don't have python support installed, I can only help by pointing out basic errors in your code; I know little of script-fu

I tried something below, but that didn't work. =(

Thanks!

Zac

gimp -i -b '(plug_in_autocrop "movie00000.jpg")'

* plug_in_autocrop accepts an image as it's first parameter, but you provided a filename.
(you also are trying to call 'plug_in_autocrop', whereas the function is named 'plug-in-autocrop'. -/_ substitution is only used if you're coding your plugin in Python.)
I think you meant to call zac-autocrop here, anyway.

(define (zac-autocrop filename)
(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image)))) (plug_in_autocrop RUN-NONINTERACTIVE image drawable)

^^
the above line has the _ / - mistake I pointed out earlier in this email.

(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename) (gimp-image-delete image)))

You defined zac-autocrop correctly, but you haven't registered it with GIMP. See this link for an example.
http://svn.gnome.org/viewvc/gimp/trunk/plug-ins/script-fu/scripts/paste-as-brush.scm?view=markup

Hope that helps!

David

Kevin Cozens
2008-04-22 16:58:47 UTC (about 16 years ago)

Exact crop question

Zachary Leung wrote:

I tried something below, but that didn't work. =(

[snip]

gimp -i -b '(plug_in_autocrop "movie00000.jpg")'

(define (zac-autocrop filename) (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable (car (gimp-image-get-active-layer image)))) (plug_in_autocrop RUN-NONINTERACTIVE image drawable) (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename) (gimp-image-delete image)))

From a quick look at the above, the zac-autocrop function appears to be ok with one minor exception. You don't use _ in the names of functions in Script-Fu. 'plug_in_autocrop' should be 'plug-in-autocrop'.

If you wrote zac-autocrop to load, crop, and re-save your files, why does your GIMP command line shown above call plug-in-autocrop instead of zac-autocrop?

Zachary Leung
2008-04-23 03:24:34 UTC (about 16 years ago)

Exact crop question

Thanks guys, I've figured out what to do from your pointers! Didn't realize there's a difference between _ and -.

Zac

saulgoode@flashingtwelve.brickfilms.com
2008-04-23 03:55:25 UTC (about 16 years ago)

Exact crop question

Quoting David Gowers :

You defined zac-autocrop correctly, but you haven't registered it with GIMP. See this link for an example.

If you are calling a Script-fu defined function from the command line, it is not required that the function be registered with the PDB. The definition will be loaded when Script-fu is initialized and the function made available within Script-fu. PDB registration is only necessary if you wish the defined function to be made available to plug-ins or scripts in other languages.