向图像添加空格并将文件保存到服务器
我有一个脚本可以为时事通讯生成一些 HTML。我使用“align=left”浮动图像并在其周围环绕文本。我使用内联 CSS 样式(在本例中为 margin-right),为图像提供一些喘息空间。 Outlook 会忽略这一点。 Outlook 也忽略填充 - 我什至尝试了 10px 右边框,它也忽略了这一点。
我无法更改布局并将图像放入表格中。我正在考虑使用 GD 来操作图像,在其右侧添加 8px 的空白。问题是,由于这是一份向数千人发送的时事通讯,因此我需要将修改后的图像保存到服务器上的某个位置,以便我可以链接到它。我不想即时生成它。
我对 GD 或使用 PHP 将文件保存到某个位置的经验为零。这是我的图像代码:
<img alt="<?php print $main2['title']; ?>" height="127" width="185" src="http://www.mydomain.com/uploads/<?php print $main2['filename']; ?>" align="left" style="margin:8px 8px 0 0;"/>
I have a script that generates some HTML for newsletters. I'm floating an image using "align=left" and wrapping text around it. I use an inline CSS style, in this case margin-right, to give the image some breathing room. Outlook ignores this. Outlook also ignores padding - I even tried a 10px border-right, it ignored that, too.
I can't change the layout and put the image in a table. I am thinking of using GD to manipulate the image, adding 8px of whitespace to the right side of it. The catch is, since this is a newsletter going out to thousands of people, is that I then need to save the modified image to the server somewhere so I can link to it. I don't want to generate this on the fly.
I have zero experience with GD or saving files to a location with PHP. Here is my image code:
<img alt="<?php print $main2['title']; ?>" height="127" width="185" src="http://www.mydomain.com/uploads/<?php print $main2['filename']; ?>" align="left" style="margin:8px 8px 0 0;"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您当然可以依靠 CSS 来处理时事通讯 - 仅某些属性,并且是内联的。我们开展了一系列非常成功的活动,时事通讯看起来很适合每个人。
我们的网络服务器上有一个文件夹,里面有几千张经过修改的小图像,这不是问题。
我们不能改变布局,因为这是一些重要人物想要的——而这些重要人物付给我相当多的钱来实现他们想要的事情。是的,我可以对此提出很大的批评,并可能说服他们,但如果我可以相反地花几个小时让它发挥作用,为什么不呢?
FWIW,我确实设法用 GD 完成了这个工作 - 并不像我想象的那么复杂 - 如果其他人需要它,我会发布脚本:
You can certainly rely on CSS for newsletters - just certain properties only, and inline. We run a very successful set of campaigns and the newsletters look just fine for everyone.
It's not a problem that we have a folder on our web server where there are a few thousand small modified images.
We can't change the layout, well, because that's what some important people want - and the important people pay me a decent amount of money to make what they want happen. Yeah, I could raise a big stink about it and probably convince them otherwise, but if I could conversely spend a few hours and get it to work, why not?
FWIW, I did manage to get this done with GD - wasn't as complicated as I thought - will post the script if anyone else needs it:
您应该首先避免在时事通讯中使用 CSS,因为您不能依赖它,除非您制作它的纯文本版本。
对于这个简单的问题,这个方法似乎有点大材小用。另外,事实上您的图像将被永远修改。如果您将包含 CSS 的新闻通讯发送给成千上万的人,我认为您应该首先确保您的客户都能够正确检查它。
你说你不能改变布局,我能问为什么吗?
现在,要回答您的问题,您不需要 GD 来执行此操作,您只需编写一个脚本来批量“转换”您的图像,并将它们全部准备好用于您的时事通讯。
例如: http://www.imagemagick.org/Usage/thumbnails/#pad
两个建议
第一
尝试在新闻通讯中使用表格而不是 CSS,您将能够在表格中使用表格有效地进行填充。
第二
首先检查问题,设计是一个问题,如果您想正确接触到所有订阅者,这一点非常重要。看看 mailchimp 免费帐户,您可以设置所有新闻通讯模板并免费测试它,您将能够检查生成的代码。
You should first avoid css for a newsletter as you can't rely on it, except if you make an text only version of it.
This method seems a little overkill for this simple problem. Plus de fact that your images are going to be modified forever. If you send your newsletter to thousands of people with css in it, i think you should first make sure of your client are all able to check it correctly.
You said that you can't change the layout, can i ask why ?
Now, to answer your question, you don't need GD to do this, you can simply make a script to "transform" your images in batches and have them all ready for your newsletter.
Eg: http://www.imagemagick.org/Usage/thumbnails/#pad
two suggestions
First
Try to use tables instead of css in your newsletter, you will be able to pad effectively with a table inside a table.
Second
Check at the problem first, the design is an issue and it is really important if you want to reach correctly all your suscribers. Have a look at mailchimp free acounts, you can setup a newsletter template all and test it all for free, you will be able to check the generated code.
您可以使用 gif 间隔符(老派 html 是的):
间隔符是一个简单的 1x1 透明像素,
你可以用 html 属性给它指定你需要的大小,这样就可以了。
顺便说一句,你的主要问题实际上是如何构建 html/css 。以下是一些关于如何发送跨客户端 html 电子邮件的重要资源: http://www.campaignmonitor.com /设计指南/
You can use a gif spacer (old school html yeah):
A Spacer is a simple 1x1 transparent pixel,
you give it the size you need with html attributes and that should do the trick.
Btw your main issue is actually how you have build your html/css. Here is some great ressources on how to do cross-clients html emails: http://www.campaignmonitor.com/design-guidelines/