MCPcopy Create free account
hub / github.com/devforth/painterro / placeAt

Method placeAt

js/selecter.js:165–201  ·  view source on GitHub ↗
(l, t, r, b, img)

Source from the content-addressed store, hash-verified

163 }
164
165 placeAt(l, t, r, b, img) {
166
167 if (this.imagePlaced) {
168 // for case when user inserts multiple images one after another without finishing placing them
169 this.finishPlacing();
170 }
171
172 this.main.closeActiveTool(true);
173 this.main.setActiveTool(this.main.defaultTool);
174 const scale = this.getScale();
175 this.setLeft(l * scale);
176 this.setTop(t * scale);
177 this.setRight(r * scale);
178 this.setBottom(b * scale);
179 const tmpCan = document.createElement('canvas');
180 tmpCan.width = img.naturalWidth;
181 tmpCan.height = img.naturalHeight;
182 const tmpCtx = tmpCan.getContext('2d');
183 tmpCtx.drawImage(img, 0, 0);
184 this.placedData = tmpCan.toDataURL('image/png');
185 const lowScale = 1000 / Math.max(img.naturalWidth, img.naturalHeight);
186 if (lowScale >= 1) {
187 this.placedDataLow = this.placedData;
188 } else {
189 tmpCan.width = img.naturalWidth * lowScale;
190 tmpCan.height = img.naturalHeight * lowScale;
191 tmpCtx.scale(lowScale, lowScale);
192 tmpCtx.drawImage(img, 0, 0);
193 this.placedDataLow = tmpCan.toDataURL('image/png');
194 }
195 this.main.select.area.rect.style['background-image'] = `url(${this.placedData})`;
196 this.show();
197 this.reCalcCropperCords();
198 this.imagePlaced = true;
199 this.main.select.activate();
200 this.placedRatio = img.naturalWidth / img.naturalHeight;
201 }
202
203 finishPlacing() {
204 this.imagePlaced = false;

Callers 1

constructorMethod · 0.80

Calls 11

finishPlacingMethod · 0.95
getScaleMethod · 0.95
setLeftMethod · 0.95
setTopMethod · 0.95
setRightMethod · 0.95
setBottomMethod · 0.95
showMethod · 0.95
reCalcCropperCordsMethod · 0.95
closeActiveToolMethod · 0.80
setActiveToolMethod · 0.80
activateMethod · 0.45

Tested by

no test coverage detected