Advertisement
swaggboi

FUUUUUUUUCK

Feb 14th, 2025
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.43 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. #
  3. # Nom :    upload_galerie_multi.plx
  4. # But :      Galerie(s) photo(s) programme pour uploader
  5. # Ecrit par :   Marc GREEN
  6. # Date création : 20/02/2007  Version : 0.1
  7. # Génération de la page (élémmentaire) par CGI
  8. # Version/revision :
  9. #
  10. # use Carp;
  11. use CGI qw/:standard/;
  12.  
  13. #
  14. # The purpose of the pragma is to prohibit unsafe use of variables, symbolic
  15. #   references and barewords
  16. # Before using a variable you'll need to declare it using  "my" keyword
  17. use strict;
  18.  
  19. #
  20. # Pour utilisation de imagemagick
  21. #
  22. use Image::Magick;
  23. # use Image::Info qw(image_info);
  24.  
  25. my $image_tmp;
  26. my $status;
  27. my $width;
  28. my $height;
  29. my $size;
  30. my $format;
  31. my $x_scale;
  32. my $x_size;
  33. my $y_scale;
  34. my $y_size;
  35. my $scale;
  36. my $new_x;
  37. my $new_y;
  38. my @filters;
  39. my $filter;
  40. my $blur;
  41.  
  42. $x_size = 100;
  43. $y_size = 150;
  44. my $image;
  45. my $entry;
  46. my @photos_disponibles;
  47. # my %galeries_disponibles;
  48. my $photo_a_reduire;
  49. my $photo_in;
  50. my $photo_out;
  51. my $geometry;   # Pour redimensionnement des images
  52.  
  53. $image_tmp = Image::Magick->new();
  54.  
  55. @photos_disponibles = qx{ls *.jpg};
  56. chomp @photos_disponibles;
  57.  
  58. @filters = qw{Point Box  Hermite Hanning Hamming Blackman Gaussian Triangle   Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc};
  59.  
  60. foreach ( @photos_disponibles ) {  
  61. # For every picture in the list apply all possible filters
  62.    foreach $filter (@filters){
  63.         print "Traitement de $_\n";
  64.         $image_tmp = Image::Magick->new();
  65.         $status = $image_tmp->Read($_);
  66.         if ( $status ) {
  67.             print "Erreur de lecture : $status \n";
  68.         }
  69.         ($width, $height, $size, $format) =
  70.                 $image_tmp->Ping("$_");
  71.         $x_scale = $x_size / $width;
  72.         $y_scale = $y_size / $height;
  73.         $scale = $x_scale;
  74.         if ( $y_scale < $scale ) {
  75.             $scale = $y_scale;
  76.         }
  77.         $new_x = int( $width * $scale + 0.5 );
  78.         $new_y = int( $height * $scale + 0.5 );
  79. # Here I make a thumbnail image (and it is sharp after writing to file)
  80.         $status = $image_tmp->Scale( width=>$new_x, height=>$new_y);
  81.         if ( $status ) {
  82.             print "Apres_reduction : $status <br>\n";
  83.         };
  84.         print "\tEcriture de mini_$_\n";
  85.         $status = $image_tmp->Write("mini_$_");
  86.         if ( $status ) {
  87.             print "Apres_enregistrement : $status <br>\n";
  88.         }
  89. # Getting the image information change the size depending if the image is horizontal or vertical
  90.         if ( $width > $height ) {
  91.             $geometry="640x480";
  92.         }
  93.         else {
  94.             $geometry="480x640";  
  95.         }
  96.         # For every image with every filter try different "blur" values
  97.         for  ($blur = 0.125; $blur <=4; $blur *= 2 ){
  98.             $status = $image_tmp->Resize(geometry=>$geometry,filter=>$filter,blur=>$blur);
  99.             if ( $status ) {
  100.                 print "Apres_reduction : $status <br>\n";
  101.             };
  102.             print "\tEcriture de mid_".$filter."_".$blur."_$_\n";
  103.             $status = $image_tmp->Write("mid_".$filter."_".$blur."_$_");
  104.             if ( $status ) {
  105.                 print "Apres_enregistrement : $status <br>\n";
  106.             }
  107. # Here none of the resize images are sharp ==> unusable.
  108.         }      
  109.    }
  110.     ($photo_a_reduire = $_ ) =~ s/ /\ /g;
  111.     print "Redution de $photo_a_reduire\n";
  112.     `convert $photo_a_reduire -resize 640x480 converted_$photo_a_reduire`;
  113. # This one gives a great quality image.
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement