A Publish plugin that helps running ImageMagick commands while building any Publish website.
To install it into your Publish package, add it as a dependency within your Package.swift
manifest:
let package = Package(
...
dependencies: [
...
.package(url: "https://github.com/mvolpato/magickpublishplugin", from: "0.3.0")
],
targets: [
.target(
...
dependencies: [
...
"MagickPublishPlugin"
]
)
]
...
)
Then import SplashPublishPlugin wherever you’d like to use it:
import MagickPublishPlugin
For more information on how to use the Swift Package Manager, check out this article, or its official documentation.
You need ImageMagick version 6 to use the optimizeForWeb(imagesInFolder: String)
method.
You can use other methods with version 7.
The plugin can then be used within any publishing pipeline like this:
import MagickPublishPlugin
...
try DeliciousRecipes().publish(using: [
...
.installPlugin(.optimizeForWeb(imagesInFolder: "Output/assets/images/blog/"))
...
])
which will use a quite good image transformation by Dave Newton.
If you want more control over the transformation you can use, for instance,
import MagickPublishPlugin
...
try DeliciousRecipes().publish(using: [
.installPlugin(
...
.magick(arguments: [
"mogrify",
"-thumbnail",
"400",
],
imagesFolder: "Output/assets/images/blog/")
)
...
])
You can also run the command on a single file:
import MagickPublishPlugin
...
try DeliciousRecipes().publish(using: [
.installPlugin(
...
.magick(arguments: [
"mogrify",
"-thumbnail",
"400",
],
imageFile: "Output/assets/images/blog/my-cat-eating-a-burrito.jpg")
)
...
])
You probably want to run this step after .copyResources()
.