Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> zapis pliku - problem, jak zapisać jpga z różną rozdzielczością
niko
post 28.07.2005, 04:11:26
Post #1





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 2.06.2005

Ostrzeżenie: (30%)
XX---


mam plik który robi mniejszego i bardziej skompresowanego jpga z pliku załadowanego na serwer - jak można to przerobić by zapisywał mi dwie miniatrurki ?

oto skrypt:

  1. <?
  2. $gd_version=1;
  3. class thumbnail
  4. {
  5. var $img;
  6. function thumbnail($imgfile)
  7. {
  8. $this->img[&#092;"format\"]=ereg_replace(\".*.(.*)$\",\"1\",$imgfile);
  9. $this->img[&#092;"format\"]=strtoupper($this->img[\"format\"]);
  10. if ($this->img[&#092;"format\"]==\"JPG\" || $this->img[\"format\"]==\"JPEG\") {
  11. //JPEG
  12. $this->img[&#092;"format\"]=\"JPEG\";
  13. $this->img[&#092;"src\"] = ImageCreateFromJPEG ($imgfile);
  14. } elseif ($this->img[&#092;"format\"]==\"PNG\") {
  15. //PNG
  16. $this->img[&#092;"format\"]=\"PNG\";
  17. $this->img[&#092;"src\"] = ImageCreateFromPNG ($imgfile);
  18. } else {
  19. //DEFAULT
  20. echo &#092;"Not Supported File! Thumbnails can only be made from .jpg and .png images!\";
  21. exit();
  22. }
  23. @$this->img[&#092;"lebar\"] = imagesx($this->img[\"src\"]);
  24. @$this->img[&#092;"tinggi\"] = imagesy($this->img[\"src\"]);
  25. //default quality jpeg
  26. $this->img[&#092;"quality\"]=100;
  27. }
  28. function size_auto($size=100)
  29. {
  30. //size
  31. if ($this->img[&#092;"lebar\"]>=$this->img[\"tinggi\"]) {
  32. $this->img[&#092;"lebar_thumb\"]=$size;
  33. @$this->img[&#092;"tinggi_thumb\"] = ($this->img[\"lebar_thumb\"]/$this->img[\"lebar\"])*$this->img[\"tinggi\"];
  34. } else {
  35. $this->img[&#092;"tinggi_thumb\"]=$size;
  36. @$this->img[&#092;"lebar_thumb\"] = ($this->img[\"tinggi_thumb\"]/$this->img[\"tinggi\"])*$this->img[\"lebar\"];
  37.  }
  38. }
  39. function jpeg_quality($quality=100)
  40. {
  41. //jpeg quality
  42. $this->img[&#092;"quality\"]=$quality;
  43. }
  44. function show($gd_version)
  45. {
  46. @Header(&#092;"Content-Type: image/\".$this->img[\"format\"]);
  47.  if($gd_version==2)
  48. {
  49. $this->img[&#092;"des\"] = imagecreatetruecolor($this->img[\"lebar_thumb\"],$this->img[\"tinggi_thumb\"]);
  50. @imagecopyresampled ($this->img[&#092;"des\"], $this->img[\"src\"], 0, 0, 0, 0, $this->img[\"lebar_thumb\"],$this->img[\"tinggi_thumb\"], $this->img[\"lebar\"], $this->img[\"tinggi\"]);
  51. }
  52. if($gd_version==1)
  53. {
  54. $this->img[&#092;"des\"] = imagecreate($this->img[\"lebar_thumb\"],$this->img[\"tinggi_thumb\"]);
  55. @imagecopyresized ($this->img[&#092;"des\"], $this->img[\"src\"], 0, 0, 0, 0, $this->img[\"lebar_thumb\"],$this->img[\"tinggi_thumb\"], $this->img[\"lebar\"], $this->img[\"tinggi\"]);
  56. }
  57. if ($this->img[&#092;"format\"]==\"JPG\" || $this->img[\"format\"]==\"JPEG\") {
  58. //JPEG
  59. imageJPEG($this->img[&#092;"des\"],\"\",$this->img[\"quality\"]);
  60. } elseif ($this->img[&#092;"format\"]==\"PNG\") {
  61. //PNG
  62. imagePNG($this->img[&#092;"des\"]);
  63. }
  64. }
  65. function save($save=&#092;"\",$gd_version)
  66. {
  67. if($gd_version==2)
  68. {
  69. $this->img[&#092;"des\"] = imagecreatetruecolor($this->img[\"lebar_thumb\"],$this->img[\"tinggi_thumb\"]);
  70. @imagecopyresampled ($this->img[&#092;"des\"], $this->img[\"src\"], 0, 0, 0, 0, $this->img[\"lebar_thumb\"], $this->img[\"tinggi_thumb\"], $this->img[\"lebar\"], $this->img[\"tinggi\"]);
  71. }
  72. if($gd_version==1)
  73. {
  74.  $this->img[&#092;"des\"] = imagecreate($this->img[\"lebar_thumb\"],$this->img[\"tinggi_thumb\"]);
  75.  @imagecopyresized ($this->img[&#092;"des\"], $this->img[\"src\"], 0, 0, 0, 0, $this->img[\"lebar_thumb\"], $this->img[\"tinggi_thumb\"], $this->img[\"lebar\"], $this->img[\"tinggi\"]);
  76. }
  77.  if ($this->img[&#092;"format\"]==\"JPG\" || $this->img[\"format\"]==\"JPEG\") {
  78. //JPEG
  79. imageJPEG($this->img[&#092;"des\"],\"$save\",$this->img[\"quality\"]);
  80. } elseif ($this->img[&#092;"format\"]==\"PNG\") {
  81. //PNG
  82. imagePNG($this->img[&#092;"des\"],\"$save\");
  83. }
  84.  
  85.  
  86.  
  87. }
  88. }
  89. ?>


wywolanie jego jest następujące :

  1. <?php
  2.  
  3. $res = move_uploaded_file($userfile, $path . $userfile_name);
  4. if (file_exists(&#092;"$site_dir/images/\" . \"thumb_$userfile_name\"))
  5. {
  6. unlink(&#092;"$site_dir/images/thumb_$userfile_name\");
  7. $thumb=new thumbnail(&#092;"$site_dir/images/$userfile_name\");
  8. $thumb->size_auto(150);
  9. $thumb->jpeg_quality(100);
  10. $thumb->save(&#092;"$site_dir/images/thumb_$userfile_name\", $gd_version);
  11. } else {
  12. $thumb=new thumbnail(&#092;"$site_dir/images/$userfile_name\");
  13. $thumb->size_auto(150);
  14. $thumb->jpeg_quality(100);
  15. $thumb->save(&#092;"$site_dir/images/thumb_$userfile_name\", $gd_version);
  16. }
  17. }
  18.  
  19. ?>


jak zrobić by odrazu zapisywał mi dwa pliki - jeden o rozmiarze 150 [wysokość] a drugi o rozmiarze 100 [wysokość]
Go to the top of the page
+Quote Post
tiraeth
post 28.07.2005, 13:20:53
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 789
Pomógł: 41
Dołączył: 30.10.2003
Skąd: Wrocław

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


Przenoszę: Skrypty php -> php
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 19.07.2025 - 12:53