Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] konwerotwanie grafiki
Baksik
post
Post #1





Grupa: Zarejestrowani
Postów: 29
Pomógł: 0
Dołączył: 6.07.2003
Skąd: Zabrze

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


Witam, mam pytanie.
Jak konwertuje się grafikę przy użyciu gd2?

Mam formularz który upload-uje plik .jpg na serwer.
I chciałbym zmiejszyć jego rozdzielczość np. do 600x400,
Mógłby ktoś pomóc, będe zobowiązany
Go to the top of the page
+Quote Post
Adiasz
post
Post #2





Grupa: Zarejestrowani
Postów: 155
Pomógł: 0
Dołączył: 28.02.2004

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


copy paste z jakiegos mojego skryptu
w twoim przypadku $this->maxWidth = 600 $this->maxHeight = 400
na forum pelno przykladow pod haslem miniaturki
  1. <?php
  2.  
  3. $dimensions = getimagesize( $this->imagesStartDir.$fileName );
  4. $oldWidth = $dimensions[0];
  5. $oldHeight = $dimensions[1];
  6.  
  7. while( $oldWidth > $this->maxWidth || $oldHeight > $this->maxHeight ) {
  8. $oldWidth -= $oldWidth * 0.01;
  9. $oldHeight -= $oldHeight * 0.01;
  10. }
  11. $newWidth = $oldWidth;
  12. $newHeight = $oldHeight;
  13.  
  14. $small = imagecreatetruecolor( $newWidth, $newHeight ); 
  15.  
  16. if( eregi( ".gif", $fileName ) ) {
  17. $source = imagecreatefromgif( $this->imagesStartDir.$fileName );
  18. } else {
  19. $source = imagecreatefromjpeg( $this->imagesStartDir.$fileName );
  20. } 
  21.  
  22. imagecopyresampled( $small, $source, 0, 0, 0, 0, (int)$newWidth, (int)$newHeight, (int)$dimensions[0], (int)$dimensions[1]);
  23.  
  24. $result = imagejpeg( $small, $this->imagesDestinationDir.$smallFileName ) ;
  25. imagedestroy( $small );
  26. ?>
Go to the top of the page
+Quote Post
Hacker
post
Post #3





Grupa: Zarejestrowani
Postów: 225
Pomógł: 0
Dołączył: 1.11.2005

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


Hmmmm...
  1. <?php
  2. while( $oldWidth > $this->maxWidth || $oldHeight > $this->maxHeight ) {
  3. $oldWidth -= $oldWidth * 0.01;
  4. $oldHeight -= $oldHeight * 0.01;
  5. }
  6. ?>


czy nie wydaje Ci się, że to niedokładne i niewydajne??

  1. <?php
  2.  
  3. $dzielnik = max($oldWidth/$this->maxWidth, $oldHeight/$this->maxHeight);
  4. $newWidth = $oldWidth/$dzielnik;
  5. $newHeight = $oldHeight/$dzielnik;
  6.  
  7. ?>


Nie lepiej?? (kod pisany na szybko może zawierać błędy)


--------------------
(\.../)This is Bunny
(O.o)Copy Bunny into your signature to help him...
(> <)...on his way to world domination
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 Aktualny czas: 20.08.2025 - 07:30