2013-07-16 7 views
6

मैं एक आकार बदलने छवि स्क्रिप्ट है कि एक 130x81 छवि लेता है और एक 130x130 छवि में जोड़ लेता है, imagecopyresampled समारोह चलाता है जब यह, अंतरिक्ष उस पर छोड़ दिया जाता है में एक काले रंग की पृष्ठभूमि कहते हैं भी आधार छवि हालांकि सफेद है। नीचे कोड, मैं वास्तव में कुछ मदद की सराहना कर सकता था।php imagecopyresampled कहते हैं काले रंग की पृष्ठभूमि

छवि मेरे द्वारा बनाए गए 130x130 फ़ाइल php पर मिलने के लिए कोशिश कर रहा हूँ है: 130x81 image

$width = 130; 
$height = 130; 
$filename = 'process-add.jpg'; //130x81px jpg 
$this->_image = imagecreatefromjpeg($filename); 

$background = imagecreatetruecolor(130,130);//create the background 130x130 
$whiteBackground = imagecolorallocate($background, 255, 255, 255); 
imagefill($background,0,0,$whiteBackground); // fill the background with white 

imagecopyresampled($background, $this->_image,(130-$width)/2,(130-$height)/2, 0, 0, $width, $height, $width, $height); // copy the image to the background 

ImageJpeg ($background,null,100); //display 

मैं कई पदों पर पढ़ा है जोड़ने के लिए:

imagealphablending($background, false); 

कोड है जो ठीक करना चाहिए में यह, लेकिन इससे कोई फर्क नहीं पड़ता है।

अग्रिम धन्यवाद!

उत्तर

10

यह हल हो गया है। यह समस्या imagecopyresampled कॉल पर teh चौड़ाई और ऊंचाई के साथ थी।

<? 

ini_set('allow_url_fopen', true); 
$filename = 'http://img.yessy.com/1402152287-17201a.jpg'; // 130x81 
$image = imagecreatefromjpeg($filename); 
list($originalWidth, $originalHeight) = getimagesize($filename); 

// Size of image to create 
$width = 130; 
$height = 130; 

$background = imagecreatetruecolor($width, $height);//create the background 130x130 
$whiteBackground = imagecolorallocate($background, 255, 255, 255); 
imagefill($background,0,0,$whiteBackground); // fill the background with white 

imagecopyresampled($background, $image, 0, ($height - $originalHeight)/2, 0, 0, $originalWidth, $originalHeight, $originalWidth, $originalHeight); // copy the image to the background 

header("Content-type: image/jpeg"); 
ImageJpeg ($background,null,100); //display 
?> 
: नीचे कोड ब्लॉक देखें
संबंधित मुद्दे