Swiftpack.co - mvolpato/magickpublishplugin as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mvolpato.
mvolpato/magickpublishplugin 0.3.0
An ImageMagick plugin for the Publish static site generator
⭐️ 2
🕓 4 weeks ago
.package(url: "https://github.com/mvolpato/magickpublishplugin.git", from: "0.3.0")

ImageMagick plugin for Publish

A Publish plugin that helps running ImageMagick commands while building any Publish website.

Installation

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 MagickPublishPlugin 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.

Usage

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().

GitHub

link
Stars: 2
Last commit: 4 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v0.3.0
3 years ago

Assume user adds ImageMagick to its PATH

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics