当前位置: 首页> 财经> 金融 > 平台搭建阳光房是否违章建筑_西安软件开发公司排行_网页设计制作软件_清理大师

平台搭建阳光房是否违章建筑_西安软件开发公司排行_网页设计制作软件_清理大师

时间:2025/7/9 1:15:58来源:https://blog.csdn.net/C_VuI/article/details/146382660 浏览次数:2次
平台搭建阳光房是否违章建筑_西安软件开发公司排行_网页设计制作软件_清理大师

代码

from PIL import Image# 定义 ASCII 字符集,从最暗到最亮
ASCII_CHARS = "@%#*+=-:. "def resize_image(image, new_width=100):width, height = image.sizeratio = height / widthnew_height = int(new_width * ratio)resized_image = image.resize((new_width, new_height))return resized_imagedef grayify(image):grayscale_image = image.convert("L")return grayscale_imagedef pixels_to_ascii(image):pixels = image.getdata()characters = "".join([ASCII_CHARS[pixel // 25] for pixel in pixels])return charactersdef main(new_width=100):image_path = input("请输入图片的路径: ")try:image = Image.open(image_path)except Exception as e:print(f"无法打开图片: {e}")returnnew_image_data = pixels_to_ascii(grayify(resize_image(image, new_width)))pixel_count = len(new_image_data)ascii_image = "\n".join([new_image_data[index:(index + new_width)] for index in range(0, pixel_count, new_width)])print(ascii_image)with open("ascii_image.txt", "w") as f:f.write(ascii_image)if __name__ == "__main__":main()

效果

原图

在这里插入图片描述

效果图

在这里插入图片描述

关键字:平台搭建阳光房是否违章建筑_西安软件开发公司排行_网页设计制作软件_清理大师

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: