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

new: command line tool for compressing images ct compress-images #25

Merged
merged 6 commits into from
Oct 27, 2023

Conversation

yxlao
Copy link
Owner

@yxlao yxlao commented Oct 27, 2023

Features

  • Compress jpg to the specified quality (default: 95), convert png to jpg
  • Update text paths given the root directory to reflect the new image paths

TLDR:

# Compress images in-place, and update text files (e.g, .tex) to reflect the new image paths
ct compress-images ~/paper/my-paper/figures -i -u ~/paper/my-paper/

Usage

# Compress images by specifying image names.
# The compressed image will have a prefix "compressed_".
ct compress-images a.png b.png c.jpg

# Compress images in-place.
# The original images will be deleted, even if a .png file is converted to .jpg.
ct compress-images a.png b.png c.jpg -i

# Compress images in the current directory, recursively.
ct compress-images .

# Compress images with -i (in-place) and -q (quality) options.
# The default quality is 95.
ct compress-images . -i -q 95

# Compress images and update text files within the root path
# This is the original purpose of this PR.
ct compress-images ~/paper/my-paper/figures --inplace --update_texts_in_dir ~/paper/my-paper/

Changes

  • fix(io.py): change imwrite function to accept quality parameter for JPEG images to allow customization of output quality
  • feat(cli.py): add compress-images subcommand to the command-line interface to allow users to compress images
  • feat(compress_images.py): add implementation for compress-images subcommand, including support for compressing PNG images to JPG format
  • feat(utility.py): add query_yes_no function to provide a utility function for asking yes/no questions to the user

@yxlao yxlao marked this pull request as ready for review October 27, 2023 14:08
@yxlao yxlao changed the title Add command line tool for compressing images ct compress-images New: Add command line tool for compressing images ct compress-images Oct 27, 2023
@yxlao yxlao changed the title New: Add command line tool for compressing images ct compress-images new: command line tool for compressing images ct compress-images Oct 27, 2023
@yxlao yxlao merged commit f1e0cf1 into master Oct 27, 2023
3 checks passed
@yxlao yxlao deleted the yixing/comparess-images branch October 27, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant