Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_GET['src'])){
- $image = imagecreatefromjpeg($_GET['src']);
- $filename = 'anotherimagem.jpg';
- // Largura e altura desejada do thumbnail
- $thumb_width = 200;
- $thumb_height = 150;
- // Largura e altura da imagem em upload
- $width = imagesx($image);
- $height = imagesy($image);
- // Caluclos Matemáticos
- $original_aspect = $width / $height;
- $thumb_aspect = $thumb_width / $thumb_height;
- if ($original_aspect >= $thumb_aspect) {
- // If image is wider than thumbnail (in aspect ratio sense)
- $new_height = $thumb_height;
- $new_width = $width / ($height / $thumb_height);
- } else {
- // If the thumbnail is wider than the image
- $new_width = $thumb_width;
- $new_height = $height / ($width / $thumb_width);
- }
- $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
- // Redimensionando e recortando
- imagecopyresampled($thumb,
- $image,
- 0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
- 0 - ($new_height - $thumb_height) / 2, // Center the image vertically
- 0, 0, $new_width, $new_height, $width, $height);
- // Definindo a qualidade da foto
- imagejpeg($thumb, $filename, 80);
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Upload de imagens</title>
- </head>
- <body>
- <form method="GET" enctype="multipart/form-data">
- <input type="file" name="src" />
- <input type="submit" name="submit" value="Upload" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement