0

I am building a IMG crop/re-size/zoom tool and I want to be able to pass some default parameters into the drawImage() function in case some are not defined yet.

For example:

I get a re-size request and can therefor input width and height:

drawImage(this.loadedImg,0, 0, 0, 0, 0,0,this.imageWidth, this.imageHeight);

I cant find the defaults anywhere. I tried false and 0, but neighter worked.

Does anyone have an idea?

Jousi
  • 456
  • 4
  • 26
  • More generally, are you looking for default function parameter? You can look [here](http://stackoverflow.com/questions/894860/set-a-default-parameter-value-for-a-javascript-function). – hhh Apr 30 '17 at 13:08

1 Answers1

0

I'm not sure I got clearly what you are after, So I'll assume you want the default values for the arguments of drawImage(source, sx, sy, sw, sh, dx, dy, dw, dh) when you use the short version drawImage(source, dx, dy) or the less short drawImage(source, dx, dy, dw, dh).

In case of an <img> element as source, it is drawImage(img, 0,0, img.naturalWidth, img.naturalHeight, 0, 0, img.naturalWidth, img.naturalHeight).

In case of a <video> element as source, it is drawImage(vid, 0,0, vid.videoWidth, vid.videoHeight, dx, dy, vid.videoWidth, vid.videoHeight).

For any other source type it is drawImage(source, 0, 0, source.width, source.height, 0, 0, dx, dy).

So we can make this table :

drawImage(
   source: always inputed,
   sx: input || 0,
   sy: input || 0,
   sw: input || source.[natural | video]width,
   sh: input || source.[natural | video]height,
   dx: always inputed,
   dy: always inputed,
   dw: input || sw,
   dh: input || sh
)
Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • This is what I was after, sory for my late response and aknowledgment of your correct answer, I resolved this problem by myselfe yesterday afterall. But the table idea is appreciated. – Jousi May 01 '17 at 07:55