Hallo! Selamat Datang di Marketplace produk digital, Freelancer terbaik di indonesia (67424 Members, 783 Products, 5279 Topic, 12953 Comments)

Gambar Berita Swarakalibata V.3.3 agar otomatis beresolusi 600x400 px

Dibuat
Login Terakhir 4 Bulan lalu,
Telah Dilihat 1431 Kali
Raihan Al Karim Mengatakan : Sultan Account
  1. Bagaimana cara agar foto berita yang dimasukkan otomatis beresolusi 600x400 px min ? Mohon bantuannya

Ada 1 Jawaban

PHPMU.COM Support
commented on 22 Mar 2017 20:32:45
  1. Assalam, ini saya kasih contoh kode untuk crop image jadi 600x400px nya mas,..
  2. silahkan digabungkan ke swarakalibatanya,.. :)
  3.  
  4. <html>
  5. <head>
  6. <title>Upload Image Dan Potong</title>
  7. </head>
  8. <body>
  9. <form action="" method="post" enctype="multipart/form-data">
  10. Pilih Gambar: <input type="file" name="image" id="fileToUpload">
  11. <input type="submit" value="Upload Image" name="submit">
  12. </form>
  13. </body>
  14. </html><hr>
  15.  
  16. <?php
  17. if (isset($_POST['submit'])){
  18. $image = $_FILES;
  19. $NewImageName = rand(4,10000)."-". $image['image']['name'];
  20. $destination = realpath('images').'/';
  21. move_uploaded_file($image['image']['tmp_name'], $destination.$NewImageName);
  22. $image = imagecreatefromjpeg($destination.$NewImageName);
  23. $filename = $destination.$NewImageName;
  24.  
  25. $thumb_width = 600;
  26. $thumb_height = 400;
  27.  
  28. $width = imagesx($image);
  29. $height = imagesy($image);
  30. $original_aspect = $width / $height;
  31. $thumb_aspect = $thumb_width / $thumb_height;
  32.  
  33. if ( $original_aspect >= $thumb_aspect){
  34. // If image is wider than thumbnail (in aspect ratio sense)
  35. $new_height = $thumb_height;
  36. $new_width = $width / ($height / $thumb_height);
  37. }else{
  38. // If the thumbnail is wider than the image
  39. $new_width = $thumb_width;
  40. $new_height = $height / ($width / $thumb_width);
  41. }
  42.  
  43. $thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
  44. // Resize and crop
  45. $image,
  46. 0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
  47. 0 - ($new_height - $thumb_height) / 2, // Center the image vertically
  48. 0, 0,
  49. $new_width, $new_height,
  50. $width, $height);
  51. imagejpeg($thumb, $filename, 80);
  52. echo "Pemotongan Selesai!"; die;
  53. }
  54. ?>
  55.  
  56. #Source : http://stackoverflow.com/questions/1855996/crop-image-in-php
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!