MZ How to get the width and height of a image.

Basically I want to do this...

Variable BustX = Graphics.width - picture.width
Variable BustY = Graphics.height - (picture.height + y offset from bottom (136))

Problem is how do I get the size of an image? (picture)

I've moved this thread to Learning Javascript. Thank you.


Like this:
Code:
sprite.width // gets the width of the image
sprite.height // gets the height of the image
The problem is that if you call this right after the sprite is created, you will get nothing since the image hasn't been loaded yet. So you either have to wait a couple frames, or find a work around. I personally added this in the update method:
Code:
Sprite_Thing.prototype.update = function() {
    Sprite_Base.prototype.update.call(this);
    if (this.width && this.height) {
        @canGetWidthHeight = true
    }
}

Sprite_Thing.prototype.getWidth = function() {
    if (@canGetWidthHeight) return this.width;
}

EDIT: This is what I did in MV and have not tried in MZ yet. I'm assuming it's also working in MZ, and I'm also assuming the loading delay is still there.
Okay let me reiterate my question. How do get I get sprite.width sprite.height of a specific picture.

$gameScreen.picture(1).width and $gameScreen.picture(1).height do not work btw even after waiting 4 frames.
Ahh, then it's much trickier. Game_Picture isn't a sprite so it doesn't have the width and height property. That means you need to either get it in the Sprite_Picture object (meaning you'll have to play inside the Spriteset_Map), or you modify the Game_Picture object so that it keeps the width and height data. I never play around with Game_Picture, so perhaps there's an easier way that I'm not aware of.
Okay now I know something is screwy. I just checked. And it is infact a sprite. or at least should be.
:ewat:

Tried adding this bit of code. Too no effect.

Code:
/*:
@target MZ
@plugindesc Allows you to grab the width and height of pictures.
@author Nekohime
*/
(() => {


    // Setting pluging name
    const pluginName = 'Neko_PictureFix';

    //add width and height to pictures. -_-
    Game_Picture.prototype.width = function() {
        return this._width;
    };

    Game_Picture.prototype.height = function() {
        return this._height;
    };

})();
You can do some ugly direct calls to sprites if its what you want
Code:
var picSpriteset = SceneManager._scene._spriteset.children.find(obj => obj.children.length >= 99);
picSpriteset.children[0].width
picSpriteset.children[0].height
children[0] - is your picture IDs from 0 to 99
You sir are a godsend.
It's an ugly hack. But it works and that's all that matters.
Thanks Krimer.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-get-the-width-and-height-of-a-image.126954/