layout |
---|
default |
{{ site.github.project_tagline }}{:class="html-only"}
Part of the process of building an app for watchOS, iOS, or macOS is including all the image assets and app icons in your application. Each image assets or app icons requires several copies for different resolutions, different devices, and different sizes. Right now, this needs to be done by exporting all the various similar images from a major graphics application.
That means developers need to:
{:height="100px"}{:class="html-only"}
Each graphic must be manually converted and resized several times for each update.
{:height="100px"}{:class="html-only"}
An asset catalog image set will need a 1x, 2x, 3x of each graphic and App Icons may need as many 30 different sizes.
{:height="100px"}{:class="html-only"} {:height="75px"}{:class="html-only"} {:height="50px"}{:class="html-only"} {:height="25px"}{:class="html-only"} {:height="12px"}{:class="html-only"} {:height="6px"}{:class="html-only"}
- Only one file is needed for each Image Set and App Icon.
- Graphic Designers need only export a single file change each time rather than as many as serveral scaled copies.
- Resizing and conversion is done behind the scenes based on a single source image.
Speculid links a single graphic file to an Image Set or App Icon and automatically renders different resolutions, file types, and sizes for all the image specifications required.
{:height="100px"}{:class="html-only"}
Speculid automates the process so only one graphic file is needed. Add Speculid to your build process and now the conversions and resizing are automated as part of the build process. Now there is no need for anyone to manually create each size for each device every time.
{:height="100px"}{:class="html-only"}
Reduce the size of your repository by including a single vector or raster image and ignore all your automated png and pdf files at compile. That means faster remote pulls, less redundancy, and complete syncronization between sizes.
This means Speculid can...
- take multiple input file types including SVG vector files and raster PNG files
- automatically create each necessary resized raster file
- remove transparencies from PNG and SVG file for App Icons
- export to PDF for vector images in Image Sets as well as PNG
- SVG - Scalable Vector Graphics
- PNG - Portable Network Graphics
- PNG - Portable Network Graphics
- PDF - Portable Document Format
Speculid only supports being called through a command line terminal for now. Once you have copied the command to your /usr/local/bin folder you should be able to access it easily.
$ speculid --process <file>
$ speculid --help
$ speculid --version
Options:
--help Show this screen.
--version Show version.
The .speculid
file is a json
file with the image set or app icon path, the graphic file source, and optionally basic image geometry (width or height). All paths specified in the json file could be relative to the .speculid
file Assets.xcassets/Raster Image.imageset
or an absolute path /Users/leo/Documents/Projects/Speculid/examples/Assets/Assets.xcassets/Raster Image.imageset
.
Here are some examples of a .speculid
file:
{
"set" : "Assets.xcassets/Raster Image.imageset",
"source" : "layers.png",
"geometry" : "128"
}
or
{
"set" : "Assets.xcassets/iOS AppIcon.appiconset",
"source" : "geometry.svg",
"background" : "#FFFFFFFF",
"remove-alpha" : true
}
set
Set is the path to the Image Set or App Icon folder used by Xcode. For more information on Image Sets, App Icons, and Asset Catalogs, check out this article here.
source
The path to the image source file. This can be either a SVG or PNG file.
geometry
The destination geometry of image if needed (i.e. image set). It must be in the format of:
- width (ex. "128") - for specifying the width of the destination image
- xheight (ex. "x128") - for specifying the height of the destination image
You can only specify the height or the width. The other dimension is automatically calculated based on the aspect ratio of the image.
background
App Icons are required to exclude any alpha channels. In order to remove a transparency from a source PNG or SVG file, you can specify to remove the alpha channel and add a background color.
The background color can be set in a standard rgb, rgba, or hex code format (#RRGGBB or #AARRGGBB). If no alpha is specified an alpha of 1.0 is assumed.
remove-alpha
To specifically remove the alpha channel, a true boolean value must be specified. This will remove the alpha channel from the file. Make sure to specify an opaque background color when removing the alpha channel.
-
Open Sketch and create a new document using the iOS App Icon Template. If you are using an existing project, you can skip to step 3.
-
Once you are in the template, duplicate one of the icon size slices on the left side.
-
On the right size, change the preset format to SVG.
-
In the top menu, select File > Export.
-
Select your duplicated slice and select Export.
-
Select the destination for your SVG file and Save.
-
Open your Photoshop document and select File > Export > Export As....
-
Under the File Settings on the right, change the format to SVG.
-
Select Export All and choose the destination for your SVG file and Save.
With Speculid, the process of building image assets can be automated in Xcode. Here is how to setup your project the first time:
-
Create the speculid file and add it to your project folder, along with your source graphic files.
- Note: you don't need to add these files to any target membership
-
In the speculid file, Add the property for the source - the path to the SVG or PNG file.
{
"source" : "geometry.svg",
...
}
- In the speculid file, Add the property for the set - the path to the Image Set or App Icon folder.
{
"set" : "Assets.xcassets/iOS AppIcon.appiconset",
...
}
- optional In the speculid file, Add the property for the geometry - if this a conversion from a vector graphic (SVG) to an Image Set, you may want to supply the 1x size.
{
"set" : "Assets.xcassets/Raster Image.imageset",
"source" : "layers.png",
"geometry" : "128"
}
If you specify *128* in the *geometry* property, that means the width for the *1x* image will be *128 pixels*, the width for the *2x* image will be *256 pixels*, and the width for the *3x* image will be *384 pixels*. Heights will be calculated based on the aspect ratio of the SVG file.
Vector images in an image set will be converted to a iOS compatible PDF file.
- optional In the speculid file, Add the properties for the background color and alpha removal - if this a conversion to an App Icon, you should remove any background transparency and add a background color.
{
"set" : "Assets.xcassets/iOS AppIcon.appiconset",
"source" : "geometry.svg",
"background" : "#FFFFFFFF",
"remove-alpha" : true
}
See the [file format section](#file-format-and-properties) for more details.
-
Add the Run Script Build Phase to the top of your project with the following code:
find "${SRCROOT}" -name "*.speculid" -print0 | while IFS= read -r -d $'\0' line; do speculid --process "$line" & done wait
If you are using fastlane to build your application. You can use the plugin to build every
.speculid
file in your directory. -
Build the application. This will create the graphics which you will use in your asset image set or app icon.
If the asset catalog does not already have file names for each image in the asset, Speculid will automatically update the asset catalog and name the files using the following pattern:
(source file base name).(size)@(scale)~(idiom).(extension)
Examples
- logo.20x20@1x~ipad.png - 20x20 size 1x scale for iPad
- logo.60x60@3x~iphone.png - 60x60 size 3x scale for iPhone
- logo.83.5x83.5@2x~ipad.png - 83.5x83.5 size 2x scale for iPad
-
Enjoy!
Speculid ©2019, BrightDigit, LLC.