<enhanced:img retina> support
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the problem
@sveltejs/enhanced-img renders the img tag using intrinsic dimensions, which causes incorrect rendering if the image is a 2x retina image.
Describe the proposed solution
I propose a boolean prop, <enhanced:img retina> that will set the img width/height to the correct logical dimensions: 1/2 the intrinsic dimensions.
Alternatives considered
- CSS styling is not helpful because it puts the burden back on the developer to specify sizes explicitly
Importance
nice to have
Additional Information
Here is a crude patch just to show the essence:
diff --git a/src/preprocessor.js b/src/preprocessor.js
index 0222037e593b554cae5b8712fa8c8e51fd071932..051d57097d4844ee3474b2f0d60584ca6578f8ba 100644
--- a/src/preprocessor.js
+++ b/src/preprocessor.js
@@ -304,8 +306,8 @@ function img_to_picture(consts, content, node, image) {
res += `<img ${serialize_img_attributes(content, attributes, {
src: to_value(consts, image.img.src),
- width: image.img.w,
- height: image.img.h
+ width: image.img.w/2,
+ height: image.img.h/2
})} />`;
return (res += '</picture>');
@@ -345,8 +347,8 @@ function dynamic_img_to_picture(content, node, src_var_name) {
const details = {
src: `{${src_var_name}.img.src}`,
- width: `{${src_var_name}.img.w}`,
- height: `{${src_var_name}.img.h}`
+ width: `{${src_var_name}.img.w/2}`,
+ height: `{${src_var_name}.img.h/2}`
};
return `{#if typeof ${src_var_name} === 'string'}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/preprocessor.js, focusing on img_to_picture and dynamic_img_to_picture, where the issue's proposed changes adjust generated image dimensions. Trace how the enhanced:img retina prop would be recognized, then verify that both static and dynamic images receive logical dimensions while other images remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100