Skip to content

Commit

Permalink
A better way to load an image (--dem diffz yo--)
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Sep 2, 2014
1 parent 591c7ae commit 45302ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
34 changes: 6 additions & 28 deletions lib/image-editor-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class ImageEditorView extends ScrollView

uri = editor.getUri()

console.log "loading iframe", @iframe[0]
@iframe.load =>
paint = @iframe[0].contentWindow

Expand All @@ -27,35 +26,14 @@ class ImageEditorView extends ScrollView
@command 'paint:invert', => paint.invert()
@command 'paint:clear-image', => paint.clear()

# The Worst Way To Load An Image™
# Load the image into paint
image = new Image

# We take a URI (Universal Resource Indicator),
# Load the URI as an image,
# Make a canvas, and draw the image to the canvas;
# Then we get the data URI from the canvas so we can
# Send it to the page(!), which
# Loads the URI as an image, and finally
# Puts it on the canvas
# SOUNDS LEGIT LET'S SHIP IT

img = document.createElement 'img'
# paint.open_from_Image(img, uri) doesn't work 'cause it can't pass the image into the iframe...
# maybe if it was an Image? I doubt that would make a difference
# no wait, create the image from within the page's document; that might work
console.log "loading image", img
$(img).load =>
console.log "loaded image", img
canvas = document.createElement 'canvas'
ctx = canvas.getContext '2d'
canvas.width = img.width
canvas.height = img.height
ctx.drawImage(img, 0, 0)
data_uri = canvas.toDataURL()
console.log "opening image"
paint.open_from_URI data_uri, uri

$(image).load =>
paint.open_from_Image(image, uri)
@loaded = true
img.src = uri

image.src = uri

afterAttach: (onDom) ->
return unless onDom
Expand Down
1 change: 0 additions & 1 deletion lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ _ = require 'underscore-plus'
ImageEditor = require './image-editor'

openUri = (uriToOpen)->
console.log "opener for paint called for #{uriToOpen}"
ext = path.extname(uriToOpen).toLowerCase()
if ext.match /.(png|gif|jpe?g|bmp|ico)$/
new ImageEditor(uriToOpen)
Expand Down

0 comments on commit 45302ad

Please sign in to comment.