imforger 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +10 -0
- data/README.txt +53 -0
- data/Rakefile +32 -0
- data/ext/imforger/extconf.rb +9 -0
- data/ext/imforger/imforger.c +62 -0
- data/lib/imforger.rb +20 -0
- data/test/helper.rb +4 -0
- data/test/test_imforger.rb +9 -0
- data.tar.gz.sig +1 -0
- metadata +111 -0
- metadata.gz.sig +0 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= imforger
|
2
|
+
|
3
|
+
== DESCRIPTION:
|
4
|
+
|
5
|
+
Imforger relies on the Imlib2 library to quickly convert between different file types, scaling and compressing on the way.
|
6
|
+
|
7
|
+
== FEATURES/PROBLEMS:
|
8
|
+
|
9
|
+
As far as I know, this gem only works on Linux and Ruby 1.9+
|
10
|
+
|
11
|
+
Imlib2 drops the ICC profile and XMP tags when it creates the new image. I have been using exiftool to copy the ICC profile and XMP tags over. This is still much faster than ImageMagick et al.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
require 'imforger'
|
16
|
+
Imforger.new(input_file_path).to_file(output_file_path)
|
17
|
+
|
18
|
+
== REQUIREMENTS:
|
19
|
+
|
20
|
+
Imlib2
|
21
|
+
|
22
|
+
== INSTALL:
|
23
|
+
|
24
|
+
gem install imforger
|
25
|
+
|
26
|
+
== SPEED:
|
27
|
+
|
28
|
+
ImageMagick was too slow and used too much memory. [I didn't even bother frobnicating with RMagick.] I also compared to the NetPBM library for good measure.
|
29
|
+
|
30
|
+
== LICENSE:
|
31
|
+
|
32
|
+
(The MIT License)
|
33
|
+
|
34
|
+
Copyright (c) 2011 FIX
|
35
|
+
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
37
|
+
a copy of this software and associated documentation files (the
|
38
|
+
'Software'), to deal in the Software without restriction, including
|
39
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
40
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
41
|
+
permit persons to whom the Software is furnished to do so, subject to
|
42
|
+
the following conditions:
|
43
|
+
|
44
|
+
The above copyright notice and this permission notice shall be
|
45
|
+
included in all copies or substantial portions of the Software.
|
46
|
+
|
47
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
48
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
49
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
50
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
51
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
52
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
53
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
|
4
|
+
class Hoe
|
5
|
+
remove_const :RUBY_FLAGS
|
6
|
+
RUBY_FLAGS = "-I#{%w(lib ext test).join(File::PATH_SEPARATOR)}"
|
7
|
+
end
|
8
|
+
|
9
|
+
gem 'rake-compiler', '>= 0.4.1'
|
10
|
+
require "rake/extensiontask"
|
11
|
+
|
12
|
+
Hoe.plugin :git, :doofus, :gemcutter
|
13
|
+
|
14
|
+
Hoe.spec 'imforger' do
|
15
|
+
developer 'Casey Rosenthal', 'clr@port49.com'
|
16
|
+
|
17
|
+
self.history_file = 'History.txt'
|
18
|
+
self.readme_file = 'README.txt'
|
19
|
+
self.testlib = :minitest
|
20
|
+
|
21
|
+
extra_dev_deps << ['rake-compiler', '>= 0.4.1']
|
22
|
+
|
23
|
+
self.spec_extras = {:extensions => ['ext/imforger/extconf.rb']}
|
24
|
+
|
25
|
+
Rake::ExtensionTask.new "imforger", spec do |ext|
|
26
|
+
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Hoe.add_include_dirs('.:lib')
|
31
|
+
|
32
|
+
task :test => :compile
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
raise "This Ruby gem requires the Imlib2 library to do the hard work. You might install it with `yum install imlib2 imlib2-devel` or some such." unless have_library('Imlib2')
|
4
|
+
|
5
|
+
%w(freetype X11 Xext).each do |lib|
|
6
|
+
raise "Library #{lib} not found." unless have_library(lib)
|
7
|
+
end
|
8
|
+
|
9
|
+
create_makefile('imforger')
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/* sprintf include */
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <string.h>
|
5
|
+
|
6
|
+
/* for access() */
|
7
|
+
#include <unistd.h>
|
8
|
+
/* include Imlib2 stuff */
|
9
|
+
#include <Imlib2.h>
|
10
|
+
/* ruby */
|
11
|
+
#include <ruby.h>
|
12
|
+
|
13
|
+
static VALUE imforger_save_file(VALUE self, VALUE anObject)
|
14
|
+
{
|
15
|
+
VALUE input_image;
|
16
|
+
VALUE output_image;
|
17
|
+
char *imagePath1;
|
18
|
+
char *imagePath2;
|
19
|
+
/* image handles */
|
20
|
+
Imlib_Image image1;
|
21
|
+
Imlib_Image image2;
|
22
|
+
|
23
|
+
input_image = rb_iv_get(self, "@input_image");
|
24
|
+
output_image = rb_iv_set(self, "@output_image", anObject);
|
25
|
+
|
26
|
+
imagePath1 = StringValuePtr(input_image);
|
27
|
+
imagePath2 = StringValuePtr(output_image);
|
28
|
+
|
29
|
+
/* check that the file exists and can be read */
|
30
|
+
/* TODO: raise a real error */
|
31
|
+
if(access(imagePath1, R_OK) == -1){
|
32
|
+
return rb_str_new2(strcat(imagePath1, ": File cannot be found."));
|
33
|
+
}
|
34
|
+
|
35
|
+
/* load the image1 */
|
36
|
+
image1 = imlib_load_image(imagePath1);
|
37
|
+
/* if the load was successful */
|
38
|
+
if (image1)
|
39
|
+
{
|
40
|
+
char *tmp;
|
41
|
+
/* set the image1 we loaded as the current context image1 to work on */
|
42
|
+
imlib_context_set_image(image1);
|
43
|
+
/* set the image1 format to be the format of the extension of our last */
|
44
|
+
/* argument - i.e. .png = png, .tif = tiff etc. */
|
45
|
+
tmp = strrchr(imagePath2, '.');
|
46
|
+
if(tmp)
|
47
|
+
imlib_context_set_anti_alias(1);
|
48
|
+
image2 = imlib_create_cropped_scaled_image(0,0,imlib_image_get_width(),imlib_image_get_height(),100,100);
|
49
|
+
imlib_context_set_image(image2);
|
50
|
+
imlib_image_set_format(tmp + 1);
|
51
|
+
/* save the image1 */
|
52
|
+
imlib_save_image(imagePath2);
|
53
|
+
}
|
54
|
+
return Qtrue;
|
55
|
+
}
|
56
|
+
|
57
|
+
VALUE cImforger;
|
58
|
+
|
59
|
+
void Init_imforger() {
|
60
|
+
cImforger = rb_define_class("Imforger", rb_cObject);
|
61
|
+
rb_define_private_method(cImforger, "save_file", imforger_save_file, 1);
|
62
|
+
}
|
data/lib/imforger.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'imforger.so'
|
2
|
+
|
3
|
+
class Imforger
|
4
|
+
VERSION = '0.1.1'
|
5
|
+
|
6
|
+
attr_accessor :input_image, :output_image
|
7
|
+
|
8
|
+
class Exception < RuntimeError; end
|
9
|
+
|
10
|
+
def initialize(path)
|
11
|
+
path = File.expand_path(path)
|
12
|
+
|
13
|
+
raise(Imforger::Exception, "Input file not found!") unless File.exists?(path)
|
14
|
+
@input_image = path
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_file(output_path)
|
18
|
+
save_file(File.expand_path(output_path))
|
19
|
+
end
|
20
|
+
end
|
data/test/helper.rb
ADDED
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
a��x$/�E���36���dU�^�<g����Gp�Nb��#�I�c`��Dn��<'È
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imforger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Casey Rosenthal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- |
|
13
|
+
-----BEGIN CERTIFICATE-----
|
14
|
+
MIIDKjCCAhKgAwIBAgIBADANBgkqhkiG9w0BAQUFADA7MQwwCgYDVQQDDANjbHIx
|
15
|
+
FjAUBgoJkiaJk/IsZAEZFgZwb3J0NDkxEzARBgoJkiaJk/IsZAEZFgNjb20wHhcN
|
16
|
+
MTEwMzI1MjIyNTA2WhcNMTIwMzI0MjIyNTA2WjA7MQwwCgYDVQQDDANjbHIxFjAU
|
17
|
+
BgoJkiaJk/IsZAEZFgZwb3J0NDkxEzARBgoJkiaJk/IsZAEZFgNjb20wggEiMA0G
|
18
|
+
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDFO65jA8Vm6mrySAEh0p9zMJ/c8pif
|
19
|
+
AwrL8K/fQzBOD8WjaHbt3WlDut4tBtzBpspaObbszg0QhH8ixvdIteaNaqWt5ivB
|
20
|
+
85BPy2NV/yBBhKZ3JshlivgcKr6RRwP/NfwVVWXMBCmX6d1/9hicHES7gLP61RLY
|
21
|
+
a13gfyuVSm1FipnzIWrgj1ArEQvLc5Qzp08ekolU3xvTQaItDPCh2ImaCixhlFaV
|
22
|
+
SZxGk2HEv5sdK2HiZfdN4P8dVBhWEK+HXh4WuyqivGI0mHioQNrAU2VSka0NN/dZ
|
23
|
+
NysVmj3E+P3EQaSJ1Apey6WVgozw/Jd2tRrcPp4bvNTcMcstXxDDdajLAgMBAAGj
|
24
|
+
OTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFJGwO8OOOSuETTTIgEHrFaPYZY50MAsG
|
25
|
+
A1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEAFZq0kRxt5VII27uV/lReyzAz
|
26
|
+
q5MWDtOv8hgUcF6DqsR8vMwYUtbl8CpKerY7CCdq8SBgI73gTSg0FlKhu/TWJyVS
|
27
|
+
vbD8qTsLMSJ1eagrRzY0W/hbl07CdFAunPKYw9vIOsQXBDLPoJoPogpSkbTGaUnD
|
28
|
+
NqVRcPwXgmwCdlJYOOBXh6QxArisZ/dFNtVZY2zUJCfdxpUwlXEtNvh9z+502nWp
|
29
|
+
B5PckRdTFq05psR5w5RInK0QZstX464GDSUs+CL7JvwXJKtnDGLb4/+xY3j5a/f6
|
30
|
+
ZZgY9wEKsxYB1Clu7uMdVBMb1hI4Kr/k6wDqXfpoZW9ltiyjmmgWvWAfPEsgSg==
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
|
33
|
+
date: 2011-03-25 00:00:00 -07:00
|
34
|
+
default_executable:
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake-compiler
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.4.1
|
45
|
+
type: :development
|
46
|
+
version_requirements: *id001
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: hoe
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.9.1
|
56
|
+
type: :development
|
57
|
+
version_requirements: *id002
|
58
|
+
description: Imforger relies on the Imlib2 library to quickly convert between different file types, scaling and compressing on the way.
|
59
|
+
email:
|
60
|
+
- clr@port49.com
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions:
|
64
|
+
- ext/imforger/extconf.rb
|
65
|
+
extra_rdoc_files:
|
66
|
+
- History.txt
|
67
|
+
- Manifest.txt
|
68
|
+
- README.txt
|
69
|
+
files:
|
70
|
+
- .autotest
|
71
|
+
- History.txt
|
72
|
+
- Manifest.txt
|
73
|
+
- README.txt
|
74
|
+
- Rakefile
|
75
|
+
- ext/imforger/extconf.rb
|
76
|
+
- ext/imforger/imforger.c
|
77
|
+
- lib/imforger.rb
|
78
|
+
- test/helper.rb
|
79
|
+
- test/test_imforger.rb
|
80
|
+
- .gemtest
|
81
|
+
has_rdoc: true
|
82
|
+
homepage:
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options:
|
87
|
+
- --main
|
88
|
+
- README.txt
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project: imforger
|
106
|
+
rubygems_version: 1.6.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Imforger relies on the Imlib2 library to quickly convert between different file types, scaling and compressing on the way.
|
110
|
+
test_files:
|
111
|
+
- test/test_imforger.rb
|
metadata.gz.sig
ADDED
Binary file
|