Swiftpack.co -  Package - nashysolutions/Vice
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
nashysolutions/Vice
A library / executable for resizing png images.
.package(url: "https://github.com/nashysolutions/Vice.git", from: "2.1.0")

Vice

Build Status

A command line tool for resizing png images. The underlying API is also available, should you want to include it in your development projects.

Usage

To resize to 100 width x 200 height.

$ vice ~/Desktop/Filename.png 100 200

To maintain aspect ratio

$ vice -r ~/Desktop/Filename.png 100 9999

Man Page

USAGE: vice <file> <width> <height> [--ratio]

ARGUMENTS:
  <file>                  A local image file. 
  <width>                 The target width of the image. 
  <height>                The target height of the image. 

OPTIONS:
  -r, --ratio             Maintain aspect ratio 
  -h, --help              Show help information.

Jaws API

The underlying core library is also available as a product (see installation below).

import Files // github.com:JohnSundell/Files
import Jaws

let file = try File(path: "~/myfile.png")
let targetSize = Size(width: width, height: height)
let jaws = Jaws(file: file, targetSize: targetSize, maintainRatio: false)
try jaws.resize()

Installation

Install Swift.

Vice Command Line Tool

$ git clone https://github.com/nashysolutions/Vice.git
$ cd Vice
$ swift build -c release
$ cd .build/release
$ cp -f vice /usr/local/bin/vice

If you have any issues with unix directories this article might be helpful.

Jaws Library

let package = Package(
    name: "MyTool",
    products: [
        .executable(name: "tool", targets: ["MyTool"]),
    ],
    dependencies: [
        .package(name: "Vice", url: "https://github.com/nashysolutions/Vice.git", .upToNextMinor(from: "2.0.0"))
    ],
    targets: [
        .target(
            name: "MyTool", 
            dependencies: [
                .product(name: "Jaws", package: "Vice")
            ])
    ]
)

Swift 5.3 only knows how to skip dependencies not used by any product, which in this package is none. This is a limitation at the moment with the Swift package manager.

As a result, if you mark your target as depending on the Jaws product, Swift will download all the source for all the dependencies in this package.

Further, the entire Vice package will be downloaded so that files such as the README and other such documentation is available.

That being said, only the source required for Jaws will be compiled.

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