我正在尝试使用此类:http ://www.verot.net/php_class_upload_samples.htm
如果有人熟悉调整大小和填充图像的其余部分,请帮助我。
这个想法是,如果你上传一张 600x600 的图片,我想保存两张图片:1-600x600 和 1-300x300。到目前为止,它工作得很好。但是,如果用户选择上传大小为 749x1202 的图片,我希望脚本使其在 300x300 和 600x600 中看起来不错,其中无用的空间被白色填充,因此图像仍然是 600x600。对于较小的图像(例如 249x400)也应如此。
到目前为止,这是我的代码:
// Set the upload directory
$uploadDir = '../../htdocs/public/product_images/'.$id.'/';
$thumbDir = '../../htdocs/public/product_images/'.$id.'/thumbs/';
@mkdir($uploadDir, 0755, true);
@mkdir($thumbDir, 0755, true);
// Store the file content in a variable
$file = file_get_contents('php://input');
// Save the file to the server
file_put_contents($uploadDir . $filename, $file);
$targetFile = str_replace('//','/',$uploadDir) . $filename;
$targetThumb = str_replace('//','/',$thumbDir) . $filename;
copy ($targetFile,$targetThumb);
$image = new upload($targetFile);
if ($image->uploaded) {
$image->image_resize = true;
$image->image_ratio_fill = true;
$image->image_x = 600;
$image->image_y = 600;
$image->file_overwrite = true;
$image->process($uploadDir);
}
$image = new upload($targetThumb);
if ($image->uploaded) {
$image->image_resize = true;
$image->image_ratio_fill = true;
$image->image_x = 300;
$image->image_y = 300;
$image->file_overwrite = true;
$image->process($thumbDir);
}
我可以用另一种方式做到这一点,但如果有人能指导我一点,我将非常感激。