Closed Botgamerns10s closed 3 weeks ago
The code would be trying to open up an image, so that you can see it on your screen. It is running xdg-open something.png
on the command line. xdg-open is installed, but it isn't connected to any application.
What application are you expecting to open up with the image?
Ahh I am not sure but I know this that the main code (which I attached) receives data from an api and saves it into images they it opens another python file which merges them into one in the whole process the image is not displayed to me instead after all the images are merged it is uploaded as a tweet on twitter
It sounds like this is code for a bot running on a server, so there's no point in showing the image to the user.
I suggest removing the img.show()
Let me try that but I won't be able to check if it's working or not because the bot auto updates at 8 pm et when the shop resets so will update you after that . Also is their anything I can do about this -- UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
Palette images with Transparency expressed in bytes should be converted to RGBA images
Convert palette images with transparency expressed in bytes to RGBA images or disable warnings (not sure if we support that?) or redirect stderr
to stdout
and stdout
to /dev/null
.
Let me try that
I don't understand where show()
is being called on a PNG image - the only time https://github.com/FortniteFevers/Fortnite-Shop-Bot/blob/main/bot.py calls show()
it is on a JPG. I thought that you might be saying that tweepy calls it, but I don't see any evidence of Pillow use in their codebase.
Are you just running bot.py, or is there other code?
If you can't find a show()
to remove that makes any difference, a quick and dirty way to stop show()
from doing anything would be to remove all of the registered viewers at the start of your code.
from PIL import ImageShow
ImageShow._viewers = []
I think if you would like further assistance with this, and with the UserWarning, it would be help if you could provide tracebacks, so that we can see how your code has reached that point.
You can easily get a traceback for the warning by running python -W error bot.py
instead of python bot.py
. That will cause all warnings to be treated as errors instead, showing the code from proceeding further, and showing how the code reached that point.
or disable warnings (not sure if we support that?)
No, there's no functionality in Image.py for that. The warning is straightforward.
The show command is on line 259 in main code And here is the second python file which is automatically imported to merge the images https://github.com/FortniteFevers/Fortnite-Shop-Bot/blob/main/merger.py
If this provides more information
I don't understand where show() is being called on a PNG image
When calling img.show()
on an image, Pillow converts it to PNG for displaying:
https://github.com/python-pillow/Pillow/blob/96f1a6e8b141934ffbda2df47e30fa4c8334c64e/src/PIL/ImageShow.py#L195-L224
If this provides more information
Thanks, it does. This is unrelated to Pillow.
You're running with -W error
which turns warnings into error. Python 3.11 has deprecation warnings about imghdr. You're using Tweepy which uses imghdr. See https://github.com/tweepy/tweepy/issues/2177. You should take this up with Tweepy, don't run with -W error
, or add an exception for this warning.
When calling
img.show()
on an image, Pillow converts it to PNG for displaying:
Ah, of course! Thanks.
Thanks guys but removing show command fixed everything just the. UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA imagesis left but I don't care about it as it doesn't interfere the output of the code
Btw guys you can see in the image that some of the items/merged images have a black background but Instead they should have a specific coloured according to their type can you tell me from the mai code where is the colour defined which is making few images with black background. I am new to python and all this stuff and couldn't find a solution on Google etc so thought to ask you guys 😅😅
https://github.com/FortniteFevers/Fortnite-Shop-Bot/blob/951d1d7f104aa03c25ffa0961f55dbdf9c9084d1/bot.py#L187-L188 pastes overlay.png, which is the lower translucent section, onto img
. So the background colour would happen before that.
But before that is just loading images from URLs and pasting them - https://github.com/FortniteFevers/Fortnite-Shop-Bot/blob/951d1d7f104aa03c25ffa0961f55dbdf9c9084d1/bot.py#L141-L183
I suggest printing some of those URLs and loading them individually in your browser.
It is possible that the 'black background' images don't actually have a black background, and are just transparent images being pasted onto the already black img
. In that case, you can set the initial colour of img
at https://github.com/FortniteFevers/Fortnite-Shop-Bot/blob/951d1d7f104aa03c25ffa0961f55dbdf9c9084d1/bot.py#L145 by changing it to img=Image.new("RGB",(512,512), "#f00")
or whatever you like.
If the images do actually have a black background in the URLs though, then that is more interesting. I could suggest using Pillow to filter out all black pixels, but the foreground of the images also have black in some cases. You could try using floodfill()
at the edge of the images, and seeing if that doesn't interfere with the foreground.
I actually checked the URLs generated by the api which the code is receiving manually but api is sending 2 links for each item, 1 with no background and another with background and the code is picking the one with no background to generate images for (but only for a few items) idk how to make it correct ðŸ˜
Are you sure this shouldn't be a question for https://github.com/FortniteFevers/Fortnite-Shop-Bot?
I found that changing https://github.com/FortniteFevers/Fortnite-Shop-Bot/blob/951d1d7f104aa03c25ffa0961f55dbdf9c9084d1/bot.py#L145-L146 to
img=Image.new("RGB",(512,512),'#0f0')
img.paste(background, (0, 0), background.convert('RGBA'))
making use of the paste()
mask
argument, worked to give a green background to some images.
For one of the images that it didn't give a green background to, I found that changing https://github.com/FortniteFevers/Fortnite-Shop-Bot/blob/951d1d7f104aa03c25ffa0961f55dbdf9c9084d1/bot.py#L96-L99 to always use 'OfferImage' fixed it.
url = i['newDisplayAsset']['materialInstances'][0]['images']['OfferImage']
That makes sense, that avoiding the 'Background' image stops the image from having a background.
Okay so sorry for the late reply but the things marked by me are some values which the api gives to make images Here the lines with [renderimage] variables are the ones which are getting images with no/black background and also the api sends another variable 'rarities' which actually decides the color of the background but when I edit the code and add it to the lines with [renderimages] the code gives a string value error . The lines with [materialinstance] and [offerimage] are making images with correct background. I tried adding [materialinstance] and [offerimage] variables to the other lines also but it messes up and the generated images are repeated. Though I found another code which is totally different but I found this which is preventing it from making images with no background here is a pic of the other code
Again, you're not asking questions about how to use Pillow. You're asking questions about how to modify the code at https://github.com/FortniteFevers/Fortnite-Shop-Bot. Users at that repository would be better able to help you than we are - before this conversation, I didn't even know Fortnite had an API.
when I edit the code and add it to the lines with [renderimages] the code gives a string value error
I tried adding [materialinstance] and [offerimage] variables to the other lines also but it messes up and the generated images are repeated.
This is hard to debug without knowing exactly what code you wrote. It would also be easier to have the complete script that you are trying to run each time as a text file, rather than portions of it as screenshots.
If you're still just trying to set the background colour for each square, then I don't see what the problem is with the code from my last comment. With the script I'm attaching here, I'm able to get a green background for all of the squares.
Yeah I went out of topic sorry won't ask again actually the person who wrote script wasn't interested in helping and I am new to python all this so thought to ask you guys sorry for the trouble
What did you do?
Trying to run a bot on render
What did you expect to happen?
It should open an image and then merge them into one and the final one to be posted on twitter
What actually happened?
Getting xdg error and the code stops
What are your OS, Python and Pillow versions?
Everything to latest version on Render
Orignal code https://github.com/FortniteFevers/Fortnite-Shop-Bot/blob/main/bot.py Error on render