File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 158
158
( minHeight || destHeight ) / destHeight
159
159
)
160
160
if ( scale > 1 ) {
161
- destWidth *= scale
162
- destHeight *= scale
161
+ /**
162
+ * These value are used to create canvas elements. Ensuring that they are integers
163
+ * (rather than floats) avoids a potential 1px rounding error in the canvas element
164
+ * as canvas elements will always round it down to the nearest integer rather than
165
+ * following standard rounding rules. For example, using a value of 199.9999999px
166
+ * for a canvas height would result in a height of 199px rather than 200px.
167
+ */
168
+ destWidth = Math . round ( destWidth * scale )
169
+ destHeight = Math . round ( destHeight * scale )
163
170
}
164
171
}
165
172
/**
171
178
( maxHeight || destHeight ) / destHeight
172
179
)
173
180
if ( scale < 1 ) {
174
- destWidth *= scale
175
- destHeight *= scale
181
+ /**
182
+ * These value are used to create canvas elements. Ensuring that they are integers
183
+ * (rather than floats) avoids a potential 1px rounding error in the canvas element
184
+ * as canvas elements will always round it down to the nearest integer rather than
185
+ * following standard rounding rules. For example, using a value of 199.9999999px
186
+ * for a canvas height would result in a height of 199px rather than 200px.
187
+ */
188
+ destWidth = Math . round ( destWidth * scale )
189
+ destHeight = Math . round ( destHeight * scale )
176
190
}
177
191
}
178
192
if ( useCanvas ) {
You can’t perform that action at this time.
0 commit comments