Make 🖼 with SPM #roppongiswift/make_image_with_spm

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
fromkk
May 23, 2018

Make 🖼 with SPM #roppongiswift/make_image_with_spm

Roppongi.swift #3で発表してきた内容です。
Swift Package Managerで画像を生成する事にトライしました。

fromkk

May 23, 2018

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

33 slides
  1. Who is me? Kazuya Ueoka iOS application engineer in Timers

    inc. Twitter: @fromkk Github: fromkk Qiita: fromkk © fromkk 2018 2
  2. module.modulemap ಺༰ module GD [system] { header "/usr/local/include/gd.h" header "/usr/local/include/gdfontt.h"

    header "/usr/local/include/gdfonts.h" header "/usr/local/include/gdfontl.h" header "/usr/local/include/gdfontg.h" header "/usr/local/include/gdfontmb.h" link "gd" export * } © fromkk 2018 10
  3. ಉ͡֊૚ʹ Package.swift Λ࡞੒ import PackageDescription let package = Package( name:

    "GD", pkgConfig: "gdlib", providers: [ .brew(["gd"]) ] ) © fromkk 2018 11
  4. GitͰλά෇͚ git init . git add . git commit -m

    "Initial commit" git tag 0.0.1 -m "Initial commit" © fromkk 2018 12
  5. ϓϩδΣΫτΛ࡞੒ cd ../ && mkdir ./MyProject && cd $_ swift

    package init --type executable © fromkk 2018 13
  6. Package.swift Λฤू import PackageDescription let package = Package( name: "MyProject",

    dependencies: [ .package(url: "../GD", from: "0.0.1"), ], targets: [ .target( name: "MyProject", dependencies: []), ] ) © fromkk 2018 14
  7. Ұ౓Ϗϧυ͢Δ swift build ↓ Fetching /PATH/TO/GD Cloning /PATH/TO/GD Resolving /PATH/TO/GD

    at 0.0.1 Compile Swift Module 'MyProject' (1 sources) Linking ./.build/x86_64-apple-macosx10.10/debug/MyProject GD ͕ϑΣον͞ΕͯͪΌΜͱϏϧυ͞Ε͍ͯΔࣄΛ֬ೝ © fromkk 2018 15
  8. ϑΥϧμߏ੒ tree . . ├── GD │ ├── Package.swift │

    └── module.modulemap └── MyProject ├── MyProject.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ └── fromkk.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ ├── xcshareddata │ │ └── xcschemes │ │ ├── MyProject-Package.xcscheme │ │ └── xcschememanagement.plist │ └── xcuserdata │ └── fromkk.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── Package.resolved ├── Package.swift ├── README.md ├── Sources │ └── MyProject │ └── main.swift └── Tests © fromkk 2018 17
  9. ը૾৽ن࡞੒ import GD let width: Int32 = 640 let height:

    Int32 = 480 let image = gdImageCreateTrueColor(width, height) © fromkk 2018 19
  10. ը૾อଘ import GD let handler = fopen("path/to/image.png", "wb") defer {

    fclose(handler) } gdImagePng(image, handler) © fromkk 2018 20
  11. ը૾߹੒ import GD let file = fopen("copy/image/path.png", "rb") defer {

    fclose(file) } let copyImage = gdImageCreateFromPng(file) gdImageCopy(image, copyImage, dstX, dstY, srcX, srcY, width, height) © fromkk 2018 21
  12. จࣈྻΛॻ͖ࠐΉ import GD let blackColor = gdImageColorAllocate(image, 0, 0, 0)

    defer { gdImageColorDeallocate(image, blackColor) } let text = UnsafeMutablePointer<UInt8>(mutating: "hogehoge") gdImageString(image, gdFontGetSmall(), x, y, text, blackColor) © fromkk 2018 22

More Decks by fromkk

Other Decks in Programming