Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z GD .bmp
dawka83
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 7.11.2011
Skąd: Kraków

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


Witam posiadam oto taką funkcję, która ma przekształcić bmp w jpg:
  1. function imagecreatefrombmp($p_sFile) {
  2. $file = fopen($p_sFile, "rb");
  3. $read = fread($file, 10);
  4. while (!feof($file) && ($read <> ""))
  5. $read .= fread($file, 1024);
  6. $temp = unpack("H*", $read);
  7. $hex = $temp[1];
  8. $header = substr($hex, 0, 108);
  9. if (substr($header, 0, 4) == "424d") {
  10. $header_parts = str_split($header, 2);
  11. $width = hexdec($header_parts[19] . $header_parts[18]);
  12. $height = hexdec($header_parts[23] . $header_parts[22]);
  13. unset($header_parts);
  14. }
  15. $x = 0;
  16. $y = 1;
  17. $image = imagecreatetruecolor($width, $height);
  18. $body = substr($hex, 108);
  19. $body_size = (strlen($body) / 2);
  20. $header_size = ($width * $height);
  21. $usePadding = ($body_size > ($header_size * 3) + 4);
  22. for ($i = 0; $i < $body_size; $i+=3) {
  23. if ($x >= $width) {
  24. if ($usePadding)
  25. $i += $width % 4;
  26. $x = 0;
  27. $y++;
  28. if ($y > $height)
  29. break;
  30. }
  31. $i_pos = $i * 2;
  32. $r = hexdec($body[$i_pos + 4] . $body[$i_pos + 5]);
  33. $g = hexdec($body[$i_pos + 2] . $body[$i_pos + 3]);
  34. $b = hexdec($body[$i_pos] . $body[$i_pos + 1]);
  35. $color = imagecolorallocate($image, $r, $g, $b);
  36. imagesetpixel($image, $x, $height - $y, $color);
  37. $x++;
  38. }
  39. unset($body);
  40. return $image;
  41. }
  42.  
  43. header('Content-Type: image/jpeg');
  44. $image = imagecreatefrombmp("1.bmp");
  45. imagejpeg($image);


jednak po jej wykonaniu dostaje jakiś dziwny rozjechany obrazek:


Powinno byc:


Co robię nie tak?
Go to the top of the page
+Quote Post

Posty w temacie
- dawka83   Problem z GD .bmp   17.12.2016, 20:17:52
- - trueblue   Kompletnie inne wymiary (nie są to wielokrotności ...   17.12.2016, 21:09:08


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

 



RSS Aktualny czas: 19.08.2025 - 17:10