Can I create 'crop' image from sketchup view?

Hey, I am searching a way to crop rectangle image from view.
For example for points:
p_start = [400, 400]
p_end = [1000,800]

I want to take only that part of image.
Something like only red rectangle.

I thought about catching whole screen by write_image method from view Class: Sketchup::View — SketchUp Ruby API Documentation and crop image from result.
but only way I found to do this is to install ImageMagick, but I want to make the plugin, so every user should installed it ;/

Second way that I am considering is to move camera and shot the picture, but this is little more problematic :wink:

Any help?

Other user may have already installed this: :wink:

You can also reload the image file back into SketchUp using the ImageRep class, then extract the cropped data into a new ImageRep object (or perhaps set the data of the current imagerep to the cropped data.)

1 Like

oh, didn’t know about this class.

I managed to get jpg binary string. Complex to edit, but looks promising.

In the meantime I found one library ‘chunky_png’ which does the job in pure ruby. Unfortunately it is slow, but it is working :slight_smile:

1 Like

The pixel data is encoded as an ASCII-8 bit String. You will likely need to unpack this data into an array.

See: packed_data - Documentation for Ruby 3.2 (

EDIT: Oh, I see that there is a #colors method that returns an array of the pixel colors, so probably no need to unpack yourself.