Pygame colours aren't correct - python

I have created a window in Pygame which shows a basketball court, before it was functioning and would show the image however I have remade the background with the help of a graphic designer yet this new polished image shows as blue. Why is it blue? Here is the bballcourt.jpg image that needs to be used
Here is the code used to create the image background:
(width, height) = (940,500)#variables for screen
background_image = pygame.image.load("bballcourt.png")#setting the background image as a variable to be used to display on the screen
screen.blit(background_image, [0,0]) #this sets the background court image

Just looking back at my old questions - here is the answer #furas provided but in answer format not comment :D
"some tool shows me that this JPG use CMYK palette which is used for printed materials - ie. in newspapers. Ask designer to create RGB file."
"Automatic converting from CMYK to RGB not always look good. There are some "color profiles" (ICC files) for programs like Photoshop to better convert color. JPG creates small file but it removes pixels so it can look worst after every conversion. Better keep image as PNG."
Thanks #furas - hopefully anyone searching SO sees this has been answered should they not see the comments

Related

Create an image having icon and text side by side with gradient background with PILLOW, Python

this is my first ever post on stackoverflow.
I want to create an image which I'll be using as a feature image on WordPress, the image will have an Icon and Text with a gradient background.
The icon will show on the left and text will show on the right (side-by-side), I've tried searching everywhere but found nothing relevant.
If any expert can show some example code that would be a great help. <3
Below i'm attaching an example of image which I want to create.
example image

How can I increase the width of the black lines on an image with opencv?

I have an image of a map with black borders, and I would like to make them thicker with opencv on python. To be honest, I am quite new to image processing and really don't know how this task can be accomplished. I already opened the image with just one color channel, since it is black and white, but I really have no idea as of what to do next to be able to accomplish what I need.
Here is the image that I am talking about:
map
Thanks in advance

set_alpha() not working when using a png image as game over surface

When the game is over, I want to put an image above it. But I don't want it to override the game over surface, so I hope I can set the transparency of the png image after i load and convert_alpha(). But it isn't working after I use set_alpha(0).
What I can think of the problem are:
my png image doesn't have alpha channel, so I checked it in my photoshop. It is rgb, not rgba, so how can I add alpha channel for it which means convert rgb to rgba.
(Note: I can change the transparency of the image in photoshop and use it in my pygame, it works but i wanna i can change the degree of transparency in my program anytime, not just have to use photoshop)
my pygame methods using wrong
png image:
The result I want is here:
(please ignore the Chinese, they are just another two images)):
Code is:
img_bg = pygame.image.load('./ui/background.png').convert_alpha()
img_bg.set_alpha(0)
screen.blit(img_bg, (0, 0))
set_alpha doesn't work with surfaces that use per pixel alpha, so use the convert method instead of convert_alpha. I changed the value to 70, since 0 would make the image fully transparent.
img_bg = pygame.image.load('./ui/background.png').convert()
img_bg.set_alpha(70)

Produce a composed image with different sized layers with transparency

I'm very new to Python and am exploring it's use to allow users to build custom images. The idea is that the client would select a few options and the image would be created on the server then downloaded (or used for other things on the server side).
The image is composed of many images, most of which are small icon type of images that are irregular shapes and have transparency. All layers are .png files.
I've tried using Pillow but it seems the image needs to be the same size as the overall image to properly use the transparency of the top layers.
Here's what I've tried so far:
from PIL import Image
background = Image.open("Background.png")
foreground = Image.open("Trim.png")
fire = Image.open("Type_Fire_Large.png")
background = Image.alpha_composite(background, foreground)
background.paste(fire, (150, 150))
background.show()
The image looks like this:
Background.png is the shaded "noise" and Trim.png is the grey diagonal lines. The best part: Trim.png has the center transparent and is able to show Background.png in the middle. But it's also the same size as the image.
The problem is Fire; notice how theres that black border (and odd fuchsia dot). The documentation states that the overlay image needs to be the same size. But it seems like a common scenario where someone would want to place a smaller icon with transparency on top of another image and compose them into one image.
I'm not attached to any particular library, I'm wide open to ideas and alternatives. The only thing I'm trying to do is keep it simple, so creating an entire game engine or the like to produce an image would probably be too much.
To just paste one png on top of another, respecting transparency, try
background.paste(fire, (x,y), fire.convert("RGBA"))
First I'd say Johannes Holmberg already answered your main concern: The missing transparency.
But I can hopefully explain what it's about with that odd fuchsia dot:
A transparent color image is usually stored as RGBA (RGB for Red, Green, Blue and A for Alpha). Here Alpha defines the transparency, from no transparency to full transparency.
Overlaying the images the correct way we see the GIMP Logo but the color stripe is almost invisible - because it's (almost) transparent.
But - as every pixel could be possibly visible - every pixel does still have a color. Even those pixels with 100% transparency. Thus, if we do not take Alpha into consideration we see each pixel color without transparency. This way we might have disturbing colors that are usually not disturbing at all - as long as they are fully transparent.

Problem with saving image

I have a problem with saving an image. I have following part of code:
self.canvas.postscript(file = filename, colormode = "color")
It works good, but when I set background color in canvas constructor (f.e. bg='red'),
finally image doesn't have this background color. It is still white.
Could anybody help me ?
Sounds like you're using Tkinter: is that right?
I believe the problem is that the bg argument is a general property shared by all widgets. It's really a part of how the widget is drawn on the screen and not a part of the image you're constructing in your canvas. I think the easiest thing for you to do is to draw a red box in your canvas for your background - that will then be included as part of the image saved in your postscript file.

Categories

Resources