(l, t, r, b, img)
| 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; |
no test coverage detected