-
Notifications
You must be signed in to change notification settings - Fork 270
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
Supported media file types / extensions #332
Comments
hey @PatMyron I had this thought the other day about svgs, but couldn't find a good dotnet optimizer for them and I naively started my own (https://github.com/dabutvin/SvgClean) I bet we can find existing optimizers for videos + pdfs though! I hadn't considered them before. |
FFmpeg? |
I recommend integrating with https://github.com/svg/svgo which does an excellent job in crunching down SVGs. It'd be great to have ImgBot take care of those. |
@geeknoid that would be really cool. I wonder what the best way to fit that into the rest of the compression workflow would be, given that svgo is all JavaScript |
svgo can run on a specific file, on a specific directory, or on a specific directory recursively. I don't know how ImgBot is put together, but if I were to hack this together, I'd just kick off "svgo -r -f " as an external command. Any file it modifies, you include in the PR you post. Now to run svgo, you would need to install it (npm install svgo -g) and then use the npx tool with it (npx svgo ). If this isn't working for some reason, an alternate solution is to create a docker image that contains svgo and use 'docker run' to execute it. |
It would be great to get svgo runnable as an executable, alternatively we would have to install node on the container - might not be so bad |
just opened #386 to start adding svg support with svgo. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@dabutvin re-open? |
SVG support is in!!!! |
see #488 for an example of an issue for adding a new compression library. |
Any update of pdf compression? It would be really nice for people that use LaTex. |
Hi @Matt-Gleich ! I'm totally cool with adding pdf compression. You recommend any libraries or tools that we should look at? |
A quick DuckDuckGo search brought up some useful tutorials on how to compress PDFs in C# As far as anything that I have first-hand experience with, no I have done no work with C#. |
@dabutvin is this project still being actively developed in 2023? I would be interested in the PDF compression/optimization support - is this already an accepted feature and just needs someone to take time to implement PDF compression in C#? Would guess that there would be libraries for this too... 🤔 |
Alternative 1: I've also created an issue in the GitHub issues for Calibre Image Actions: |
Alternative 2A separate GitHub Actions workflow to do this using name: Compress PDFs
on:
pull_request:
# Run only when PDF files are added or changed
paths:
- '**.pdf'
jobs:
build:
# Only run on Pull Requests within the same repository, and not from forks.
if: github.event.pull_request.head.repo.full_name == github.repository
name: Compress PDFs
runs-on: ubuntu-latest
steps:
- name: Run apt update
run: sudo apt update
- name: Install Ghostscript for compression
run: sudo apt install -y ghostscript
- name: Checkout Repo
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Compress PDFs
run: |
find . -type f -iname '*.pdf' -not -path "./node_modules/*" | while read file; do
echo "Compressing $file"
# Compress the file for screen using Ghostscript
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile="./temp.pdf" "$file"
mv ./temp.pdf "$file"
done
- name: Commit files
run: |
git config user.email github-actions@github.com
git config user.name github-actions
# Discard modified compressed files that are not more
# than 10KB smaller than the previous version
git ls-files -z --modified '*.pdf' | while IFS= read -r -d '' file; do
old_size=$(git cat-file -s "HEAD:$file")
new_size=$(wc -c < "$file" | tr -d ' ')
if [[ $(($old_size - $new_size)) -lt 10000 ]]; then
echo "Discarding changes to $file, compressed file size $new_size is not >10KB smaller than old size $old_size"
git checkout -- "$file"
continue
fi
echo "Compressed $file from $old_size to $new_size bytes"
done
git add **/*.pdf
if [ -z "$(git status --porcelain)" ]; then
exit 0
fi
git commit -m "Compress PDFs"
git push origin HEAD:${{ github.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.PDF_COMPRESSION_GITHUB_TOKEN }} |
These seem like the current supported file extensions:
https://github.com/dabutvin/ImgBot/blob/392f7b20e4117e363b78e2537e4d915cabefcc26/Common/KnownImgPatterns.cs#L5
Would love additional formats like
.svg
,.pdf
, and audio+video formats like.mp4
The text was updated successfully, but these errors were encountered: