2010-11-10 19 views
5

तो मैं png छवि है और मैं इसे बारी बारी से, लेकिन मैं एक काली पृष्ठभूमि मिल .. या अगर मैं सफेद मैं सफेद मिल ofr रंग कोड करना .. मैं यह कर की कोशिश की ..php के साथ एक पीएनजी छवि rotaing के बाद मैं एक पारदर्शी पृष्ठभूमि कैसे प्राप्त करूं?

$trans = imagecolorallocatealpha(image, 0, 0, 0, 127); 
imagerotate($image, $degree, $trans) 

मैं भी कोशिश की है ..

$trans = imagecolorallocatealpha($image, 255, 255, 255, 127); 

क्या कोई मेरी मदद कर सकता है?

यहां मेरा कोड है .. अगर मैं 0, 0, 255, 0 पर आवंटित करता हूं तो यह नीला हो जाता है। लेकिन 0, 0, 0, 127 के साथ यह अभी भी काला है।

function rotate($degrees) {
$image = $this->image;
imagealphablending($image, false);
$color = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($this->image, 0, 0, $color);
$rotate = imagerotate($image, $degrees, $color);
imagesavealpha($image, TRUE);
$this->image = $rotate;

+0

क्या मूल कोड यहां '$ image' की बजाय 'image' का उपयोग करता है? – MiffTheFox

+0

हाँ वे मूल कोड $ छवि – Chris

उत्तर

0

आप इस की कोशिश की है?

imagecolortransparent

आशा है कि मैं अपने प्रश्न समझ में आ!

+0

का उपयोग करते हैं धन्यवाद! आखिर में काम किया! – Chris

+0

@ सुनने के लिए महान !! एक जवाब को सही के रूप में जांचना याद रखें! (डोस्ट मेरा होना है, लेकिन जिसने आपको सबसे ज्यादा मदद की है) – Trufa

+0

हाँ मैंने पाया कि यह वास्तव में काम नहीं करता है। यह सिर्फ एक सफेद पृष्ठभूमि थी इसलिए यह उस तरह से दिखाई दिया, इसलिए मैं अभी भी एक जवाब की तलाश में हूं। हालांकि मुझे उस समारोह को दिखाने के लिए धन्यवाद! – Chris

0
 // Turn off transparency blending (temporarily) 
     imagealphablending($image, false); 

     // Create a new transparent color for image 
     $color = imagecolorallocatealpha($image, 0, 0, 0, 127); 

     // Completely fill the background of the new image with allocated color. 
     imagefill($image, 0, 0, $color); 

     // Restore transparency blending 
     imagesavealpha($image, true); 
+0

मैंने पहले यह कोशिश की थी और यह किसी कारण से काम नहीं कर रहा था – Chris

+0

ठीक है इसलिए मैंने झूठ बोला कि imagecolortransparent काम नहीं कर रहा है, यह सिर्फ सफेद पृष्ठभूमि की वजह से दिखता है .. मैंने फिर से इस तरह से कोशिश की और मुझे पता है कि यह काम करता है क्योंकि मैं पृष्ठभूमि को बदल सकता हूं नीला और लाल इत्यादि आदि, लेकिन जब मैं अल्फा चैनल के साथ गड़बड़ करता हूं तो यह सब काले रंग के पारदर्शी बनाता है .. उदाहरण के लिए यदि मेरे पास आवंटित है .. 0, 0, 255, 75 यह सिर्फ नीले रंग की गहरा छाया बनाता है अगर यह नीला पारदर्शी बनाता है लेकिन इसके पीछे एक काला रंग है – Chris

9
$destimg = imagecreatefromjpeg("image.png"); 
$transColor = imagecolorallocatealpha($destimg, 255, 255, 255, 127); 
$rotatedImage = imagerotate($destimg, 200, $transColor); 
imagesavealpha($rotatedImage, true); 
imagepng($rotatedImage,"rotated.png"); 
+0

ग्रेट उत्तर ... पूरी तरह से काम कर रहा है :-) – abhis

+2

"imagecreatefromjpeg (" image.png ")" imagecreatefrompng ("image.png") "होना चाहिए" –

0
$info = pathinfo($pathToImage); 
    $name = str_replace("." . $info['extension'], "", $info['basename']); 

    $size = getimagesize($pathToImage); 



    $type = isset($size['type']) ? $size['type'] : $size[2]; 

    // Check support of file type 
    if (!(imagetypes() & $type)) { 
     // Server does not support file type 
     return false; 
    } 

    $source = self::imageCreateFrom($pathToImage, trim($info['extension'])) or notfound(); 
    $transColor = imagecolorallocatealpha($source, 255, 255, 255, 127); 

    // $transparency = imagecolorallocatealpha($source, 0, 0, 0, 127); 
    $rotate = imagerotate($source, 360 - $rotate_angle, $transColor); 
    //imagealphablending($rotate, false); 


    imagesavealpha($rotate, TRUE); 
    //imagejpeg($rotate,$pathToThumbs.DIRECTORY_SEPARATOR.$info['basename']); 
    self::createImage($rotate, $pathToThumbs, $info['basename'], trim($info['extension'])); 

    // imagejpeg($rotate); 
    imagedestroy($source); 
    imagedestroy($rotate); 
0

यह मैं क्या उपयोग कर रहा हूँ, यह काम पारदर्शी पृष्ठभूमि के साथ फ़ाइलों .png लिए अच्छा है। उच्च मछुआरे!

function rotate($degrees) { 

    // Switch from default counter-clockwise to clockwise 
    $degrees = 360 - $degrees; 

    // Get the image 
    $source = imagecreatefrompng("images/image.png"); 

    // Rotate the image 
    $rotated_image = imagerotate($source, $degrees, imageColorAllocateAlpha($source, 0, 0, 0, 127)); 

    // Save the rotated image 
    imagepng($rotated_image, 'images/rotated_image.png'); 

} 
संबंधित मुद्दे

 संबंधित मुद्दे