diff --git a/CONFIG.md b/CONFIG.md index 391f86a6..0e842de4 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -99,6 +99,11 @@ android: # Parameters for exporting images images: # Image file format: svg or png - format: png - + format: webp + # Format options for webp format only + webpOptions: + # Encoding type: lossy or lossless + encoding: lossy + # Encoding quality in percents. Only for lossy encoding. + quality: 90 ``` diff --git a/Examples/AndroidExample/.idea/vcs.xml b/Examples/AndroidExample/.idea/vcs.xml index 6c0b8635..b2bdec2d 100644 --- a/Examples/AndroidExample/.idea/vcs.xml +++ b/Examples/AndroidExample/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_empty.png deleted file mode 100644 index 4a967b28..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_empty.webp new file mode 100644 index 00000000..86701fe9 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_error.png deleted file mode 100644 index 9352ad95..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_error.webp new file mode 100644 index 00000000..747b84b9 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_internet.png deleted file mode 100644 index db6700e8..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_internet.webp new file mode 100644 index 00000000..e740b195 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-hdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_empty.png deleted file mode 100644 index 2509599c..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_empty.webp new file mode 100644 index 00000000..2c40a1cc Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_error.png deleted file mode 100644 index 96345b78..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_error.webp new file mode 100644 index 00000000..48baf62a Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_internet.png deleted file mode 100644 index 610441b3..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_internet.webp new file mode 100644 index 00000000..917a8e07 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-mdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_empty.png deleted file mode 100644 index e5e6f82d..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_empty.webp new file mode 100644 index 00000000..38be55c2 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_error.png deleted file mode 100644 index 01910b88..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_error.webp new file mode 100644 index 00000000..772751cb Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_internet.png deleted file mode 100644 index a0b1a159..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_internet.webp new file mode 100644 index 00000000..c3bfb320 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-hdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_empty.png deleted file mode 100644 index 48d86612..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_empty.webp new file mode 100644 index 00000000..4f9b1508 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_error.png deleted file mode 100644 index e65fe0ee..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_error.webp new file mode 100644 index 00000000..c204f209 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_internet.png deleted file mode 100644 index 23b4956e..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_internet.webp new file mode 100644 index 00000000..e9002bf3 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-mdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_empty.png deleted file mode 100644 index 84284040..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_empty.webp new file mode 100644 index 00000000..0b37aa9b Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_error.png deleted file mode 100644 index ae79b2cd..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_error.webp new file mode 100644 index 00000000..70b44eec Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_internet.png deleted file mode 100644 index bff22487..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_internet.webp new file mode 100644 index 00000000..87777975 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xhdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_empty.png deleted file mode 100644 index 026004a1..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_empty.webp new file mode 100644 index 00000000..20169c8a Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_error.png deleted file mode 100644 index fc2d55b0..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_error.webp new file mode 100644 index 00000000..80b54928 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_internet.png deleted file mode 100644 index c43a027f..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_internet.webp new file mode 100644 index 00000000..d80d9630 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xxhdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_empty.png deleted file mode 100644 index 1c8ef871..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_empty.webp new file mode 100644 index 00000000..7aa44d20 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_error.png deleted file mode 100644 index f181e4a5..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_error.webp new file mode 100644 index 00000000..d75268c3 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_internet.png deleted file mode 100644 index aa5636e2..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_internet.webp new file mode 100644 index 00000000..0470932c Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-night-xxxhdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_empty.png deleted file mode 100644 index 266e40cb..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_empty.webp new file mode 100644 index 00000000..00156253 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_error.png deleted file mode 100644 index 6ee3ec4d..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_error.webp new file mode 100644 index 00000000..ca2dbe15 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_internet.png deleted file mode 100644 index 0697235c..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_internet.webp new file mode 100644 index 00000000..21f2e36f Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xhdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_empty.png deleted file mode 100644 index 86524f86..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_empty.webp new file mode 100644 index 00000000..0f414cdb Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_error.png deleted file mode 100644 index 9d690169..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_error.webp new file mode 100644 index 00000000..10565093 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_internet.png deleted file mode 100644 index c6995897..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_internet.webp new file mode 100644 index 00000000..73aac794 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xxhdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_empty.png b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_empty.png deleted file mode 100644 index df40c9cd..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_empty.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_empty.webp b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_empty.webp new file mode 100644 index 00000000..6350751b Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_empty.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_error.png b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_error.png deleted file mode 100644 index fc4260bb..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_error.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_error.webp b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_error.webp new file mode 100644 index 00000000..b12eac19 Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_error.webp differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_internet.png b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_internet.png deleted file mode 100644 index 4bf95772..00000000 Binary files a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_internet.png and /dev/null differ diff --git a/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_internet.webp b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_internet.webp new file mode 100644 index 00000000..4f5dd52b Binary files /dev/null and b/Examples/AndroidExample/app/src/main/res/drawable-xxxhdpi/img_zero_internet.webp differ diff --git a/Examples/AndroidExample/figma-export.yaml b/Examples/AndroidExample/figma-export.yaml index 3db72d49..b59ac835 100644 --- a/Examples/AndroidExample/figma-export.yaml +++ b/Examples/AndroidExample/figma-export.yaml @@ -6,4 +6,11 @@ figma: android: mainRes: ./app/src/main/res images: - format: png + # Image file format: svg, png or webp + format: webp + # Format options for webp format only + webpOptions: + # Encoding type: lossy or lossless + encoding: lossy + # Encoding quality in percents. Only for lossy encoding. + quality: 85 diff --git a/README.md b/README.md index 78e1d5a8..7240548c 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ Colors will be exported to `values/colors.xml` and `values-night/colors.xml` fil Icons will be exported to `drawable` directory as vector xml files. Vector images will be exported to `drawable` and `drawable-night` directories as vector `xml` files. -Raster images will be exported to `drawable-???dpi` and `drawable-night-???dpi` directories as `png` files. +Raster images will be exported to `drawable-???dpi` and `drawable-night-???dpi` directories as `png` or `webp` files. ## Installation @@ -215,6 +215,8 @@ Raster images will be exported to `drawable-???dpi` and `drawable-night-???dpi` ``` brew install RedMadRobot/formulae/figma-export ``` +If you want to export raster images in WebP format install [cwebp](https://developers.google.com/speed/webp/docs/using) command line utility. +brew install webp ### CocoaPods + Fastlane Add the following line to your Podfile: @@ -255,7 +257,7 @@ Run `fastlane sync_colors` to run FigmaExport. `./figma-export images -i figma-export.yaml` - To export typography use `typography` argument: + To export typography (iOS only) use `typography` argument: `./figma-export typography -i figma-export.yaml` diff --git a/Sources/FigmaExport/Input/Params.swift b/Sources/FigmaExport/Input/Params.swift index 0ef597a1..9ee6fb4b 100644 --- a/Sources/FigmaExport/Input/Params.swift +++ b/Sources/FigmaExport/Input/Params.swift @@ -86,8 +86,18 @@ struct Params: Decodable { enum Format: String, Decodable { case svg case png + case webp + } + struct FormatOptions: Decodable { + enum Encoding: String, Decodable { + case lossy + case lossless + } + let encoding: Encoding + let quality: Int? } let format: Format + let webpOptions: FormatOptions? } let mainRes: URL let images: Images diff --git a/Sources/FigmaExport/Loaders/ImagesLoader.swift b/Sources/FigmaExport/Loaders/ImagesLoader.swift index d999f260..4b2fa284 100644 --- a/Sources/FigmaExport/Loaders/ImagesLoader.swift +++ b/Sources/FigmaExport/Loaders/ImagesLoader.swift @@ -35,7 +35,8 @@ final class ImagesLoader { } func loadImages(filter: String? = nil) throws -> (light: [ImagePack], dark: [ImagePack]?) { - if (platform == .android && params.android?.images.format == .png) || platform == .ios { + switch (platform, params.android?.images.format) { + case (.android, .png), (.android, .webp), (.ios, .none): let lightImages = try loadPNGImages( fileId: params.figma.lightFileId, frameName: .illustrations, @@ -52,7 +53,7 @@ final class ImagesLoader { lightImages, darkImages ) - } else { + default: let light = try _loadImages( fileId: params.figma.lightFileId, frameName: .illustrations, diff --git a/Sources/FigmaExport/Output/WebpConverter.swift b/Sources/FigmaExport/Output/WebpConverter.swift new file mode 100644 index 00000000..98f3454f --- /dev/null +++ b/Sources/FigmaExport/Output/WebpConverter.swift @@ -0,0 +1,32 @@ +import Foundation +import FigmaExportCore + +/// PNG to WebP converter +final class WebpConverter { + + enum Encoding { + case lossy(quality: Int) + case lossless + } + + private let encoding: Encoding + + init(encoding: Encoding) { + self.encoding = encoding + } + + /// Converts PNG files to WebP + func convert(file url: URL) throws { + let outputURL = url.deletingPathExtension().appendingPathExtension("webp") + + let task = Process() + task.executableURL = URL(fileURLWithPath: "/usr/local/bin/cwebp") + if case Encoding.lossless = encoding { + task.arguments = ["-lossless", url.path, "-o", outputURL.path, "-short"] + } else if case Encoding.lossy(let quality) = encoding { + task.arguments = ["-q", String(quality), url.path, "-o", outputURL.path, "-short"] + } + try task.run() + task.waitUntilExit() + } +} diff --git a/Sources/FigmaExport/Subcommands/ExportIcons.swift b/Sources/FigmaExport/Subcommands/ExportIcons.swift index d3b53301..b6123086 100644 --- a/Sources/FigmaExport/Subcommands/ExportIcons.swift +++ b/Sources/FigmaExport/Subcommands/ExportIcons.swift @@ -128,7 +128,7 @@ extension FigmaExportCommand { // 5. Convert all SVG to XML files logger.info("Converting SVGs to XMLs...") - try fileConverter.convert(inputDirectoryPath: tempDirectoryURL.path) + try svgFileConverter.convert(inputDirectoryPath: tempDirectoryURL.path) // Create output directory main/res/drawable/ let outputDirectory = URL(fileURLWithPath: android.mainRes.path) diff --git a/Sources/FigmaExport/Subcommands/ExportImages.swift b/Sources/FigmaExport/Subcommands/ExportImages.swift index 650c42e0..70efa4e2 100644 --- a/Sources/FigmaExport/Subcommands/ExportImages.swift +++ b/Sources/FigmaExport/Subcommands/ExportImages.swift @@ -107,10 +107,11 @@ extension FigmaExportCommand { ) let images = try processor.process(light: imagesTuple.light, dark: imagesTuple.dark).get() - if android.images.format == .svg { + switch android.images.format { + case .svg: try exportAndroidSVGImages(images: images, params: params, logger: logger) - } else if android.images.format == .png { - try exportAndroidPNGImages(images: images, params: params, logger: logger) + case .png, .webp: + try exportAndroidRasterImages(images: images, params: params, logger: logger) } logger.info("Done!") @@ -147,10 +148,10 @@ extension FigmaExportCommand { // Convert all SVG to XML files logger.info("Converting SVGs to XMLs...") - try fileConverter.convert(inputDirectoryPath: tempDirectoryLightURL.path) + try svgFileConverter.convert(inputDirectoryPath: tempDirectoryLightURL.path) if images.first?.dark != nil { logger.info("Converting dark SVGs to XMLs...") - try fileConverter.convert(inputDirectoryPath: tempDirectoryDarkURL.path) + try svgFileConverter.convert(inputDirectoryPath: tempDirectoryDarkURL.path) } logger.info("Writting files to Android Studio project...") @@ -185,7 +186,7 @@ extension FigmaExportCommand { try FileManager.default.removeItem(at: tempDirectoryDarkURL) } - private func exportAndroidPNGImages(images: [AssetPair], params: Params, logger: Logger) throws { + private func exportAndroidRasterImages(images: [AssetPair], params: Params, logger: Logger) throws { guard let android = params.android else { return } // Create empty temp directory @@ -207,10 +208,28 @@ extension FigmaExportCommand { // Move downloaded files to new empty temp directory try fileWritter.write(files: localFiles) + + // Convert to WebP + if android.images.format == .webp, let options = android.images.webpOptions { + logger.info("Converting PNG files to WebP...") + let converter: WebpConverter + switch (options.encoding, options.quality) { + case (.lossless, _): + converter = WebpConverter(encoding: .lossless) + case (.lossy, let quality?): + converter = WebpConverter(encoding: .lossy(quality: quality)) + case (.lossy, .none): + fatalError("Encoding quality not specified. Set android.images.webpOptions.quality in YAML file.") + } + localFiles = try localFiles.map { file in + try converter.convert(file: file.destination.url) + return file.changingExtension(newExtension: "webp") + } + } logger.info("Writting files to Android Studio project...") - // Move PNG files to main/res/drawable-XXXdpi/ + // Move PNG/WebP files to main/res/drawable-XXXdpi/ localFiles = localFiles.map { fileContents -> FileContents in let directoryName = Drawable.scaleToDrawableName(fileContents.scale, dark: fileContents.dark) let directory = URL(fileURLWithPath: android.mainRes.path).appendingPathComponent(directoryName, isDirectory: true) diff --git a/Sources/FigmaExport/main.swift b/Sources/FigmaExport/main.swift index a959ceb2..d09a91aa 100644 --- a/Sources/FigmaExport/main.swift +++ b/Sources/FigmaExport/main.swift @@ -24,7 +24,7 @@ enum FigmaExportError: LocalizedError { struct FigmaExportCommand: ParsableCommand { - static let fileConverter = VectorDrawableConverter() + static let svgFileConverter = VectorDrawableConverter() static let fileWritter = FileWritter() static let fileDownloader = FileDownloader() diff --git a/Sources/FigmaExportCore/FileContents.swift b/Sources/FigmaExportCore/FileContents.swift index 815a316f..a1952015 100644 --- a/Sources/FigmaExportCore/FileContents.swift +++ b/Sources/FigmaExportCore/FileContents.swift @@ -55,4 +55,28 @@ public struct FileContents: Equatable { self.dataFile = dataFile self.sourceURL = nil } + + /// Make a copy of the FileContents with different file extension + /// - Parameter newExtension: New file extension + public func changingExtension(newExtension: String) -> FileContents { + var newFile: FileContents + + let newFileURL = self.destination.file.deletingPathExtension().appendingPathExtension(newExtension) + let newDestination = Destination(directory: self.destination.directory, file: newFileURL) + + if let sourceURL = sourceURL { // Remote file + newFile = FileContents(destination: newDestination, sourceURL: sourceURL) + } else if let dataFile = dataFile { // On-disk file + newFile = FileContents(destination: newDestination, dataFile: dataFile) + } else if let data = data { // In-memory file + newFile = FileContents(destination: newDestination, data: data) + } else { + fatalError("Unable to change file extension.") + } + + newFile.scale = self.scale + newFile.dark = self.dark + + return newFile + } }