Browse Source

- Version 1.0
- Added LICENSE
- Added README.md

zombiez 8 years ago
parent
commit
4f209fb3d5
5 changed files with 100 additions and 1 deletions
  1. 73 0
      IMGresizer
  2. 1 1
      LICENSE
  3. 10 0
      README.md
  4. 7 0
      nbproject/project.properties
  5. 9 0
      nbproject/project.xml

+ 73 - 0
IMGresizer

@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+
+use Image::Resize;
+use File::Basename;
+
+if (! $ARGV[0]) {
+   print "\n\n";
+   print "Invalid argument[1], source file is required!";
+   print "\n";
+   exit 1;
+}
+
+if (! $ARGV[1]) {
+   print "\n\n";
+   print "Invalid argument[2], 'width' is required!";
+   print "\n";
+   exit 1;
+}
+
+if (! $ARGV[2]) {
+   print "\n\n";
+   print "Invalid argument[3], 'height' is required!";
+   print "\n";
+   exit 1;
+}
+
+my $sourceFile = $ARGV[0];
+
+print "Source file: \'", $sourceFile, "\'\n";
+
+if (! -f $sourceFile) {
+   print "\n\n";
+   print "Source file doesn't exist!";
+   print "\n";
+   exit 1;
+}
+
+my $destFile = $sourceFile;
+
+my @exts = qw (.jpeg .jpg .png .gif); 
+my ($name, $path, $ext) = fileparse($sourceFile, @exts);
+$ext = lc($ext);
+
+print "File type: \'", $ext, "\'\n";
+
+$Image = Image::Resize->new($sourceFile);
+
+if ($Image->width > $Image->height) {
+  $newWidth = $ARGV[1];
+  $newHeight = int($Image->height / ($Image->width() / $newWidth));
+} else {
+  $newHeight = $ARGV[2];
+  $newWidth = int($Image->width / ($Image->height() / $newHeight));
+}
+print "Resizing to ", $newWidth, "x",  $newHeight, "px\n";
+
+$gd = $Image->resize($newWidth, $newHeight);
+open(FH, '>' . $destFile);
+
+if ($ext eq ".jpg" || $ext eq ".jpeg") {
+  print "Writing jpeg output\n";
+  print FH $gd->jpeg();
+} elsif ($ext eq ".png") {
+  print "Writing png output\n";
+  print FH $gd->png(0);
+} elsif ($ext eq ".gif") {
+  print "Writing gif output\n";
+  print FH $gd->gif();
+}
+
+close(FH);
+
+exit 0;

+ 1 - 1
LICENSE

@@ -1,6 +1,6 @@
 BSD 3-Clause License
 
-Copyright (c) 2017, Daniele Bonini
+Copyright (c) 2016, 2017, the Open Gallery's contributors
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without

+ 10 - 0
README.md

@@ -0,0 +1,10 @@
+# IMGresizer
+A (CGI/Perl) image resizer  
+
+##Usage
+       perl IMGresizer /path/to/image.png 1600 1200
+
+##Note
+  IMGresizer works with png, jpg/jpeg, gif and more  
+       
+

+ 7 - 0
nbproject/project.properties

@@ -0,0 +1,7 @@
+include.path=${php.global.include.path}
+php.version=PHP_56
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=false
+web.root=.

+ 9 - 0
nbproject/project.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+    <type>org.netbeans.modules.php.project</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/php-project/1">
+            <name>IMGresizer</name>
+        </data>
+    </configuration>
+</project>