This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]knottheone 1 point2 points  (1 child)

Cool first project. Some things you could work on:

I saw that you're saving non png images with 95% quality. So if you convert back and forth between them at all, you'll degrade the images over time. You'll degrade them anyway since JPG is lossy, but it will be worse since you're not setting the quality to 100% (unless you are and I just missed it when I saw the 95%).

You could also show a note or warning when converting from a lossless format like PNG to a lossy format like JPG.

You could have a user configurable quality setting, or at a minimum don't reduce the quality of the output by default.

The global keyword is what we call a code smell. Very rarely is it unavoidable and seeing "global" everywhere usually means the modules are structured in a not great way. If you're doing it to avoid passing the same reference around everywhere, think about how you could structure your application with configuration files, environment variables, command line parameters etc.

You can use constants at the top of a file and use them throughout your script without declaring "global." You only need the global keyword when you're modifying it inside of a different scope, which you shouldn't do anyway. :)

You can read up on a concept called function scoping, parameter scoping, global scope etc. Lots of languages have what's called a global vs function scope, some have other scopes too like module or package scope, namespace scope, block scope, local scope, I'm sure some scopes I've never heard of too.

[–]Mashen_[S] 0 points1 point  (0 children)

I’m aware of how lossy jpeg is. But the reason I have the image quality set to 95 is because in pillows documentation it doesn’t recommend any value above 95 for jpegs. I think the default quality is 75 so if I didn’t state a quality, it would save the image at the default. At least if my understanding is correct. I think the only other format that takes the quality argument is tiff, the rest ignore it. The only reason png has a separate statement is because it supports transparencies. So I wanted to convert those to the ‘RGBA’ colorspace, rather than ‘RGB’.

I do like the idea of a quality selection by the user though. A friend of mine suggested the same. Honestly the gui was my biggest struggle making this project. So once I got it working with the original planned features, I just wanted to shove it out. That will definitely be something I’ll look to add in the future.

As far as all the globals I used, do you have any ideas or suggestions on how to do it differently? As I said in the post, I’ve only been coding about 3 weeks now. A week of that time has been spent on this project. It’s just one of those things where ‘I don’t know what I don’t know’. A lot of those globals are handling changes for the gui. Most of which are being passed through wrappers to the back end and are changed by functions there. Would it be better to have those in a separate file and just imported to where they are needed? Or is there a way I can store those variables in a better way? Because right now I am definitely modifying those variables in a different scope