Złożyłem funkcję, która ma zmienić rozmiar zdjęcia $src_file na określoną szerokość $dst_width albo wysokość $dst_height i zapisać jako plik $dst_file.
<?php function resizeJPEG( $src_file, $dst_file, $dst_width=false, $dst_height=false ) { # one or both of dst_width or dst_height must be int if( !$dst_width && !$dst_height ) switch ( $type ) { case 1: $src_img = @ImageCreateFromGIF($src_file); break; case 2: $src_img = @ImageCreateFromJPEG($src_file); break; case 3: $src_img = @ImageCreateFromPNG($src_file); break; default: return false; } if( !$src_img ) return false; $src_width = imagesx($src_img); $src_height = imagesy($src_img); if( $src_width <= $dst_width && $src_height <= $dst_height ) { # src img is smaller than wanted dimensions $success = imageJPEG( $src_img, $dst_file ); } else { # resize image if( $dst_width !== false && $dst_height === false ) { # only specified dst_width, calculate dst_height $dst_height = (int) ( $src_height / $proportion ); } elseif( $dst_width === false && $dst_height !== false ) { # only dst_height specified, calculate dst_width $dst_width = (int) ( $src_width / $proportion ); } $new_img = imagecreatetruecolor( $dst_width, $dst_height ); imagecopyresampled( $new_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height ); $success = imageJPEG( $new_img, $dst_file ); } # clean up imagedestroy( $new_img ); imagedestroy( $src_img ); return $success; } ?>
Mówiąc najkrócej: nie działa. W php nie jestem zbyt biegły, ale zastosowałem starą dobrą metodę wstawiania "znaczników" wewnątrz kodu, aby sprawdzić co szwankuje. W oknie przeglądarki pojawia się wyłącznie pierwszy ("FAFARAFA") znacznik. Reszty nie ma. Dziwi mnie to, bo wydaje mi się, że albo powinny zostać wypisane, albo funkcja powinna się wywalić.
Co z tym zrobic? Macie jakis pomysł?
