Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][imagejpeg]Zmaian wymiarów obrazka podczas zapisu, Funkcja imagejpeg
LukasKK
post
Post #1





Grupa: Zarejestrowani
Postów: 43
Pomógł: 0
Dołączył: 20.02.2007

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


Witam,


Wpadłem na mały problem zmieniam sobie rozmiar pliku i gdy go wyswietle to ma prawidłowe rozmiary powiedzmy 200x200
  1. <?php
  2. header ("Content-type: image/jpeg");
  3. /*
  4. JPEG / PNG Image Resizer
  5. Parameters (passed via URL):
  6.  
  7. img = path / url of jpeg or png image file
  8.  
  9. percent = if this is defined, image is resized by it's
  10. value in percent (i.e. 50 to divide by 50 percent)
  11.  
  12. w = image width
  13.  
  14. h = image height
  15.  
  16. constrain = if this is parameter is passed and w and h are set
  17. to a size value then the size of the resulting image
  18. is constrained by whichever dimension is smaller
  19.  
  20. Requires the PHP GD Extension
  21.  
  22. Outputs the resulting image in JPEG Format
  23.  
  24. By: Michael John G. Lopez - www.sydel.net
  25. Filename : imgsize.php
  26. */
  27.  
  28. $img = 'img/garten2_001ARVT1.JPG';
  29. $percent = $_GET['percent'];
  30. $constrain = $_GET['constrain'];
  31. $w = 200;
  32. $h = 200;
  33.  
  34. // get image size of img
  35. $x = @getimagesize($img);
  36. // image width
  37. $sw = $x[0];
  38. // image height
  39. $sh = $x[1];
  40.  
  41. if ($percent > 0) {
  42. // calculate resized height and width if percent is defined
  43. $percent = $percent * 0.01;
  44. $w = $sw * $percent;
  45. $h = $sh * $percent;
  46. } else {
  47. if (isset ($w) AND !isset ($h)) {
  48. // autocompute height if only width is set
  49. $h = (100 / ($sw / $w)) * .01;
  50. $h = @round ($sh * $h);
  51. } elseif (isset ($h) AND !isset ($w)) {
  52. // autocompute width if only height is set
  53. $w = (100 / ($sh / $h)) * .01;
  54. $w = @round ($sw * $w);
  55. } elseif (isset ($h) AND isset ($w) AND isset ($constrain)) {
  56. // get the smaller resulting image dimension if both height
  57. // and width are set and $constrain is also set
  58. $hx = (100 / ($sw / $w)) * .01;
  59. $hx = @round ($sh * $hx);
  60.  
  61. $wx = (100 / ($sh / $h)) * .01;
  62. $wx = @round ($sw * $wx);
  63.  
  64. if ($hx < $h) {
  65. $h = (100 / ($sw / $w)) * .01;
  66. $h = @round ($sh * $h);
  67. } else {
  68. $w = (100 / ($sh / $h)) * .01;
  69. $w = @round ($sw * $w);
  70. }
  71. }
  72. }
  73.  
  74. $im = @ImageCreateFromJPEG ($img) or // Read JPEG Image
  75. $im = @ImageCreateFromPNG ($img) or // or PNG Image
  76. $im = @ImageCreateFromGIF ($img) or // or GIF Image
  77. $im = false; // If image is not JPEG, PNG, or GIF
  78.  
  79. if (!$im) {
  80. // We get errors from PHP's ImageCreate functions...
  81. // So let's echo back the contents of the actual image.
  82. readfile ($img);
  83. } else {
  84. // Create the resized image destination
  85. $thumb = @ImageCreateTrueColor ($w, $h);
  86. // Copy from image source, resize it, and paste to image destination
  87. @ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh);
  88. // Output resized image
  89. @ImageJPEG ($thumb);
  90. }
  91. ?>




Jednak po zapisie
  1. <?php
  2. imagejpeg($thumb,$new,100);
  3. ?>
zmienia rozmiar na totalnie przypadkowy nie wiem czemu.



Pozdro Łukasz

Ten post edytował LukasKK 13.09.2007, 22:30:49
Go to the top of the page
+Quote Post

Posty w temacie


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: 20.08.2025 - 07:11