image-uploads
Skill0 starsChanged 48 days agoMITView on GitHub
Store Laravel image uploads as responsive WebP sizes plus JPEG share images for WhatsApp/Facebook previews, with face-friendly cropping of portrait photos, logo-safe 'contain' sizes, per-size URLs on models, safe deletion and a regenerate command. Use when handling image uploads, thumbnails, resizing, WebP conversion, Intervention Image, og:image sizes, cropped heads in photos, or slow pages caused by large images.
In this repository11 other files it gives its agents.
- bot-proof-formsSkill
- inertia-admin-tablesSkill
- json-ld-structured-dataSkill
- mpesa-stk-pushSkill
- paypal-checkoutSkill
- pre-push-checksSkill
- secrets-scannerSkill
- seo-crawlabilitySkill
- shared-network-rate-limitsSkill
- social-share-previewsSkill
- wordpress-migrationSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Run php artisan storage:link (for the default public disk).
- Very specific: line 35
Add 'image_urls' to $appends if the model is sent to Inertia or an API.
- Very specific: line 37
When replacing or deleting, call $uploader->delete($oldPath).
- Very specific: line 53
Use imagick (IMAGES_DRIVER=imagick) when available: it's faster and keeps colour profiles.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Image uploads: sized WebP, JPEG share images, sensible crops
One call turns an upload into every size the site needs:
$path = app(ImageUploader::class)->store($request->file('image'), 'posts');
// posts/9b1e.../original.webp, card.webp, detail.webp, thumb.webp, share.jpg
$post->update(['image' => $path]);
$post->image_urls['card']; // URL of the card size
$post->image_urls['share']; // 1200 × 630 JPEG for og:imageInstall
composer require intervention/image:^3.11- Copy from
stubs/, dropping.stub:config/images.php,app/Support/ImageUploader.php,app/Models/Concerns/HasImageUrls.php,app/Console/Commands/RegenerateImages.php,tests/Feature/ImageUploaderTest.php. - Run
php artisan storage:link(for the defaultpublicdisk). - Define sizes per type in
config/images.php, named after where they're shown (card,detail,thumb,share). Match them to the actual CSS box at 1x–2x. - In each model with an image, add the
HasImageUrlstrait and an accessor:
Addprotected function imageUrls(): Attribute { return Attribute::get(fn () => $this->resolveImageUrls($this->image, 'posts')); }'image_urls'to$appendsif the model is sent to Inertia or an API. - List every model in
config('images.models'), sophp artisan images:regeneraterebuilds it after a size change. A model missing from that list silently keeps old sizes. - When replacing or deleting, call
$uploader->delete($oldPath). It removes the whole folder of sizes.
What it gets right
- WebP for the site, JPEG for previews. WebP is 25–35% smaller, but WhatsApp, Facebook and LinkedIn often show no preview image for WebP. Sizes marked
'jpg'(likeshare, 1200 × 630) are saved as JPEG. - Heads stay in the picture. Cropping a portrait photo into a landscape box around the centre cuts off heads. A photo taller than the target keeps its top. The other photos are cropped around the centre. A test checks this with a two-colour image.
- Logos are never cropped. Sizes marked
'contain'scale to fit inside the box. - No upscaling. A 640-pixel upload stays 640 pixels as the original. Only the fixed-box sizes are filled.
- The original is capped at
max_width(1920), so a 12 MB phone photo doesn't become a 12 MB page. - Regenerating doesn't degrade quality. The original is never re-encoded. Older single-file uploads are converted into sized folders.
- Bundled images (paths under
assets/) work with the sameimage_urlsAPI: every size points at the one file.
Rules
- Validate uploads:
['image', 'mimes:jpg,jpeg,png,webp,avif', 'max:10240']. Resizing a huge image needs memory, so raisememory_limitfor upload requests if needed. - Output
<img src="{{ $post->image_urls['card'] }}" width="400" height="532" loading="lazy" decoding="async" alt="...">. Explicit width and height stop layout shift. Don't lazy-load the image at the top of the page (the LCP image). - Use
imagick(IMAGES_DRIVER=imagick) when available: it's faster and keeps colour profiles. GD works everywhere. - For S3, set
IMAGES_DISK=s3. Everything goes through theStoragefacade. - Seeders: store each photo once. Check
ImageUploader::isUpload($model->image)before uploading again, or everydb:seedcreates new folders.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

