llorracc / as.180.369-2023-Fall

Johns Hopkins AS.180.369—“Tools for Writing a Research Paper in Economics” (Fall 2023)
1 stars 15 forks source link

Images not appearing on slides #34

Open marcill1 opened 11 months ago

marcill1 commented 11 months ago

I'm having an error with images not appearing on my slides. They either will not show up at all or just appear like this: imgerror

However, the images do load just fine in jupyter notebook. How would I fix this?

emurinson commented 11 months ago

I'm not sure, but am also having the same issue. Tried looking around online, but couldn't find any relevant answers.

Sunsett5 commented 11 months ago

K told me to just drag the image from the folder and drop it directly on to the presentation file. It works for me, but I still can't find a way to adjust figure size.

emurinson commented 11 months ago

ah thanks so much! that's better than no picture at all:)

marcill1 commented 11 months ago

This worked, thank you! I guess you'd have to adjust the figure size externally.

Sunsett5 commented 11 months ago

I resized the images in python, and they all fit the slide now. Thanks for the suggestion!

emurinson commented 11 months ago

Sun could you show an example of how you did that? TIA!

Sunsett5 commented 11 months ago

Sure thing!, this is my code to add whitespace to both sides of the image. You need whitespace because resizing alone won't work. If you run this code with your image in the same folder as this code, it will return the original size in pixel. Then, you can change the "new_width" so that they are larger than the original width.


from PIL import Image, ImageOps

def resize_with_whitespace(input_path, output_path, new_width):
    original_image = Image.open(input_path)

    # Calculate the new height to maintain the aspect ratio
    print("Original size:", original_image.size)
    original_width, original_height = original_image.size
    new_height = original_height

    # Create a new image with the desired size and white background
    new_image = Image.new("RGB", (new_width, new_height), "white")

    # Paste the original image onto the new image, centering it
    offset = ((new_width - original_width) // 2, (new_height - original_height) // 2)
    new_image.paste(original_image, offset)

    # Save the result
    new_image.save(output_path)

# Example usage:
input_image_path = "image.png"
output_image_path = "image_resized.png"
new_width = 3600  # Adjust this to your desired width

resize_with_whitespace(input_image_path, output_image_path, new_width)```
emurinson commented 11 months ago

Thank you so much! this is so helpful!