JuanPotato/Legofy

Tries to write new image to / (Permission denied)

Closed this issue · 13 comments

Hi,

legofy tries to write the new image to /. Results in a permission denied error.

$ python legofy/cli.py 2014-08-08.jpg
Static image detected, will now legofy and save as /lego_2014-08-08.png
Traceback (most recent call last):
  File "legofy/cli.py", line 17, in <module>
    main()
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "legofy/cli.py", line 14, in main
    legofy.main(image, brick=brick)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/legofy-0.0.1-py3.5.egg/legofy/__init__.py", line 131, in main
    makeLegoImage(baseImage, brick).save(newFilename)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/PIL/Image.py", line 1659, in save
    fp = builtins.open(filename, "wb")
PermissionError: [Errno 13] Permission denied: '/lego_2014-08-08.png'

I have the same issue

same here

I tried to use ./pic_name.png as a workaround, then it works.

@methou nice, it worked. :)

@methou Worked for me too 👍

Awesome - Just wanted to also push the following patch:
--- a/legofy/init.py
+++ b/legofy/init.py
@@ -81,7 +81,9 @@ def main(filename, brick, width=30, height=30, scale=1):
baseImage = Image.open(filename)
newSize = baseImage.size
static = filename.lower().endswith(".gif") and is_animated(baseImage)

  • newFilename = '{0}/lego_{1}'.format(*os.path.split(filename))
  • (_path, _filename) = os.path.split(filename)
  • if len(_path) <= 0 : _path = "."
  • newFilename = '{0}/lego_{1}'.format(_path, _filename)

if newSize[0] > 30 or newSize[1] > 30:
if newSize[0] < newSize[1]:

@grisu48: either wrap that with ``` or submit a PR

I'm having the same issue: how does when specify the output of the file? Is there any documentation anywhere?

The output parameter is not used, what it does is take the original file name and create a file with the same name with 'lego_' prepended to it... The problem is when you specify a file path in the same working directory you are at (ie: test.jpg) the way it calculates the path at the moment will try to put the new file at '/lego_test.jpg' which will cause the permission denied error...

As suggested above, a temporary fix would be to pass the name of the file like so: ./test.jpg instead of: test.jpg

Ah great. I understand. Would you welcome a PR for this?

On Thu, 29 Oct 2015, 20:53 Eyal Zekaria notifications@github.com wrote:

The output parameter is not used, what it does is take the original file
name and create a file with the same name with 'lego_' prepended to it...
The problem is when you specify a file path in the same working directory
you are at (ie: test.jpg) the way it calculates the path at the moment will
try to put the new file at '/lego_test.jpg' which will cause the permission
denied error...

As suggested above, a temporary fix would be to pass the name of the file
like so: ./test.jpg instead of: test.jpg


Reply to this email directly or view it on GitHub
#22 (comment).

Sorry I haven't merged this yet, I've been working on the project and fixing bits before it got a lot of attention on /r/python or where ever most of you came from. I'm almost done and will look through the merges after I'm done.

furas commented

You could use

_path, _name = os.path.split(filename)
newFilename = os.path.join(_path, 'lego_' + _name)

in place of

newFilename = '{0}/lego_{1}'.format(*os.path.split(filename))

to remove problem with /

This should be fixed, please try with the newest code.