Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> ustawianie przezroczystości obrazka
patrykt
post
Post #1





Grupa: Zarejestrowani
Postów: 101
Pomógł: 0
Dołączył: 3.12.2005

Ostrzeżenie: (0%)
-----


nie mogę na końcu tego skryptu ustawić przezroczystości dla żółtego koloru. generuję jpga ale niżej będzie inny obrazek dlatego chcę, żeby ten wyższy miał gdzieniegdzie przezroczystość. jeśli funkcja, której używam jest przeznaczona do gifów/pngów to może inaczej to zrobić?

  1. <?
  2. header('Content-type: image/jpeg');
  3.  
  4. $im = imagecreatefromjpeg('b.jpg');
  5.  
  6.  
  7. $src_img = $im;
  8. $angle = -7;
  9. $bicubic=false;
  10.  
  11.  // convert degrees to radians
  12.  $angle = $angle + 180;
  13.  $angle = deg2rad($angle);
  14.  
  15.  $src_x = imagesx($src_img);
  16.  $src_y = imagesy($src_img);
  17.  
  18.  $center_x = floor($src_x/2);
  19.  $center_y = floor($src_y/2);
  20.  
  21.  $cosangle = cos($angle);
  22.  $sinangle = sin($angle);
  23.  
  24.  $corners=array(array(0,0), array($src_x,0), array($src_x,$src_y), array(0,$src_y));
  25.  
  26.  foreach($corners as $key=>$value) {
  27.  $value[0]-=$center_x; //Translate coords to center for rotation
  28.  $value[1]-=$center_y;
  29.  $temp=array();
  30.  $temp[0]=$value[0]*$cosangle+$value[1]*$sinangle;
  31.  $temp[1]=$value[1]*$cosangle-$value[0]*$sinangle;
  32.  $corners[$key]=$temp;
  33.  }
  34.  
  35.  $min_x=1000000000000000;
  36.  $max_x=-1000000000000000;
  37.  $min_y=1000000000000000;
  38.  $max_y=-1000000000000000;
  39.  
  40.  foreach($corners as $key => $value) {
  41.  if($value[0]<$min_x)
  42.  $min_x=$value[0];
  43.  if($value[0]>$max_x)
  44.  $max_x=$value[0];
  45.  
  46.  if($value[1]<$min_y)
  47.  $min_y=$value[1];
  48.  if($value[1]>$max_y)
  49.  $max_y=$value[1];
  50.  }
  51.  
  52.  $rotate_width=round($max_x-$min_x);
  53.  $rotate_height=round($max_y-$min_y);
  54.  
  55.  $rotate=imagecreatetruecolor($rotate_width,$rotate_height);
  56.  imagealphablending($rotate, false);
  57.  imagesavealpha($rotate, true);
  58.  
  59.  //Reset center to center of our image
  60.  $newcenter_x = ($rotate_width)/2;
  61.  $newcenter_y = ($rotate_height)/2;
  62.  
  63.  for ($y = 0; $y < ($rotate_height); $y++) {
  64.  for ($x = 0; $x < ($rotate_width); $x++) {
  65.  // rotate...
  66.  $old_x = round((($newcenter_x-$x) * $cosangle + ($newcenter_y-$y) * $sinangle))
  67.  + $center_x;
  68.  $old_y = round((($newcenter_y-$y) * $cosangle - ($newcenter_x-$x) * $sinangle))
  69.  + $center_y;
  70.  
  71.  if ( $old_x >= 0 && $old_x < $src_x
  72.  && $old_y >= 0 && $old_y < $src_y ) {
  73.  
  74.  $color = imagecolorat($src_img, $old_x, $old_y);
  75.  //$color = imagecolorset($src_img, 247, 247, 173);
  76.  
  77.  } else {
  78.  // this line sets the background colour
  79.  $color = imagecolorallocatealpha($src_img, 247, 247, 173, 127);
  80.  }
  81.  imagesetpixel($rotate, $x, $y, $color);
  82.  }
  83.  }
  84.  
  85.  $im = $rotate;
  86.  $trans = imagecolorallocate($im, 247,247,173);
  87.  imagecolortransparent($im,$trans);
  88. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
batman
post
Post #2





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




Będę szczery. Nie przejrzałem kodu (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Z tego co mi wiadomo jpg nie obsługuje czegoś takiego jak przezroczystość. Jeśli chcesz jej użyć to zamiast jpg daj gifa i powinno być ok.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 08:13