Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] Przycinanie obrazka
Forum PHP.pl > Forum > Przedszkole
motor
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 ?
mdco
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?
Spirit86
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
motor
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. ?>
Spirit86
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 )
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.