Page 1 of 1

imagecreatetruecolor(): Invalid image dimensions

Posted: Sat Aug 24, 2019 11:06 pm
by rgbrewer
3.0.2

system/library/image

public function resize ($width = 0, $height = 0, $default = '') {
[...]
$this->image = imagecreatetruecolor($width, $height)
}

This line should be
$this->image = imagecreatetruecolor($new_width, $new_height)

I believe the same error occurs here:
imagefilledrectangle($this->image, 0, 0, $width, $height, $background);

which I believe should be imagefilledrectangle($this->image, 0, 0, $new_width, $new_height, $background);

as well as here at the very end of the method
$this->width = $width;
$this->height = $height;

should be $new_width and $new_height

Re: imagecreatetruecolor(): Invalid image dimensions

Posted: Sat Aug 24, 2019 11:30 pm
by rgbrewer
There's actually several problems with this code... here are my revisions that are currently working properly.

https://pastebin.com/2fx4vxA3

Re: imagecreatetruecolor(): Invalid image dimensions

Posted: Sat Aug 24, 2019 11:38 pm
by letxobnav
eh, no.

Re: imagecreatetruecolor(): Invalid image dimensions

Posted: Sat Aug 24, 2019 11:46 pm
by rgbrewer
Thanks for your helpful thoughts.

I'm not making things up, this fails. Walk through it for this method call:
$image->resize(300);

what does $height equal when imagecreatetruecolor($width, $height) runs? It will evaluate to 0 and imagecreatetruecolor will fail because you cannot create an image that is zero pixels tall...

Re: imagecreatetruecolor(): Invalid image dimensions

Posted: Sun Aug 25, 2019 8:22 am
by letxobnav
Well, you did not request helpful thoughts or an explanation as to why it works the way it does, you made an assertion, a flawed one.

The function of resize is to take an image of any size and any aspect ratio and resize it to fixed dimensions, as per admin settings, while maintaining that aspect ratio.
You however believe it should have a different function and thus claim it does not work correctly.

While there are better resize functions which can be written, which can do more magical things, that does not make your assessment any better.
So, eh, no.

Re: imagecreatetruecolor(): Invalid image dimensions

Posted: Sun Aug 25, 2019 9:31 pm
by rgbrewer
The function has three default parameters, however if you try to use them, the function fails. You really trying to say that is an intended result? If the function requires three parameters to work -- and fails without all three parameters -- Why are the parameters optional? Can you explain that to me? If you can, I will apologize and delete my posts.

But you can't.

Don't be an obstinate jackass. My changes to this code is a marked improvement on the current code base, and there is no argument to be made that its not. You should be grateful that people come here and take time to help solve problems in the codebase, not troll with unhelpful two words replies based on your utter ignorance of the topic.

"Eh, no".

Re: imagecreatetruecolor(): Invalid image dimensions

Posted: Tue Feb 23, 2021 4:07 pm
by drest341
rgbrewer wrote:
Sat Aug 24, 2019 11:30 pm
There's actually several problems with this code... here are my revisions that are currently working properly.
https://pastebin.com/2fx4vxA3
It works perfect for me on OC3.0.3.1 - thanks