Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] Przycinanie obrazka
motor
post 12.09.2006, 09:30:42
Post #1





Grupa: Zarejestrowani
Postów: 211
Pomógł: 0
Dołączył: 15.12.2005

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


Witam
mam taki dylemat chcę przyciąć obrazki jpg z góry i z dołu o daną wartość zawsze tą samą .

szukam najlepiej gotowego skryptu
na forum znalazłem coś takiego

  1. <?php
  2. $im_file_name="1.jpg";
  3.  
  4. function resize($im_file_name){
  5. $image_attribs = getimagesize($im_file_name);
  6. $im_old = imageCreateFromJpeg($im_file_name);
  7. $th_max_width = 120;
  8. $th_max_height = 120;
  9. if($image_attribs[0]>=$image_attribs[1]){
  10. @$ratio = ($width >= $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1];
  11. }
  12. else{
  13. @$ratio = ($width < $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1];
  14. }
  15. $th_width = $image_attribs[0] * $ratio;
  16. $th_height = $image_attribs[1] * $ratio;
  17. $im_new = imagecreatetruecolor($th_width,$th_height);
  18. $th_file_name = strrchr($im_file_name, "/");
  19. $th_file_name = substr($im_file_name, 0 , strlen($im_file_name)-4) . '-thumb.jpg';
  20. imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]);
  21. imageJpeg($im_new, $th_file_name ,80);
  22. }
  23. ?>


Ale coś mi nie działa nie wiem dlaczego ?
Go to the top of the page
+Quote Post
mdco
post 12.09.2006, 09:41:29
Post #2





Grupa: Zarejestrowani
Postów: 324
Pomógł: 5
Dołączył: 14.12.2004

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


A mam takie bardzo ważne pytanie. Wywołujesz gdzieś tą zdefiniowaną funkcje?
Poza tym ta funkcja skaluje obrazek, nie wiem czy o to Ci chodziło?

Ten post edytował mdco 12.09.2006, 09:42:34


--------------------
zmoderowano - rozmiar
Go to the top of the page
+Quote Post
Spirit86
post 12.09.2006, 09:44:22
Post #3





Grupa: Zarejestrowani
Postów: 607
Pomógł: 23
Dołączył: 8.09.2004
Skąd: Wrocław

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


spróbuj tak:
  1. <?php
  2. $im_file_name="1.jpg";
  3.  
  4.  
  5. $image_attribs = getimagesize($im_file_name);
  6. $im_old = imageCreateFromJpeg($im_file_name);
  7. $th_max_width = 120;
  8. $th_max_height = 120;
  9. if($image_attribs[0]>=$image_attribs[1]){
  10. @$ratio = ($width >= $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1];
  11. }
  12. else{
  13. @$ratio = ($width < $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1];
  14. }
  15. $th_width = $image_attribs[0] * $ratio;
  16. $th_height = $image_attribs[1] * $ratio;
  17. $im_new = imagecreatetruecolor($th_width,$th_height);
  18. $th_file_name = strrchr($im_file_name, "/");
  19. $th_file_name = substr($im_file_name, 0 , strlen($im_file_name)-4) . '-thumb.jpg';
  20. imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]);
  21. imageJpeg($im_new, $th_file_name ,80);
  22.  
  23. ?>

biggrin.gif


--------------------
Audio: Metallica, Soil, RHCP, OffSpring, Green Day, "Retro", Gorillaz, Disturbed, Coma
DB: MySQL 4.1 | php: 4.4.3 Pomogłem Ci? Wciśnij przycisk POMÓGŁ.
Go to the top of the page
+Quote Post
motor
post 12.09.2006, 10:06:57
Post #4





Grupa: Zarejestrowani
Postów: 211
Pomógł: 0
Dołączył: 15.12.2005

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


działa ale ta funkcja zmniejsza obrazek a ja chce go przyciąć bez zmiany rozmiaru coś takiego smile.gif




mam tu jeszcze coś takiego
  1. <?php
  2. $filejpg= './images/' . $_POST['dzial'] . '/' . date("mdYHis") . '.jpg';
  3. if(move_uploaded_file($_FILES['plik']['tmp_name'], $filejpg)){
  4. $f = fopen($filetext, "w+");
  5. fputs($f, htmlspecialchars($_POST['cena']) . "n");
  6. fputs($f, date("mdYHis"));
  7. fclose($f);
  8. resize($filejpg);
  9. print "zaladowano";
  10.  
  11. }
  12. ?>


Ten post edytował motor 12.09.2006, 10:23:19
Go to the top of the page
+Quote Post
Spirit86
post 12.09.2006, 10:24:43
Post #5





Grupa: Zarejestrowani
Postów: 607
Pomógł: 23
Dołączył: 8.09.2004
Skąd: Wrocław

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


spróbuj stworzyć nowy obrazek poprzez imagecopy


Cytat
bool imagecopy ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h )


Ten post edytował Spirit86 12.09.2006, 10:27:20


--------------------
Audio: Metallica, Soil, RHCP, OffSpring, Green Day, "Retro", Gorillaz, Disturbed, Coma
DB: MySQL 4.1 | php: 4.4.3 Pomogłem Ci? Wciśnij przycisk POMÓGŁ.
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: 24.07.2025 - 19:06