PHP——更多的是如何在保持透明度的同时组合两个图像


PHP - a little more than how to combine two images while keeping transparency

所以我已经知道如何使用带有php的GD图像库来组合两个图像并保持透明度,但我需要能够从服务器中提取图像,同时保持尺寸为2的幂,这样我就可以将它们用作纹理,应用于opengl中的三维对象。

因此,我真正的问题是,如何将图像的缩放版本保持其原始比例在256x256或128x128尺寸的透明图像中。另外,我想把调整大小的图像放在完全透明的图像的中心。

这方面的一些帮助会很棒。

查看这些引用,我认为这正是您想要的:http://php.net/manual/en/function.imagecopyresized.php

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>