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

Update aio cli #213

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
strategy:
matrix:
node-version: [14.16.1, 14.17]
node-version: [18.14.2]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup unit test environment
run: sudo apt-get install librsvg2-bin imagemagick exiftool
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -29,15 +29,15 @@ jobs:
run: uname -a
- name: Run directory
run: pwd
- name: Install aio
run: npm install -g @adobe/aio-cli@8.2.0
- name: Install aio CLI
run: npm install -g @adobe/aio-cli@9.4.1
- name: Log aio details
run: aio info
- name: Docker login
run: docker login -u $REGISTRY_ID -p $REGISTRY_SECRET adobeassetcompute.azurecr.io
env:
REGISTRY_ID: ${{ secrets.AZURE_CONTAINER_REGISTRY_ID }}
REGISTRY_SECRET: ${{ secrets.AZURE_CONTAINER_REGISTRY_SECRET }}
REGISTRY_SECRET: ${{ secrets.AZURE_CONTAINER_REGISTRY_SECRET }}
- name: Install dependencies (all)
run: npm install
- name: Run unit tests
Expand All @@ -49,17 +49,17 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: npx @adobe/sizewatcher
semantic-release:
runs-on: ubuntu-latest
needs: [build]
if: ${{ !contains(github.event.head_commit.message, '[ci skip]') && github.ref == 'refs/heads/master' }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js 12.19
- name: Use Node.js 12.19 for semantic release
uses: actions/setup-node@v1
with:
node-version: "14.17"
Expand Down
57 changes: 44 additions & 13 deletions lib/postprocessing/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
"interlace",
"dpi",
"convertToDpi",
"watermark"
"watermark",
"pdfbgcolor"
]);

const SRGB_COLOR_PROFILE_FILE = process.env.SRGB_COLOR_PROFILE_FILE;
Expand Down Expand Up @@ -191,7 +192,6 @@
if (format) {
return metadata.FileType === format;
}

return false;
}

Expand Down Expand Up @@ -473,7 +473,7 @@
img = convertSvg(img, instructions);
} else {
// raster
img = handleTransparency(img, instructions.fmt);
img = handleTransparency(img, instructions);
}

// handle exif orientation
Expand Down Expand Up @@ -623,12 +623,10 @@
* @param {Object} directories working directories of the current activation
*/
async function imagePostProcess(intermediateRendition, rendition, directories) {

const img = await read(intermediateRendition.path);
img.setFormat(rendition.instructions.fmt);

await applyOperations(img, intermediateRendition, rendition, directories);

await applyOutputProperties(img, rendition.instructions);

await write(img, rendition.path);
Expand All @@ -639,23 +637,56 @@
// Only using width because ImageMagick will use the smallest value whether it be width or height
const width = instructions.width || SVG_DEFAULT_WIDTH;

img = handleTransparency(img, instructions.fmt);
img = handleTransparency(img, instructions);

// some svgs have no size (only percentage width/height), so we scale them to our target size
img.in("-size", `${width}`); // 2020-11-10 img.rawSize() will not be applied at the correct time and the SVG will be upscaled resulting in a fuzzy final rendition
return img;
}

// gm("img.png").set(attribute, value)
function handleTransparency(img, fmt) {
if (FORMAT_SUPPORTS_TRANSPARENCY[fmt]) {
img.background(DEFAULT_TRANSPARENCCY_BACKGROUND); // Keep transparency
function parseBackgroundColor(instructions){
let inputBackgroundColor = instructions.pdfbgcolor;
if(!inputBackgroundColor) return null;

if(typeof inputBackgroundColor === 'string') {
if(inputBackgroundColor.match(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)){
// HEX color
return inputBackgroundColor;
} else if(inputBackgroundColor.match(/^\d+$/)) {
// Possibly the numerical value to apply to the R, G and B channels
inputBackgroundColor = Number.parseInt(inputBackgroundColor, 10);
} else {
throw new GenericError(`Invalid background color set in instructions (value set was: ${instructions.pdfbgcolor})`);
}
}

// If we are here, we have numerical values for the color channels
// Verify the numerical value to apply to the R, G and B channels
if(Number.isInteger(inputBackgroundColor)
&& inputBackgroundColor >= 0
&& inputBackgroundColor <= 255){
return `rgb(${inputBackgroundColor},${inputBackgroundColor},${inputBackgroundColor})`;
} else {
img.background(DEFAULT_BACKGROUND_COLOR); // Change tranparency background to default background color
img.flatten(); // forces the image on its background to "commit" the background
throw new GenericError(`Invalid background color values set for RGB channels in instructions: ${instructions.pdfbgcolor}`);
}
}

return img;
function handleTransparency(img, instructions) {
if(instructions.pdfbgcolor) {
// replacing transparency with a color defined in instructions
// (disregard if the format supports keeping transparency or not)
const backgroundColor = parseBackgroundColor(instructions);
img.background(backgroundColor);
img.flatten();
} else {
if (FORMAT_SUPPORTS_TRANSPARENCY[instructions.fmt]) {
img.background(DEFAULT_TRANSPARENCCY_BACKGROUND); // Keep transparency
} else {
img.background(DEFAULT_BACKGROUND_COLOR); // Change tranparency background to default background color
img.flatten(); // forces the image on its background to "commit" the background
}
}
return img;

Check failure on line 689 in lib/postprocessing/image.js

View workflow job for this annotation

GitHub Actions / build (18.14.2)

Expected indentation of 4 spaces but found 2
}

module.exports = {
Expand Down
Loading
Loading