i have a given picture and have to create a picture that is twice as wide as the given picture. For each pixel (x, y) in the original picture, the pixels (2 * x, y) and (2 * x + 1, y) in the new picture should be set to the same color as it.
i am not allowed to use any other module( like PIL)
so i have to create a picture that is twice width
plz help me out here
here is what i have so far

import media

def widen(new_pic):

height = media.get_height(pic)
width = media.get_width(pic)
new_pic = media.create_picture( width * 2, height)
new_height = media.get_height(new_pic)
new_width = media.get_width(new_pic)
for y in range(0, new_height):

for x in range(0, new_width):

from_p = media.get_pixels(pic)

to_p = media.get_pixels(new_pic, 2 * x + 1, y)

media.set_color(to_p, media.get_color(from_p))

return new_pic

im not sure that i have used range function right but i dont really know how to use pixel pix to make same color

I'm not a very experienced programmer like others around here but I took a look at this since there are no other answers. I was able to accomplish what you describe in the following manner, no guarantees that this is a recommended way to do this and obviously there is more than one way to skin the proverbial cat.

import picture
import media
import time

#open the image file
fd = open("path to file...", "rb")

#loaded picture from file--> returns image object
img = picture.load_image(fd)

#close file
fd.close()

#create picture object from image
Pic_obj = picture.Picture(image=img)

Pic_obj.show()
time.sleep(2)
Pic_obj.close_inspect()

#get width/height of original
h = Pic_obj.get_height()
w = Pic_obj.get_width()

#create new picture object for the resized image
new_pic = media.create_picture( width * 2, height)

#loop over the x,y in some way to fill in the new image

for y in range(0, height):
    for x in range(0, width*2, 2):        

        old_pixel = Pic_obj.get_pixel(x/2, y)

        old_pixel_color = old_pixel.get_color()

        new_pixel1 = new_pic.get_pixel(x,y)
        new_pixel2 = new_pic.get_pixel(x+1,y)

        new_pixel1.set_color(old_pixel_color)
        new_pixel2.set_color(old_pixel_color)

new_pic.show()

i have a given picture and have to create a picture that is twice as wide as the given picture. For each pixel (x, y) in the original picture, the pixels (2 * x, y) and (2 * x + 1, y) in the new picture should be set to the same color as it.
i am not allowed to use any other module( like PIL)
so i have to create a picture that is twice width
plz help me out here
here is what i have so far

import media

def widen(new_pic):
    
     height = media.get_height(pic)
     width = media.get_width(pic)
     new_pic = media.create_picture( width * 2, height)
     new_height = media.get_height(new_pic)
     new_width = media.get_width(new_pic)
     for y in range(0, new_height):
        
          for x in range(0, new_width):
            
               from_p = media.get_pixels(pic)

               to_p = media.get_pixels(new_pic, 2 * x + 1, y)
            
               media.set_color(to_p, media.get_color(from_p))
            
               return new_pic

im not sure that i have used range function right but i dont really know how to use pixel pix to make same color

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.