Skip to content

Commit

Permalink
Merge pull request #4 from lunatic-fox/develop
Browse files Browse the repository at this point in the history
Code adjustments and add support to PS
  • Loading branch information
lunatic-fox authored Nov 17, 2022
2 parents 610a42a + 5af222f commit 3640d42
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- main
- develop
jobs:
test-actions:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -64,3 +63,11 @@ jobs:
output: ./logo6 # The path will be converted to "./logo6.pdf"
format: pdf

- name: Convert EPS to PS with "input" and "format" defined, but with incomplete "output"
if: success()
uses: ./
with:
input: ./.github/workflows/logo.eps
output: ./logo7 # The path will be converted to "./logo7.ps"
format: ps

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- **Vector formats**
- `.svg`
- `.ps`
- `.pdf`

## Usage
Expand Down Expand Up @@ -52,11 +53,10 @@ format:

# Optional. Path to the output file.
# Patterns: "" | "./" | "./dirname/" | "./filename" | "./filename.xyz"
# ".xyz" = supported formats
output: ./pathTo/outputFilename.xyz
output: ./pathTo/outputFilename

# Optional. Format of the output file.
# Options: "png" | "bmp" | "tiff" | "jpeg" | "svg" | "pdf"
# Options: "png" | "bmp" | "tiff" | "jpeg" | "svg" | "ps" | "pdf"
format: png
```
---
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: EPS 2 Image
author: lunatic-fox
description: Convert an EPS file to Image formats (PNG, JPEG, TIFF or BMP) or to Vector formats (SVG or PDF).
description: Convert an EPS file to Image formats (PNG, JPEG, TIFF or BMP) or to Vector formats (SVG, PS or PDF).

inputs:
input:
Expand Down
49 changes: 20 additions & 29 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,29 @@ input="$1"
output="$2"
format="$3"

outputFormats="jpeg|bmp|tiff|png|pdf|svg"
outputFormats="jpeg|bmp|tiff|png|pdf|svg|ps"

# Echo with foreground color
# $1 message; $2 red; $3 green; $4 blue
color() {
echo -e "\033[38;2;$2;$3;$4m$1\033[0m"
}
color() { echo -e "\033[38;2;$2;$3;$4m$1\033[0m"; }

error() {
color ":: Error :: $1" 255 0 0
exit 1
}

replace() {
echo $1 | sed -E "s/$2/$3/"
}
# Check if the `.eps` exists
if [[ ! -f $input ]]; then
error "Parameter \"input\" does not exist in \"$input\""
fi

replace() { echo $1 | sed -E "s/$2/$3/"; }

# Change format
# $1 path; $2 extension
changeFmt() {
local r=$(replace $1 '(.+\/)+(.+)\..+$' '\1\2')
echo "$r.$2"
}
changeFmt() { echo "$(replace $1 '(.+\/)+(.+)\..+$' '\1\2').$2"; }

removeFmt() {
local r=$(replace $1 '(.+\/)+(.+)\..+$' '\1\2')
echo "${r}$2"
}
removeFmt() { echo $(replace $1 '(.+\/)+(.+)\..+$' '\1\2'); }

# Validates the $format input parameter
isValidFormat() {
Expand All @@ -43,11 +38,6 @@ isValidFormat() {
fi
}

# Check if the `.eps` exists
if [ ! -f $input ]; then
error "Parameter \"input\" does not exist in \"$input\""
fi

isValidFormat $format

defaultFilename=$(replace $input '(.+\/)+(.+)\.eps$' '\2')
Expand All @@ -72,42 +62,43 @@ case $output in
format=$defaultOutputFormat;;
esac

if [[ $format == +(jpeg|tiff|png|svg) ]]; then toCairo=true; fi
if [[ $format == +(jpeg|tiff|png|svg|ps) ]]; then toCairo=true; fi

if [[ $format == +(jpeg|tiff|png|pdf|svg) ]]; then
if [[ $format == +(jpeg|tiff|png|pdf|svg|ps) ]]; then
device="pdfwrite"
fmt=$format
format="pdf"
output=$(changeFmt $output "pdf")
else
device="bmp16m"
isRaster="-dGraphicsAlphaBits=4"
isBMP="-dGraphicsAlphaBits=4"
fi

dirOutput=$(replace $output '(.+\/).+$' '\1')

if [ ! -d $dirOutput ]; then mkdir -p $dirOutput; fi

gs $isRaster -sDEVICE=$device -dEPSCrop -o $output -q $input
gs $isBMP -sDEVICE=$device -dEPSCrop -o $output -q $input

if [[ $toCairo ]]; then
input=$output

case $fmt in
svg)
output=$(changeFmt $input "svg")
pdftocairo -svg $input $output;;
+(svg|ps))
output=$(changeFmt $input $fmt)
pdftocairo -$fmt $input $output;;
+(png|tiff))
output=$(removeFmt $input);
pdftocairo -singlefile -$fmt -transp $input $output;;
jpeg)
output=$(removeFmt $input);
pdftocairo -singlefile -$fmt -jpegopt quality=100,optimize=y $input $output;;
pdftocairo -singlefile -$fmt -jpegopt quality=100,optimize=y $input $output
wait
mv "$output.jpg" "$output.jpeg";;
esac

wait

if [[ $fmt == "jpeg" ]]; then mv "$output.jpg" "$output.jpeg"; fi
if [[ $fmt == "tiff" ]]; then mv "$output.tif" "$output.tiff"; fi
if [[ $fmt == +(png|jpeg|tiff) ]]; then output="$output.$fmt"; fi

Expand Down

0 comments on commit 3640d42

Please sign in to comment.