-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Division by zero #3
Comments
You did not include the code that you are using, so you are forcing us to take a totally random guess on what it is you are trying to do. If my suggested solutions below do not fix your issue, going to need you to include some actual code that you are trying to implement. But, if I had to take a wild guess, I would predict that your set height/image is greater than the height and/or width of the original image that you are using. That has a tendency to throw that "Division by zero" error, along with a few other things, sigh. Sadly the author of this small script just did not really mature things, nor has seemed to want to resolve a few issues already brought up. But here is an easy way to see/check the issue I mentioned above: Inside of the
place that after the line:
That should at least output a slightly better/helpful error message for you to solve the image size issue. I would also highly recommend making this change from using ceil() to using floor() as it can help solve some other issues that might show up in your using of this script. And, if you plan on using the
Again, the author of smartcrop.php has not done a very good job on maturing this script. The code above will at least attempt to properly output the image to the correct mime-type, unlike the hard-coded A good example of this is that the image that you have in your example Likewise, the scripts author needs to put into a next version of the script the ability to handle There are a couple other possible suggestions to resolve this issue, but as I said at the beginning, your lack of posting any code that you are using makes it so that all I/we can do at this point in time is take random guesses at trying to solve your issue. Hopefully something I have already shared solves it, but if not, well, you know what the next step is 😉 |
hello @johnabela About the image, I did notice it was a png and not a jpg, but because the script uses
on canvasImageResample() and crop() after the imagecreatetruecolor() call. |
Opps on not remembering your usersname and the Yeah, the whole thing about the So when I was bug hunting this about 6 hours ago, here is how I rewrote the function for a unit test:
My effort was to try to prevent an actual mathematical division by zero by changing all of the So when I change the function to the above, for your image I get:
Could you update your Also, could you give this small change a try... Inside of the Some stupid math issue that is using a zero, or a negative number, somewhere, eh! |
btw, here is the exact code that I am using for your image, and it is working, ref the attached image.
When using your image, the only time I am able to reproduce your 'Divided by zero' error is when I set the height to something higher than the size of your original file. |
Hello, The division by zero only occurs once, with this values : r : 382 |
so,
in the saturation() method before the return to just prevent any division by zero and return 0 instead. should I create a pr? |
Certainly worth a try submitting a PR/Commit and seeing if @xymak accepts it. Maybe also:
In regards to the changes you made to the
And here is my image size check code:
And here is my
Might as well give it all one big PR/Commit at once, and just see if he accepts it or not. If nothing else, we can use it to point others too if others have issues in the future, eh. |
hi, |
PS : the comparison in saturation() method must be with |
Hello,
For some images i'm getting the error "Division by zero" in xymak-smartcrop/smartcrop.php:449.
example image : https://ufile.io/764g9 ( 501x376 )
The text was updated successfully, but these errors were encountered: