{"action":"created","issue":{"url":"https://api.github.com/repos/SimonSapin/cairocffi/issues/51","labels_url":"https://api.github.com/repos/SimonSapin/cairocffi/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/SimonSapin/cairocffi/issues/51/comments","events_url":"https://api.github.com/repos/SimonSapin/cairocffi/issues/51/events","html_url":"https://github.com/SimonSapin/cairocffi/issues/51","id":58243553,"number":51,"title":"simple example writing onto existing numpy buffer dies","user":{"login":"stuaxo","id":179677,"avatar_url":"https://avatars.githubusercontent.com/u/179677?v=3","gravatar_id":"","url":"https://api.github.com/users/stuaxo","html_url":"https://github.com/stuaxo","followers_url":"https://api.github.com/users/stuaxo/followers","following_url":"https://api.github.com/users/stuaxo/following{/other_user}","gists_url":"https://api.github.com/users/stuaxo/gists{/gist_id}","starred_url":"https://api.github.com/users/stuaxo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stuaxo/subscriptions","organizations_url":"https://api.github.com/users/stuaxo/orgs","repos_url":"https://api.github.com/users/stuaxo/repos","events_url":"https://api.github.com/users/stuaxo/events{/privacy}","received_events_url":"https://api.github.com/users/stuaxo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-02-19T17:51:28Z","updated_at":"2015-08-09T10:03:19Z","closed_at":"2015-08-09T10:03:19Z","body":"This example of dies -\r\n\r\nhttp://stackoverflow.com/questions/10031580/how-to-write-simple-geometric-shapes-into-numpy-arrays/10031877#10031877\r\n\r\nCode\r\n```python\r\nimport numpy\r\nimport cairo\r\n#import cairocffi as cairo\r\nimport math\r\ndata = numpy.zeros((200, 200, 4), dtype=numpy.uint8)\r\nsurface = cairo.ImageSurface.create_for_data(\r\n    data, cairo.FORMAT_ARGB32, 200, 200)\r\ncr = cairo.Context(surface)\r\n\r\n# fill with solid white\r\ncr.set_source_rgb(1.0, 1.0, 1.0)\r\ncr.paint()\r\n\r\n# draw red circle\r\ncr.arc(100, 100, 80, 0, 2*math.pi)\r\ncr.set_line_width(3)\r\ncr.set_source_rgb(1.0, 0.0, 0.0)\r\ncr.stroke()\r\n\r\n# write output\r\nprint data[38:48, 38:48, 0]\r\nsurface.write_to_png(\"circle.png\")\r\n```\r\nOutput in pycairo:\r\n```python\r\n## -- End pasted text --\r\n[[255 255 255 255 255 255 255 253 110   0]\r\n [255 255 255 255 255 255 251  95   0   0]\r\n [255 255 255 255 255 246  73   0   0   0]\r\n [255 255 255 255 247  75   0   0   0  90]\r\n [255 255 255 247  70   0   0   0 108 254]\r\n [255 255 247  68   0   0   0 136 255 255]\r\n [255 251  82   0   0   0 127 255 255 255]\r\n [255  97   0   0   0 118 255 255 255 255]\r\n [127   0   0   0 119 255 255 255 255 255]\r\n [  1   0   0  91 254 255 255 255 255 255]]\r\n```\r\n\r\nOutput in CairoCFFI\r\n```\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-7-7cdc9a0244d0> in <module>()\r\n      3 data = numpy.zeros((200, 200, 4), dtype=numpy.uint8)\r\n      4 surface = cairo.ImageSurface.create_for_data(\r\n----> 5     data, cairo.FORMAT_ARGB32, 200, 200)\r\n      6 cr = cairo.Context(surface)\r\n      7 \r\n\r\n/mnt/data/home/stu/.virtualenvs/tmp/local/lib/python2.7/site-packages/cairocffi/surfaces.pyc in create_for_data(cls, data, format, width, height, stride)\r\n    658 \r\n    659         \"\"\"\r\n--> 660         return cls(format, width, height, data, stride)\r\n    661 \r\n    662     @staticmethod\r\n\r\n/mnt/data/home/stu/.virtualenvs/tmp/local/lib/python2.7/site-packages/cairocffi/surfaces.pyc in __init__(self, format, width, height, data, stride)\r\n    647             if length < stride * height:\r\n    648                 raise ValueError('Got a %d bytes buffer, needs at least %d.'\r\n--> 649                                  % (length, stride * height))\r\n    650             pointer = cairo.cairo_image_surface_create_for_data(\r\n    651                 ffi.cast('char*', address), format, width, height, stride)\r\n\r\nValueError: Got a 200 bytes buffer, needs at least 160000.\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/SimonSapin/cairocffi/issues/comments/129150258","html_url":"https://github.com/SimonSapin/cairocffi/issues/51#issuecomment-129150258","issue_url":"https://api.github.com/repos/SimonSapin/cairocffi/issues/51","id":129150258,"user":{"login":"stuaxo","id":179677,"avatar_url":"https://avatars.githubusercontent.com/u/179677?v=3","gravatar_id":"","url":"https://api.github.com/users/stuaxo","html_url":"https://github.com/stuaxo","followers_url":"https://api.github.com/users/stuaxo/followers","following_url":"https://api.github.com/users/stuaxo/following{/other_user}","gists_url":"https://api.github.com/users/stuaxo/gists{/gist_id}","starred_url":"https://api.github.com/users/stuaxo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stuaxo/subscriptions","organizations_url":"https://api.github.com/users/stuaxo/orgs","repos_url":"https://api.github.com/users/stuaxo/repos","events_url":"https://api.github.com/users/stuaxo/events{/privacy}","received_events_url":"https://api.github.com/users/stuaxo/received_events","type":"User","site_admin":false},"created_at":"2015-08-09T10:03:19Z","updated_at":"2015-08-09T10:03:19Z","body":"Somehow I missed this at the time.   Just tested in a fresh virtualenv and it works :)"}}