'Image saved in google colab is not showing in files

I tried to generate an image using PIL.ImageDraw and saved it in 'content/'. But when I tried to open that image using files, it is not there. I also tried to display that image using several methods, it's also not working. Here is my code:

from PIL import ImageDraw,Image
from IPython.display import Image, display
import random
import cv2
import matplotlib.pyplot as plt
def generate_art():
 #Creating an image
 image_size_px= 128
 image_bg_color = (255,255,255) 
 padding_px = 16
 image = Image.new("RGB",size=(image_size_px,image_size_px),color=image_bg_color)
 #Draw some lines on that image
 draw = ImageDraw.Draw(image)
 points =[]
 for _ in range(10):
   random_point = (
       random.randint(padding_px,image_size_px - padding_px),
       random.randint(padding_px,image_size_px - padding_px),
       )
   points.append(random_point)
 #Draw the points
 thickness = 0
 for i,point in enumerate(points):
   p1 = point
   if i == len(points)-1:
     p2 = points[0]
   else:
     p2 = points[i+1]
   line_xy = (p1,p2)
   line_color = (0,0,0) 
   thickness +=1
   draw.line(line_xy,fill=line_color,width = thickness)
   image.save('content/test_image.png')
   display(image)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source