generate the image in swift and remove dependency on imagemagic and graphicsmagick#100
Conversation
compose-icon.js
Outdated
| } | ||
|
|
||
| const hasGm = async () => { | ||
| const hasSwiftExecutable = async () => { |
There was a problem hiding this comment.
This is moot now. We know we have it.
| func perspectiveTransform(image: CGImage, width: Int, height: Int) -> CGImage? { | ||
| // Apply perspective transformation directly to the image | ||
| let ciImage = CIImage(cgImage: image) | ||
| let filter = CIFilter(name: "CIPerspectiveTransform")! |
There was a problem hiding this comment.
Use the type-safe version of the filter.
| guard let outputImage = filter.outputImage else { return nil } | ||
|
|
||
| // Create context for the final image | ||
| let context = CGContext( |
There was a problem hiding this comment.
This is repeated many times. Ask AI to DRY up the code.
| bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | ||
| ) | ||
|
|
||
| guard let ctx = context else { return nil } |
There was a problem hiding this comment.
| guard let ctx = context else { return nil } | |
| guard let context else { return nil } |
you can just shadow
| } | ||
|
|
||
| func loadImage(from path: String) -> CGImage? { | ||
| guard let url = URL(string: "file://\(path)"), |
There was a problem hiding this comment.
This is not the correct way to create a URL from path.
|
Ask AI to improve and simplify the Swift code. |
|
Is the change in |
At some point it's easier to take over. Good feedback on the code. |
| filter.setValue(ciImage, forKey: kCIInputImageKey) | ||
| filter.setValue(CIVector(x: w * 0.08, y: h), forKey: "inputTopLeft") // Top-left: inset 8% | ||
| filter.setValue(CIVector(x: w * 0.92, y: h), forKey: "inputTopRight") // Top-right: inset to 92% | ||
| filter.setValue(CIVector(x: 0, y: 0), forKey: "inputBottomLeft") // Bottom-left: no change | ||
| filter.setValue(CIVector(x: w, y: 0), forKey: "inputBottomRight") // Bottom-right: no change |
There was a problem hiding this comment.
The point of using the typed filter is to use the typed properties.
|
AI review:
Bugs / correctness
|
df10919 to
55dfc37
Compare
55dfc37 to
5f15a15
Compare
|
@sindresorhus thoughts? Unclear why the test timed-out only on node 20. |
|
@sindresorhus so? |
|
I don't have time to look into it. Try asking AI. |
fc13e01 to
d45e818
Compare
d45e818 to
adf5a6f
Compare
|
It's green now. |
|
Nice work! @sindresorhus do you publish this to npm later? This also fixes the warning in ci: npm warn deprecated gm@1.25.1: The gm module has been sunset. Please migrate to an alternative. https://github.com/aheckmann/gm?tab=readme-ov-file#2025-02-24-this-project-is-not-maintained |
This should address #57
Disclaimer: this code is mostly vibe coded. The result looks good from my testing though:
Before: