Skip to content
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

Add option to overwrite original #20

Open
ajimix opened this issue Apr 8, 2018 · 17 comments
Open

Add option to overwrite original #20

ajimix opened this issue Apr 8, 2018 · 17 comments

Comments

@ajimix
Copy link

ajimix commented Apr 8, 2018

Normally I want just to compress the original exported assets so would be nice to have an "overwrite original" option

Thanks for the great work 👍

@chrissimpkins
Copy link
Owner

This is a lossy optimization so I think that many/most will want to hang on to their original images for comparison. Let me see if we can work an option for overwrites into the new command line executable that is in development. We should be able to support this.

@zipang
Copy link

zipang commented Apr 19, 2018

👍 Excellent results with this tool : it can further optimize image that PNGenie had already compressed !
But i must add my +1 to this request : I use PNGenie to do exactly that : drag the PNG file and optimize them in situ. So that i can routinely download user's uploaded images from several servers i'm an administrator, optimize them in one drag and drop, and reupload them easily.
If i want to compare the images when i'm not sure, i can make a duplicate of my directory before compression..
So let's make it an option in a Preferences screen ! :)

@chrissimpkins
Copy link
Owner

Thanks for your feedback! Will look into it.

@chrissimpkins
Copy link
Owner

I have a new command line executable that is in development in #19. It supports parallel image processing on any *nix system (this will get to Linux and *nix on Win support) and the scripting will be the basis of the next version of the GUI tool. It will be simple to add this request to the command line executable. How important is it to you that this is implemented in the GUI tool as well? I am not a macOS objC/Swift developer and the GUI approach that I am using would likely involve a workaround like an environment variable or dotfile in the $HOME directory to support optional overwrites from the GUI tooling.

@ajimix
Copy link
Author

ajimix commented May 1, 2018

Well the GUI is great to have as it makes the app easier to use. But if it's too complex then I'll switch from using GUI to command line which is slower at the end than just grabbing and dragging a bunch of files to a window

@chrissimpkins
Copy link
Owner

chrissimpkins commented May 1, 2018

We should be able to make it happen in the GUI. Will let you know when it is available. Thanks for the feedback.

@chrissimpkins chrissimpkins added this to the v3.0.0 milestone May 18, 2018
@chrissimpkins chrissimpkins removed this from the v3.0.0 milestone Jun 1, 2018
@chrissimpkins chrissimpkins added this to the v3.1.0 milestone Jun 5, 2018
@chrissimpkins chrissimpkins removed this from the v3.1.0 milestone Oct 19, 2019
@marcinkrzeminski
Copy link

Hi @chrissimpkins,

any progress on that?

BTW great tool. Love it! ❤️❤️❤️❤️❤️

@chrissimpkins
Copy link
Owner

Thanks for the note Marcin! I am working on native macOS application chops as we speak. I am considering a rebuild of the desktop application from scratch. I will definitely look into it for both GUI and command line as soon as I circle back to this project. And it is always open for PR's! If anyone else out there wants to tackle it as an optional feature that users call explicitly, I would be happy to implement it.

@marcinkrzeminski
Copy link

Thanks for letting me know. I'd be happy to help, but sadly, I'm not familiar with Python 😔

@chrissimpkins
Copy link
Owner

No worries! I'll do my best to get back to this soon. Time...

@chrissimpkins
Copy link
Owner

chrissimpkins commented Jan 11, 2020

If you want to modify the default behavior yourself, I believe that you should be able to do it by modifying this block beginning at line 400:

Crunch/src/crunch.py

Lines 400 to 410 in dee3cba

# report percent original file size / post file path / size (bytes) to log file (macOS GUI + right-click service)
if is_gui(sys.argv):
log_info(
"[ "
+ percent_string
+ " ] "
+ img.post_filepath
+ " ("
+ str(img.post_size)
+ " bytes)"
)

to something like the following:

    # report percent original file size / post file path / size (bytes) to log file (macOS GUI + right-click service)
    if is_gui(sys.argv):
        log_info(
            "[ "
            + percent_string
            + " ] "
            + img.post_filepath
            + " ("
            + str(img.post_size)
            + " bytes)"
        )
    
    try:
        os.remove(img.pre_filepath)
        shutil.move(img.post_filepath, img.pre_filepath)
        stdstream_lock.acquire()
        print("Moved {} to {}".format(img.post_filepath, img.pre_filepath))
        stdstream_lock.release()
    except Exception as e:
        stdstream_lock.acquire()
        sys.stderr.write("Error: Unable to overwrite pre image file {}.  Error message: {}".format(img.pre_filepath, e))
        stdstream_lock.release()

You can then rename the crunch.py script and place it in a directory on your system PATH (e.g., /usr/local/bin) with a file name crunch instead of crunch.py. Then call it on the command line with crunch [arguments - see README page]. This change will always overwrite the in path file.

Please (please, please) try this on copies of files before you attempt on anything that you can't afford to lose. This is 100% untested but I think that it should work™ and is intended as a way to help anyone out there who is interested get started on a derivative that addresses this issue until I can do it upstream.

@marcinkrzeminski
Copy link

@chrissimpkins thanks for the pointers. Following your instructions, I did some changes and made a PR #76

@chrissimpkins
Copy link
Owner

The changes from Marcin are now in the dev branch and we will plan to include these in the next release.

@neochief
Copy link

Just want to let you know, that this is the primary way I'd use it. I'm going to install the dev branch right now.

@mattlongman
Copy link

mattlongman commented Mar 28, 2021

Just looking at the comments on @marcinkrzeminski's PR (#76), perhaps instead of a checkbox for overwriting, some kind of contextual popup could be used? E.g. dragging files to GUI, delay for a few seconds, background of GUI changes, and when you release the mouse button, you receive an 'Are you sure?' prompt. Please excuse the rough mock-up, but something like:

crunch-mockup-crunch
(Edit: Replaced the image with the crunched version, because, why not.)

I'm not sure if that's any easier than modifying the GUI, though.

If the information helps: I'm going to try to use this in an image processing workflow with the -f flag (I can regenerate from the original image when I need), so GUI option less critical (but nice to have).

Anyway, just an idea!

@chrissimpkins
Copy link
Owner

E.g. dragging files to GUI, delay for a few seconds, background of GUI changes, and when you release the mouse button, you receive an 'Are you sure?' prompt.

Thanks for the suggestion! I really like it but it isn't possible with the current approach. The GUI is built around our scripts with an automated tool and the addition of dialogs/toasts/OK + Cancel buttons and the like are not possible.

I've been giving some thought to moving this over to PyQt5 so that we have the ability to support cross-platform GUI, custom settings (including an option to always write files in place), and user-defined zopflipng/pngquant paths. Let me see when time opens up to look into this. If we keep it relatively simple, it may not be a terribly large amount of work.

@mattlongman
Copy link

mattlongman commented Mar 30, 2021

Understood - I thought that might be the case based on previous notes.

For automated workflows, -f will be great, but I was also wondering whether the python core can be published to pypi? (Edit: not to drag things off topic, issue #87 created.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants