# Core Image, Where Art Thou?

**URL:** <https://www.ruby-forum.com/t/core-image-where-art-thou/181687>\
**Category:** Ruby\
**Created:** [January 16, 2010, 2:27am UTC](https://www.ruby-forum.com/t/core-image-where-art-thou/181687 "2010-01-16T02:27:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spencer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8dc957/32.png) [@spencer](https://www.ruby-forum.com/u/spencer)\
**Post date:** [January 16, 2010, 2:27am UTC](https://www.ruby-forum.com/t/core-image-where-art-thou/181687/1 "2010-01-16T02:27:51Z")

</div>

Lately, I’ve been developing some image editing functions for my rails  
app using RubyCocoa and Core Image. With my novice understanding of  
objective-c and the lack of examples for Core Image, much less Core  
Image through RubyCocoa, I’ve had a pretty rough time. The lack of  
documentation is rather surprising given the power of Apple’s Core Image  
suite, and the people that swear by it.

Perhaps I’ve been looking in all the wrong places? All I’ve been able  
to find is Apple’s Core Image Reference Library, a few examples on Red  
Artisan’s blog, and an image manipulation class built for python. It  
seems as though the people clever enough, or the people with enough time  
to figure out Apple’s Core Image technology and syntax guard their  
knowledge closely and only let it out for a price via an app they have  
created.

Does anyone here have experience using Core Image in Ruby? I’d really  
appreciate any help you could give me, even if it’s just directing me to  
another forum or hopefully some tutorials or examples. I really have a  
lot to learn about Core Image and the syntax/methodology behind it.

As for where I’m at now, I’ve managed to build a few functions to  
convert and resize images but cannot seem to figure out the correct  
syntax to rotate an image. Perhaps someone can help me figure this out.

As reference, this is the code I’ve used to resize an image - a mini  
guide to syntax heh.

newImage = self.image  
create\_core\_image\_context(newWidth, newHeight)  
scale\_x, scale\_y = scale(newWidth, newHeight)

newImage.affine\_clamp :inputTransform =\>  
OSX::NSAffineTransform.transform do |clamped|  
clamped.lanczos\_scale\_transform :inputScale =\> scale\_x \> scale\_y ?  
scale\_x : scale\_y, :inputAspectRatio =\> scale\_x / scale\_y do |scaled|  
scaled.crop :inputRectangle =\> vector(0, 0, newWidth, newHeight)  
do |cropped|  
newImage = cropped  
end # crop  
end # scale  
end # clamped

For rotating an image, I’ve tried various combinations but nothing seems  
to work.

newImage.transform :inputTransform =\>  
OSX::NSAffineTransform.transform.rotateByDegrees(degrees) do |rotated|  
newImage = rotated  
end # rotated

or even using the affine clamp…

newImage.affine\_clamp :inputTransform =\>  
OSX::NSAffineTransform.transform do |clamped|  
clamped.rotateByDegrees :inputAngle =\> degrees do |rotated|  
newImage = rotated  
end # rotated  
end # clamped

Thanks in advance for any help you all can give me!
