הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   היפוך תמונה עם GD ורקעים שקופים (https://hosts.co.il/forums/showthread.php?t=83238)

Erez | TrustMedia.co.il 19-06-10 20:27

היפוך תמונה עם GD ורקעים שקופים
 
אני מנסה להפוך תמונה בצורה אופקית עם GD אבל תמיד כשיש רקע שקוף זה עושה לי בעיות,הנה הפונקציה שאני משתמש בה כדי להפוך את התמונה:
PHP קוד:

function flipHorizontal(&$img) {
$size_x imagesx($img);
$size_y imagesy($img);
$temp imagecreatetruecolor($size_x$size_y);
$x imagecopyresampled($temp$img00, ($size_x-1), 0$size_x$size_y0-$size_x$size_y);
if (
$x) {
$img $temp;
}
else {
die(
"לא ניתן להפוך את התמונה ".$file);
}


והנה הקוד שבעזרתו אני קורא לפונקציה:
PHP קוד:

preg_match('/\.([a-zA-Z]+)$/',$file,$x);
    
$x $x[1];
    if(
$x == 'png'){
        
$myimage imagecreatefrompng($file);
    } elseif(
$x == 'gif'){
        
$myimage imagecreatefromgif($file);
    }  elseif(
$x == 'jpg' || $x == 'jpeg'){
        
$myimage imagecreatefromjpeg($file);
    } else exit;
    if(isset(
$_POST[md5($file)])){
        
flipHorizontal($myimage);
    }
    if(
$x == 'png'){
        
imagepng($myimage,'new'.$file);
    } elseif(
$x == 'gif'){
        
imagegif($myimage,'new'.$file);
    }  elseif(
$x == 'jpg' || $x == 'jpeg'){
        
imagejpeg($myimage,'new'.$file);
    } else exit; 

אני שובר את הראש כבר שעות ולא מצליח,אז אם מישהו יודע איך לסדר את זה(וכן,חיפשתי פתרונות בגוגל וניסית imagesavealpha וכל מיני שיטות ולא עבד לי)
תודה לעוזרים

~The_Sultan~ 19-06-10 22:55

מצאתי את זה ב-PHP.NET:
PHP קוד:

Don't forget about imagealphablending() and imagesavealpha() if you're working with [semi]transparent png.

<?php
$file 
'semitransparent.png'// path to png image
$img imagecreatefrompng($file); // open image
imagealphablending($imgtrue); // setting alpha blending on
imagesavealpha($imgtrue); // save alphablending setting (important)
?>

ותעיין אולי בפונקציה הזו: http://www.php.net/manual/en/functio...ransparent.php

בהצלחה


כל הזמנים הם GMT +2. הזמן כעת הוא 20:51.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ