2012-03-02 25 views
0

因此,我已經知道如何結合兩個圖像,並保持透明使用GD圖像庫與PHP,但我需要能夠從服務器拉圖像,同時保持兩個冪的維度,以便我可以將它們用作紋理以應用於opengl中的3d對象。PHP - 稍微比如何結合兩個圖像,同時保持透明

所以我真正的問題是如何放置一個圖像的縮放版本,保持其原始比例在一個具有256x256或128x128尺寸的透明窗體。此外,我想將調整大小的圖像放置在完全透明的圖像中央。

對此有些幫助會很棒。

回答

1

退房此引用,我認爲這是你想要什麼: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); 
?> 
+0

那部分我已經,但即時通訊使用一個循環,我去了每一個像素,以確保它保持着適當的顏色和透明度,因爲有時只使用這種方法,你會得到空白的地方,你的圖像是黑色的。我現在需要的是如何將我的一個圖像放在另一個地方的某個地方 – 2012-03-02 22:00:35

相關問題