• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

resize an image to the icon button size

Participant ,
Apr 29, 2016 Apr 29, 2016

Copy link to clipboard

Copied

hi,

how can i resize an image to the icon button size?

var w = new Window ("dialog");

b=w.add ("iconbutton", undefined, "~/Desktop/abc.png");

b.size=[50,50]

w.show();

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 29, 2016 Apr 29, 2016

Copy link to clipboard

Copied

There is an example from Marc Autret inside ScriptUI for dummies by Peter Kahrel .

It shows how to resize the image, but I think it would probably work for iconbutton too:

Image.prototype.onDraw = function()

{ // written by Marc Autret

// "this" is the container; "this.image" is the graphic

if( !this.image ) return;

var WH = this.size,

wh = this.image.size,

k = Math.min(WH[0]/wh[0], WH[1]/wh[1]),

xy;

// Resize proportionally:

wh = [k*wh[0],k*wh[1]];

// Center:

xy = [ (WH[0]-wh[0])/2, (WH[1]-wh[1])/2 ];

this.graphics.drawImage(this.image,xy[0],xy[1],wh[0],wh[1]);

WH = wh = xy = null;

}

var w = new Window ("dialog", "Bouquet");

var flowers = w.add ("image", undefined, File ("/d/scriptui/bouquet.jpg"));

flowers.size = [50,50];

w.show ();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 29, 2016 Apr 29, 2016

Copy link to clipboard

Copied

Thank you for your answer,

but it works only on "image", not on "iconbutton".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 30, 2016 Apr 30, 2016

Copy link to clipboard

Copied

I think that the only way to scale the image of the icon button is to overwrite the onDraw method for the button (as in Marc Autret snippet), but then this would also overwrite the default (built-in) graphic behaviour of the iconbutton (mouseover, mousedown, etc), which means that you would need to write more code to handle this as well (add corresponding event listeners to the iconbutton, prepare specific images for the mouseover/mousedown states, etc). In other words, you'll loose all the benefits of the built-in class and have to rewrite everything. Worth it ?

Xavier.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 30, 2016 Apr 30, 2016

Copy link to clipboard

Copied

can you write to me an example please?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2016 May 01, 2016

Copy link to clipboard

Copied

Resizing the image is not good when script has many images since it cost a lot of time.A better way is to crop the image.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 01, 2016 May 01, 2016

Copy link to clipboard

Copied

LATEST

cropping an image is not always the right way, sometimes a better way is to scale your images to button...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines