Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This is the main way people contribute. Add one shop end to end.
}
```

3. **Photo** — must be **under 300KB**, EXIF-stripped, longest side ~800px, named `{shopId}-001.jpg` (`-002`, … for more). Use the helper (macOS `sips` + `jpegtran`):
3. **Photo** — must be **under 300KB**, EXIF-stripped, longest side ~800px, named `{shopId}-001.jpg` (`-002`, … for more). Use the helper (macOS `swift` + `sips` + `jpegtran`; it also applies the EXIF orientation so photos stay upright):

```sh
mkdir -p content/shops/{shopId}
Expand Down
2 changes: 1 addition & 1 deletion tools/resize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ new_path=$2
echo "Move: $org_path to $new_path"
mv $org_path $new_path
echo "Resize and Optimize: $new_path"
sips -Z 800 $new_path
swift "$(dirname "$0")/resize.swift" $new_path $new_path
jpegtran -copy none -optimize -outfile $new_path $new_path
sips -g pixelHeight -g pixelWidth $new_path
29 changes: 29 additions & 0 deletions tools/resize.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Foundation
import ImageIO

let args = CommandLine.arguments
guard args.count == 3 else {
FileHandle.standardError.write("Usage: swift resize.swift input.jpg output.jpg\n".data(using: .utf8)!)
exit(1)
}

let options = [
kCGImageSourceCreateThumbnailFromImageAlways: true,
kCGImageSourceCreateThumbnailWithTransform: true,
kCGImageSourceThumbnailMaxPixelSize: 800,
] as CFDictionary

guard let source = CGImageSourceCreateWithURL(URL(fileURLWithPath: args[1]) as CFURL, nil),
let image = CGImageSourceCreateThumbnailAtIndex(source, 0, options),
let destination = CGImageDestinationCreateWithURL(
URL(fileURLWithPath: args[2]) as CFURL, "public.jpeg" as CFString, 1, nil)
else {
FileHandle.standardError.write("Failed to resize \(args[1])\n".data(using: .utf8)!)
exit(1)
}

CGImageDestinationAddImage(destination, image, nil)
guard CGImageDestinationFinalize(destination) else {
FileHandle.standardError.write("Failed to write \(args[2])\n".data(using: .utf8)!)
exit(1)
}
Loading