It is currently Thu Apr 18, 2024 10:44 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 16 posts ] 
Author Message
 Post subject: Resize by Area
PostPosted: Fri Dec 14, 2012 2:16 pm  (#1) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
There was a request for a script to resize an image by area:
http://registry.gimp.org/node/27728

The idea being that it makes it easier to compose different proportioned images together so they all have the same visual weight.

I created a script that accomplished this and figured I'd share here as well for testing and suggestions before uploading to the GPR.

It shows up under Image->Resize By Area...

You basically specify an equivalent width and height, and it resizes the image to have the same area as that, using your default scaling method.

(See later in the thread for an update)


-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Last edited by RobA on Mon Dec 17, 2012 4:06 pm, edited 1 time in total.

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: Resize by Area
PostPosted: Fri Dec 14, 2012 3:36 pm  (#2) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
It works like a charm for me, RobA :bigthup
I tested with a variety of image sizes, up and down scale.
This script can be very useful in web design.
win32, Gimp 2.8.2

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: Resize by Area
PostPosted: Sat Dec 15, 2012 8:01 am  (#3) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
Hi RobA.

I have just tested the script on an image equipped with all the possible objects that can be added to it (layers, layer groups, channels, paths, floating selection), and according to me at the moment it already works great. :)

Howsoever, If I may, I would only like to suggest adding a combo-box widget (SF-OPTION) that allows to choose the interpolation method among the usual ones provided by GIMP, specifying for instance the "Cubic" one as the default.

Also, I think it could be useful to arrange for the script to be available through the "Repeat Last" and "Re-show Last" commands, where such a feature should be easily achieved (I imagine) by setting in the script registration the image type's parameter to "*" rather than to "".

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: Resize by Area
PostPosted: Mon Dec 17, 2012 4:06 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
Gino D wrote:
... choose the interpolation method among the usual ones provided by GIMP, ...[and]... to be available through the "Repeat Last" and "Re-show Last"


Thanks for the feedback - the image mode as "" was just an oversight, and should have been there.

Good call on the use of SF-ENUM. Added..

here is an update...
please find the actual working one later one.... :)

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Last edited by RobA on Tue Dec 18, 2012 8:44 am, edited 1 time in total.

Top
 Post subject: Re: Resize by Area
PostPosted: Mon Dec 17, 2012 5:54 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
RobA in the equation (max 1 (min 262144 (round (* w (sqrt (/ a (* w h)))))))

what does the terms max and min mean? :mrgreen:

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Resize by Area
PostPosted: Mon Dec 17, 2012 6:07 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
RobA wrote:
Thanks for the feedback - the image mode as "" was just an oversight, and should have been there.

Good call on the use of SF-ENUM. Added..


Thanks for paying attention to my suggestions. I am glad that you took them into consideration.

Anyway, regarding the updated version, the only thing I don't understand is how the script can set the interpolation method to the appropriate value specified in the dialog box, since in the source code I don't see any "gimp-context-set-interpolation" statement, which I think should be necessary for the purpose. Unless, maybe, the special SF-ENUM option automatically performs this task too (sorry, that's a widget that I am not very familiar with yet).

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: Resize by Area
PostPosted: Mon Dec 17, 2012 8:35 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Gino D to add a choice for interpolation just modify your script to this ↓

(define (script-fu-resizebyarea img inLayer interpolation inWidth inHeight)
  (let*
    ((w (car (gimp-image-width img)))
    (h (car (gimp-image-height img)))
    (a (* inWidth inHeight))
   )

    ;  it begins here
    (gimp-context-push)
    (gimp-image-undo-group-start img)
   
   (gimp-image-scale-full img
      (max 1 (min 262144 (round (* w (sqrt (/ a (* w h)))))))
      (max 1 (min 262144 (round (* h (sqrt (/ a (* w h)))))))
      interpolation)
      
   (gimp-image-undo-group-end img)
    (gimp-displays-flush)
    (gimp-context-pop)
   
  )
)

(script-fu-register "script-fu-resizebyarea"
                  "<Image>/Image/Resize by Area..."
                    "Resize by Area"
                    "Rob Antonishen"
                    "Rob Antonishen"
                    "Dec 2012"
                    ""
                    SF-IMAGE      "image"      0
                    SF-DRAWABLE   "drawable"   0
               SF-ENUM "Interpolation" '("InterpolationType" "cubic")
               SF-ADJUSTMENT "Equivalent Width" '(1000 1 10000 10 1000 0 1)
               SF-ADJUSTMENT "Equivalent Height" '(1000 1 10000 10 10000 0 1)
)

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Resize by Area
PostPosted: Tue Dec 18, 2012 6:27 am  (#8) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
Graechan wrote:
Gino D to add a choice for interpolation just modify your script to this ↓
(gimp-image-scale-full img
      (max 1 (min 262144 (round (* w (sqrt (/ a (* w h)))))))
      (max 1 (min 262144 (round (* h (sqrt (/ a (* w h)))))))
      interpolation)

Yes, Graechan, the modification you propose to Rob can certainly be a very valid alternative. :)

Nevertheless, as for me and only for being consistent with the last GIMP versions, lately in my scripts and my code snippets I prefer using the generic "gimp-image-scale" procedure preceded by a "gimp-context-interpolation" statement, as "gimp-image-scale-full" is numbered among the commands listed as deprecated in GIMP 2.8 (though I don't quite agree with this decision, finding the latter procedure still very convenient).

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: Resize by Area
PostPosted: Tue Dec 18, 2012 8:43 am  (#9) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
@ Gino D - Thanks. I'm an idiot. That's what a fellow gets for working on too many things at once! I added the parameter an then never added the code to use it :P
@ Graechan - exactly what is necessary for the 2.6.x series. Also min and max are scheme functions (return the min and return the max). I am using them to clamp the width and height to the allowable limits.

Attached is the updated script that works in 2.6.x (calling interpolate-full) and later versions (setting the context and then calling the default interpolate).
Attachment:
resizebyarea.scm [2.66 KiB]
Downloaded 141 times


This should do the trick for everyone.

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Top
 Post subject: Re: Resize by Area
PostPosted: Tue Dec 18, 2012 2:36 pm  (#10) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
RobA wrote:
Attached is the updated script that works in 2.6.x (calling interpolate-full) and later versions (setting the context and then calling the default interpolate).

Well, now your script is perfect, and I find the function checking the gimp version really effective. I too have created a special code snippet with the same purpose for the upcoming new versions of my scripts (one of which, that is "Remove Holes", actually is already available at the GPR.)

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: Resize by Area
PostPosted: Wed Dec 19, 2012 3:30 pm  (#11) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
Just a last question, Rob: by chance, do you know where it is possible to find an updated list of all the registered enums that the SF-ENUM widget can accept as input?
I have been searching for it everywhere for quite some time, but so far without success. :(

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: Resize by Area
PostPosted: Wed Dec 19, 2012 6:30 pm  (#12) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Gino D this is the list I use Gimp-enums

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Resize by Area
PostPosted: Thu Dec 20, 2012 4:10 am  (#13) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
Graechan wrote:
Gino D this is the list I use Gimp-enums

Thanks a lot, Graechan. :tyspin
The only problem, as you can see as well, is that unfortunately in such page the specific SF-ENUM widget used by Rob for setting the interpolation method doesn't seem to be listed among the possible registered enums. So that's the reason why I guess there has to be somewhere a more complete list of the enumerators that may be used for the Script-Fu registering, and likely Rob must have got to know about this somehow.

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: Resize by Area
PostPosted: Thu Dec 20, 2012 7:51 am  (#14) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Gino D, you should be able to find all of the GIMP enumerated types within http://git.gnome.org/browse/gimp/tree/l ... h=gimp-2-8

Here they are at the time of this posting (with the leading "Gimp" removed):
AddMaskType BlendMode BrushApplicationMode BrushGeneratedShape BucketFillMode ChannelOps ChannelType CloneType ConvertDitherType ConvertPaletteType ConvolutionType ConvolveType DesaturateMode DodgeBurnType FillType ForegroundExtractMode GradientSegmentColor GradientSegmentType GradientType GridStyle HistogramChannel HueRange IconType ImageBaseType ImageType InkBlobType InterpolationType LayerModeEffects MaskApplyMode MergeType MessageHandlerType OffsetType OrientationType PDBArgType PDBErrorHandler PDBProcType PDBStatusType PaintApplicationMode ProgressCommand RepeatMode RotationType RunMode SelectCriterion SizeType StackTraceMode TextDirection TextHintStyle TextJustification TransferMode TransformDirection TransformResize UserDirectory VectorsStrokeType


You need to be somewhat careful though, because that file is generated dynamically when GIMP is compiled; so the one you are looking at may not exactly match the one that corresponds to your build of GIMP.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Resize by Area
PostPosted: Thu Dec 20, 2012 12:24 pm  (#15) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
saulgoode wrote:
Gino D, you should be able to find all of the GIMP enumerated types within http://git.gnome.org/browse/gimp/tree/l ... h=gimp-2-8


Thank you. :)

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: Resize by Area
PostPosted: Thu Dec 20, 2012 6:03 pm  (#16) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
My apologies Gino D the list I gave is for 2.4 and I only new that Interpolation actually also worked in 2.6 Wilbur is never up to date with info

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
Post new topic Reply to topic  [ 16 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Can't resize brush

23

No new posts In area 51

4

No new posts Attachment(s) [solved]quickly resize patterns

7

No new posts Attachment(s) Link Area on image.

16

No new posts Attachment(s) How to edit enlarged boundary size area.

2



* Login  



Powered by phpBB3 © phpBB Group