File tree Expand file tree Collapse file tree 10 files changed +123
-0
lines changed
examples/image_processing Expand file tree Collapse file tree 10 files changed +123
-0
lines changed Original file line number Diff line number Diff line change 1+ bundle /
2+ .bundle /
3+ func.yaml
4+ Gemfile.lock
5+ * .png
Original file line number Diff line number Diff line change 1+ FROM iron/ruby:dev
2+ RUN apk --no-cache --update add imagemagick
3+
4+ COPY ./ /func
5+ WORKDIR /func
6+
7+ RUN gem install bundler --no-ri --no-rdoc
8+ RUN bundle
9+
10+ ENTRYPOINT bundle exec ruby func.rb
Original file line number Diff line number Diff line change 1+ source 'https://rubygems.org'
2+
3+ gem 'json'
4+ gem 'mini_magick'
Original file line number Diff line number Diff line change 1+ ## Image processing with Ruby Example
2+
3+ This example will show you how to process images with a Ruby function.
4+
5+ ``` sh
6+ # create your func.yaml file
7+ fn init < YOUR_DOCKERHUB_USERNAME> /image-processing
8+
9+ # build the function
10+ fn build
11+
12+ # test it
13+ echo " http://www.sourcecertain.com/img/Example.png" | fn run > image.png
14+
15+ # push it to Docker Hub
16+ fn push
17+
18+ # Create a route to this function on IronFunctions (assuming you have an app called `test`)
19+ fn routes create test /image-processing
20+
21+ # you can now access via curl as well
22+ curl -v -X POST http://localhost:8080/r/test/image-processing -d " http://www.sourcecertain.com/img/Example.png" > image.png
23+ ```
24+
Original file line number Diff line number Diff line change 1+ require 'mini_magick'
2+
3+ payload = STDIN . read . strip
4+ image = MiniMagick ::Image . open ( payload )
5+ image . contrast
6+ image . resize "250x200"
7+ image . rotate "-90"
8+ image . write STDOUT
Original file line number Diff line number Diff line change 1+ bundle /
2+ .bundle /
3+ func.yaml
4+ Gemfile.lock
5+ * .png
Original file line number Diff line number Diff line change 1+ FROM iron/ruby:dev
2+ RUN apk --no-cache --update add imagemagick
3+
4+ COPY ./ /func
5+ WORKDIR /func
6+
7+ RUN gem install bundler --no-ri --no-rdoc
8+ RUN bundle
9+
10+ ENV AWS_ACCESS_KEY_ID {add your id here}
11+ ENV AWS_SECRET_ACCESS_KEY {add your key here}
12+ ENV AWS_S3_BUCKET iron-functions-image-resize
13+ ENV AWS_REGION us-east-1
14+
15+ ENTRYPOINT bundle exec ruby func.rb
Original file line number Diff line number Diff line change 1+ source 'https://rubygems.org'
2+
3+ gem 'json'
4+ gem 'mini_magick'
5+ gem 'aws-sdk-s3' , '~> 1'
Original file line number Diff line number Diff line change 1+ ## Image processing with Ruby Example, Upload to S3
2+
3+ This example will show you how to process images with a Ruby function, and upload to a S3 bucket.
4+
5+ ``` sh
6+ # create your func.yaml file
7+ fn init < YOUR_DOCKERHUB_USERNAME> /image-processing
8+
9+ # build the function
10+ fn build
11+
12+ # test it
13+ echo " http://www.sourcecertain.com/img/Example.png" | fn run
14+
15+ # push it to Docker Hub
16+ fn push
17+
18+ # Create a route to this function on IronFunctions (assuming you have an app called `test`)
19+ fn routes create test /image-processing
20+
21+ # you can now access via curl as well
22+ curl -v -X POST http://localhost:8080/r/test/image-processing -d " https://www.nationalgeographic.com/content/dam/science/photos/000/010/1086.ngsversion.1491440409220.adapt.1900.1.jpg"
23+ > https://iron-functions-image-resize.s3.amazonaws.com/1086.ngsversion.1491440409220.adapt.1900.1.jpg
24+ ```
25+
Original file line number Diff line number Diff line change 1+ require 'mini_magick'
2+ require 'aws-sdk-s3'
3+
4+ file_uri = STDIN . read . strip
5+ image = MiniMagick ::Image . open ( file_uri )
6+ image . contrast
7+ image . resize "250x200"
8+ image . rotate "-90"
9+
10+ s3 = Aws ::S3 ::Client . new
11+ bucket = ENV [ 'AWS_S3_BUCKET' ]
12+
13+ obj = s3 . put_object ( bucket : bucket ,
14+ key : File . basename ( file_uri ) ,
15+ body : image . tempfile ,
16+ acl : "public-read" ,
17+ cache_control : "max-age=604800" )
18+
19+ # Unfortunately put_object returns `put object output`, not an object.
20+ # So we create another reference here. Probably there is a better way to do this in S3 API.
21+ obj = Aws ::S3 ::Object . new bucket_name : bucket , key : File . basename ( file_uri )
22+ puts obj . public_url
You can’t perform that action at this time.
0 commit comments