Skip to content

Commit

Permalink
Added support for overriding the image type in the size JSON object.
Browse files Browse the repository at this point in the history
  • Loading branch information
erictompkins committed Jul 19, 2019
1 parent 31526b6 commit 1db68a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ For example, if the URL is `https://www.branchcms.com` then the file name will b

You can specify a file name for the screenshot. The file name can be just the name without the extension, or if can include the "jpg" or "png" extension. If the file name does not have an extension or it doesn't match either "jpg" or "png" extension then the correct extension based on the `type` argument will be used.

If the file name does have an extension and the extension is `jpg` or `png`, then that will always override the file type. The file type will be set to match the extension.

The file name can include a directory path. For example: `screenshots/shot-{stub}-{width}.jpg`. If it does then the full path set by the file name will be appended to the directory setting value if that was specified.

Dynamic file names
-----------------

Expand Down Expand Up @@ -309,6 +313,8 @@ The above specifies 3 URLs to get screenshots for and 3 different viewport sizes

> **NOTE: The contents of the JSON file needs to be valid JSON. Use double quotes instead of single quotes.**
Validate your JSON at [jsonlint.com](https://jsonlint.com/) if you're having any troubles.

### JSON Options

Below is a description of each of the JSON keys that you can set values for.
Expand Down Expand Up @@ -425,7 +431,8 @@ You wouldn't use all of the options as some of them override other options. For
"height": 400,
"fit": true,
"name": "small-{stub}-{quality}",
"quality": 80
"quality": 80,
"type": "png"
},
{
"width": 800,
Expand All @@ -434,7 +441,7 @@ You wouldn't use all of the options as some of them override other options. For
"dir": "medium",
"key": "medium-shot",
"delay": 1500,
"name" "med-{stub}.png"
"name": "med-{stub}.png"
}
],
"type": "jpg",
Expand Down Expand Up @@ -488,6 +495,7 @@ Below are the values that you can override in the size object
- full
- name
- quality
- type

You can also set the `key` value to specify a name for the size that can be used to replace the `{size}` placeholder in the [dynamic file name](#dynamic-file-names).

Expand Down
18 changes: 17 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ class PageShots {
fullScreen,
name,
quality,
size;
size,
type,
typeTemp;
try {
console.log('');
if (this.urls.length > 0) {
Expand All @@ -397,6 +399,8 @@ class PageShots {
dir = url.dir;
fullScreen = url.fullScreen;
name = url.name;
quality = url.quality;
type = url.type;
for (size of url.sizes) {
url.width = size.width;
url.height = size.height;
Expand Down Expand Up @@ -434,7 +438,11 @@ class PageShots {
size.quality = parseInt(size.quality);
if (size.quality > 0 && size.quality <= 100) {
url.quality = size.quality;
} else {
url.quality = quality;
}
} else {
url.quality = quality;
}

// See if the size name was set
Expand All @@ -451,6 +459,14 @@ class PageShots {
url.name = name;
}

// Check the size is specifying a type
typeTemp = this._validateType(size.type);
if (typeTemp) {
url.type = typeTemp;
} else {
url.type = type;
}

// Regenerate the file name and path
url = this._regenerateFilename(url);

Expand Down

0 comments on commit 1db68a5

Please sign in to comment.