将空白添加到图像并将文件保存到服务器 [英] Add whitespace to image and save file to server

查看:128
本文介绍了将空白添加到图像并将文件保存到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本可以为简报生成一些HTML。我使用align = left浮动图像并在其周围包装文本。我使用内联CSS样式,在这种情况下是margin-right,为图像提供一些喘息空间。 Outlook忽略了这一点。 Outlook也忽略了填充 - 我甚至尝试了10px的边框右边,它也忽略了它。

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.

我无法更改布局并将图像放在表格中。我正在考虑使用GD来操作图像,在其右侧添加8px的空白。因为这是一个向成千上万的人发送的时事通讯,因此我需要将修改后的图像保存到某个地方的服务器,以便我可以链接到它。我不想在运行中生成这个。

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.

我没有使用GD的经验或使用PHP将文件保存到某个位置。这是我的图像代码:

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;"/>


推荐答案

你当然可以依靠CSS来发送简讯 - 只是肯定仅限属性和内联。我们运行了一系列非常成功的广告系列,每个人的新闻简报都很合适。

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 ,我确实设法用GD完成了 - 没有我想的那么复杂 - 如果其他人需要它会发布脚本:

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:

// get image
$url = 'myimage.jpg';
$src = imagecreatefromjpeg($url);

// dimensions (just to be safe, should always be 185x127 though)
$src_wide = imagesx($src);
$src_high = imagesy($src);

// set white padding color
$clear = array('red'=>255,'green'=>255,'blue'=>255);

// new image dimensions with right padding
$dst_wide = $src_wide+8;
$dst_high = $src_high+8;

// New resource image at new size
$dst = imagecreatetruecolor($dst_wide, $dst_high);

// fill the image with the white padding color
$clear = imagecolorallocate( $dst, $clear["red"], $clear["green"], $clear["blue"]);
imagefill($dst, 0, 0, $clear);

// copy the original image on top of the new one
imagecopymerge($dst,$src,0,8,0,0,$src_wide,$src_high, 100);

// store the new image in tmp directory
$pth = 'tmp/myimage.jpg';
imagejpeg($dst, $pth, 100);

// free resources
imagedestroy($src);
imagedestroy($dst); 

这篇关于将空白添加到图像并将文件保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆