Code Monkey home page Code Monkey logo

Comments (6)

hugofalkman avatar hugofalkman commented on July 28, 2024 2

The following solves the bug:

The cropping method isn't really cropping, it adjusts to the size of the to: parameter whether it's larger or smaller than the input image.

CIConstantColorGenerator generates an image with size 0x0, so you need to apply the cropping method before returning it as output of the generate function. That means it needs to use the input image just like the other functions. The following generate function works without crashing in the Xcode 8.2.1 playground:

func generate(color: UIColor) -> Filter {
return { image in
let parameters = [kCIInputColorKey: CIColor(cgColor: color.cgColor)]
guard let filter = CIFilter(name: "CIConstantColorGenerator",
withInputParameters: parameters)
else { fatalError() }
guard let outputImage = filter.outputImage
else { fatalError() }
return outputImage.cropping(to: image.extent)
}
}

Btw the blur function returns an image larger than the input image, so it also needs cropping in the return statement. Once you have added cropping to all the other functions, cropping is no longer needed in the overlay function.

Also to avoid all the "failed to obtain sandbox extension" warning messages I added the following to the Xcode 8.2.1 playground:
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)

TheFilterType.playground.zip

from functional-swift.

chriseidhof avatar chriseidhof commented on July 28, 2024

Hi @hugofalkman, I remember we had this problem with old versions UIKit. Could you try on a recent version or on the Mac? It might also be a new problem, not sure!

from functional-swift.

hugofalkman avatar hugofalkman commented on July 28, 2024

Am on latest Xcode 8.2.1 so am sure it's a new problem. Just copy my code into a fresh Xcode playground to reproduce.

from functional-swift.

chriseidhof avatar chriseidhof commented on July 28, 2024

Thanks a lot @hugofalkman !

I'm going to leave this open until we have time to do a proper update of the book. That will also help other people stumbling over this issue.

from functional-swift.

hugofalkman avatar hugofalkman commented on July 28, 2024

This issue was closed, but I don't see an updated version of the book on Gumroad.

from functional-swift.

chriseidhof avatar chriseidhof commented on July 28, 2024

No, we're working on it =)

from functional-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.