我们正在使用Python脚本每天生成电子邮件,并将每日报告发送给业务用户。在这些电子邮件中,我们添加了报告的PrintScreen。在这种情况下,用户无需在手机上打开附件(PDF)即可在电子邮件内部查看结果(报告编号)。
但是问题是,对于某些iPhone机型,图像非常模糊,无法看到图像的内容。Android手机没有问题。
对于iPhone,有什么话要说的,例如请不要大幅缩小图像质量。
添加图像的功能:
def send_email(send_to, subject, html, plain, img_path, cc):
try:
# prepare date for email subject
scorecard_date = date.today() - timedelta(1)
# prepare message
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = send_to
msg['Subject'] = subject + ' - for ' + scorecard_date.strftime('%d/%m/%Y')
# attach cc if applicable
if cc is not None:
msg['Cc'] = cc
send_to = [send_to, cc]
# attach plain or html body
if html is not None:
msg.attach(MIMEText(html, 'html'))
else:
msg.attach(MIMEText(plain, 'plain'))
# attach image if applicable
if img_path is not None:
fp = open(img_path, 'rb')
msg_image = MIMEImage(fp.read())
msg_image.add_header('Content-ID', '<image1>')
msg.attach(msg_image)
fp.close()
# create server instance and send email
server = smtplib.SMTP(smtp_host, smtp_port)
server.starttls()
server.login(email_user, sc.get_email_pass())
text = msg.as_string()
server.sendmail(email_user, send_to, text)
server.quit()
# return ok
return 0
except:
# something went wrong - probably timeout
return 1
在电子邮件正文中插入图像的HTML标签:
<div style="line-height:15px;font-size:1px"> </div> <img class="left autowidth fullwidth" align="left" border="0" src="cid:image1" alt="Image" title="Image" style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: block !important;border: 0;height: auto;float: none;width: 150%;max-width: 1024px" width="1024">
谢谢,大流士
iPhone正在使用我们所说的视网膜显示器。简而言之,这些设备具有比其他传统Apple显示器更高的像素密度]。
Apple所做的工作是将2像素替换为1。这意味着您的图像是其应显示图像大小的一半。
例如,如果您的图像设置为200px x 200px,Apple会将其显示为200px x 200px,但是在其设备上400px x 400px的空间中,这意味着您将图像调整为适合该空间的大小。
您将需要截屏并在iOS上以较小的尺寸显示以避开视网膜显示。
具有视网膜显示的型号可以找到here。