{"action":"created","issue":{"url":"https://api.github.com/repos/mozman/svgwrite/issues/24","repository_url":"https://api.github.com/repos/mozman/svgwrite","labels_url":"https://api.github.com/repos/mozman/svgwrite/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/mozman/svgwrite/issues/24/comments","events_url":"https://api.github.com/repos/mozman/svgwrite/issues/24/events","html_url":"https://github.com/mozman/svgwrite/issues/24","id":332762129,"node_id":"MDU6SXNzdWUzMzI3NjIxMjk=","number":24,"title":"Include bitmap image as base64 encoded","user":{"login":"scls19fr","id":109167,"node_id":"MDQ6VXNlcjEwOTE2Nw==","avatar_url":"https://avatars3.githubusercontent.com/u/109167?v=4","gravatar_id":"","url":"https://api.github.com/users/scls19fr","html_url":"https://github.com/scls19fr","followers_url":"https://api.github.com/users/scls19fr/followers","following_url":"https://api.github.com/users/scls19fr/following{/other_user}","gists_url":"https://api.github.com/users/scls19fr/gists{/gist_id}","starred_url":"https://api.github.com/users/scls19fr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scls19fr/subscriptions","organizations_url":"https://api.github.com/users/scls19fr/orgs","repos_url":"https://api.github.com/users/scls19fr/repos","events_url":"https://api.github.com/users/scls19fr/events{/privacy}","received_events_url":"https://api.github.com/users/scls19fr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-15T12:52:40Z","updated_at":"2018-08-05T02:50:11Z","closed_at":null,"author_association":"NONE","body":"Hello, \r\n\r\nI would like to include an image in a SVG file as base64 encoded.\r\n\r\nI should get something like\r\n\r\n```svg\r\n  <image\r\n     width=\"231\"\r\n     height=\"443\"\r\n     preserveAspectRatio=\"none\"\r\n     xlink:href=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAAG7CAIAAAC3rRVPAAAAAXNSR0IArs4c6QAAQABJREFUeAHs 3XegdUV1NvAopPfmZyHyvoCCIk0DSH+pCgICAUMXwQgooKKIIhISFAtFBTGAElBAUESCICpNQFEj Cmo0SiSQotFU03vC9zv3IcP2tHvuOfu0++75Y9/ZM2vWrPXMM2tml7PvYx5++OEfatLqisD//u// PmYhBYD/+Z//USL96I/+6CxD8thZNq6xrUGgKwJrdi1tClcTBMTZqqdOH/vYOQhkj2l2CNVhW53z VSa0sXnWYGli7ayNyBTsKXydcbIWaJpYW6BoMnODwBxsYuYGy8bQSSHQsHZSSDf91IdAw9r6sGw0 TQqBhrWTQrrppz4EGtbWh2WjaVIINKydFNJNP/Uh0LC2PiwbTZNCoGHtpJBu+qkPgYa19WHZaJoU Ag1rJ4V00099CDSsrQ/LR\r\n...\r\nJzs9eJNkKYCZtkMys0baZnonOz14l2D2EmbCKE Lf1ocrdktokmAv8D6M4XLBxaA6kAAAAASUVORK5CYII= \"\r\n     id=\"image4832\"\r\n     x=\"0\"\r\n     y=\"0\" />\r\n```\r\n\r\nIs there an easy way to do it with svgwrite?\r\n\r\nKind regards"},"comment":{"url":"https://api.github.com/repos/mozman/svgwrite/issues/comments/410491612","html_url":"https://github.com/mozman/svgwrite/issues/24#issuecomment-410491612","issue_url":"https://api.github.com/repos/mozman/svgwrite/issues/24","id":410491612,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDQ5MTYxMg==","user":{"login":"stevenj","id":764829,"node_id":"MDQ6VXNlcjc2NDgyOQ==","avatar_url":"https://avatars3.githubusercontent.com/u/764829?v=4","gravatar_id":"","url":"https://api.github.com/users/stevenj","html_url":"https://github.com/stevenj","followers_url":"https://api.github.com/users/stevenj/followers","following_url":"https://api.github.com/users/stevenj/following{/other_user}","gists_url":"https://api.github.com/users/stevenj/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenj/subscriptions","organizations_url":"https://api.github.com/users/stevenj/orgs","repos_url":"https://api.github.com/users/stevenj/repos","events_url":"https://api.github.com/users/stevenj/events{/privacy}","received_events_url":"https://api.github.com/users/stevenj/received_events","type":"User","site_admin":false},"created_at":"2018-08-05T02:50:11Z","updated_at":"2018-08-05T02:50:11Z","author_association":"NONE","body":"Yes, Use wand (Image Magic library)\r\n\r\nSomething like this:\r\n```\r\n    from wand.image import Image\r\n\r\n    # Load PNG Image\r\n    img = Image(filename=\"my.png\")\r\n\r\n    # Then get raw PNG data and encode DIRECTLY into the SVG file.\r\n    image_data = img.make_blob(format='png')\r\n    encoded = base64.b64encode(image_data).decode()\r\n    pngdata = 'data:image/png;base64,{}'.format(encoded)\r\n\r\n    image = dwg.add(dwg.image(href=(pngdata))):\r\n```\r\n\r\nBonus, the wand library lets you use ANY format image and encode it as a PNG\r\nYou can also do cropping, transforms, etc on the image before encoding it.\r\nYou can also embed an SVG inside an SVG the same way:\r\n\r\n```\r\n   from wand.image import Image\r\n\r\n    # Load PNG Image\r\n    img = Image(filename=\"my.svg\")\r\n\r\n    # Then get raw SVG data and encode DIRECTLY into the SVG file.\r\n    image_data = img.make_blob()  # Dont change its format, just use it as an SVG\r\n    encoded = base64.b64encode(image_data).decode()\r\n    svgdata = 'data:image/png;base64,{}'.format(encoded)\r\n\r\n    image = dwg.add(dwg.image(href=(svgdata))):\r\n```"}}
{"actor":{"display_login":"stevenj"}}