Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make 🖼 with SPM #roppongiswift/make_image_with_spm

249b3122eee454c0a818bfe7851418e4?s=47 fromkk
May 23, 2018

Make 🖼 with SPM #roppongiswift/make_image_with_spm

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

249b3122eee454c0a818bfe7851418e4?s=128

fromkk

May 23, 2018
Tweet

More Decks by fromkk

Other Decks in Programming

Transcript

  1. Make ! with SPM Roppongi.swift #3 © fromkk 2018 1

  2. Who is me? Kazuya Ueoka iOS application engineer in Timers

    inc. Twitter: @fromkk Github: fromkk Qiita: fromkk © fromkk 2018 2
  3. લఏ • macOS High Sierra • Xcode 9.3 © fromkk

    2018 3
  4. ݕ౼ͨ͠πʔϧ • Imagemagick • GD Graphics Library © fromkk 2018

    4
  5. ࠓճ͸ GD Λར༻ © fromkk 2018 5

  6. ԿނAppKit࢖Θͳ͍ͷ͔ • GDͳΒLinux͔ΒͰ΋ར༻ग़དྷΔҝ © fromkk 2018 6

  7. GDͷΠϯετʔϧ brew install gd © fromkk 2018 7

  8. Swift͔ΒCݴޠͷϥΠϒϥϦΛར༻͢Δ © fromkk 2018 8

  9. module.modulemap Λ࡞੒ mkdir ./GD && cd $_ touch module.modulemap ©

    fromkk 2018 9
  10. 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
  11. ಉ͡֊૚ʹ Package.swift Λ࡞੒ import PackageDescription let package = Package( name:

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

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

    package init --type executable © fromkk 2018 13
  14. 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
  15. Ұ౓Ϗϧυ͢Δ 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
  16. XcodeprojΛ࡞੒ swift package generate-xcodeproj © fromkk 2018 16

  17. ϑΥϧμߏ੒ 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
  18. GDͷجૅ © fromkk 2018 18

  19. ը૾৽ن࡞੒ import GD let width: Int32 = 640 let height:

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

    fclose(handler) } gdImagePng(image, handler) © fromkk 2018 20
  21. ը૾߹੒ 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
  22. จࣈྻΛॻ͖ࠐΉ 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
  23. ࡞ͬͯΈͨπʔϧ https://github.com/fromkk/TestSummaries XCTestͷUIςετͷ݁ՌΛΠΠײ͡Ͱݟ͍ͨ(Qiita) Πϯετʔϧํ๏ brew install fromkk/TestSummaries/testsummaries © fromkk 2018

    23
  24. Demo © fromkk 2018 24

  25. ݁Ռ © fromkk 2018 25

  26. ·ͱΊ • XCTestͰࡱͬͨεΫγϣΛը૾ʹ·ͱΊͯνʔϜʹڞ༗ग़ དྷΔ༷ʹ͠·ͨ͠ • Homebrew͔Β୭Ͱ΋Πϯετʔϧग़དྷ·͢ • ·ͩ·ͩաڈͷࢿ࢈Λ׆༻͢ΔࣄͰศརͳπʔϧ͸࡞ΕΔ © fromkk

    2018 26
  27. PR 1 © fromkk 2018 27

  28. © fromkk 2018 28

  29. © fromkk 2018 29

  30. © fromkk 2018 30

  31. PR 2 © fromkk 2018 31

  32. https://pre-wwdc.connpass.com/event/83346/ © fromkk 2018 32

  33. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ © fromkk 2018 33