# RMagick exporting pixels as string

**URL:** <https://www.ruby-forum.com/t/rmagick-exporting-pixels-as-string/51814>\
**Category:** Ruby\
**Created:** [January 7, 2006, 11:08am UTC](https://www.ruby-forum.com/t/rmagick-exporting-pixels-as-string/51814 "2006-01-07T11:08:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilmari\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a587f6/32.png) [@Ilmari\_H](https://www.ruby-forum.com/u/Ilmari_H)\
**Post date:** [January 7, 2006, 11:08am UTC](https://www.ruby-forum.com/t/rmagick-exporting-pixels-as-string/51814/1 "2006-01-07T11:08:27Z")

</div>

Hi,

I’m exporting pixels to an OpenGL texture from Magick::Image  
using export\_pixels.

The problem is that it’s slow.  
5.5 seconds for a 330x370 image -slow.

Is there a faster way to do this:

image.export\_pixels(0,0, cols, rows, “BGRA”).pack(“c\*”)

Thanks in advance,  
Ilmari

---

<div class="post-metadata">

**Author:** ![Ilmari\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a587f6/32.png) [@Ilmari\_H](https://www.ruby-forum.com/u/Ilmari_H)\
**Post date:** [January 7, 2006, 11:29am UTC](https://www.ruby-forum.com/t/rmagick-exporting-pixels-as-string/51814/2 "2006-01-07T11:29:29Z")

</div>

On 1/7/06, Ilmari H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> image.export\_pixels(0,0, cols, rows, “BGRA”).pack(“c\*”)  
> Did some more timing and pinpointed the problem:  
> export-bgra: 0.557612  
> pack: 4.761164

export\_pixels isn’t quite the speed demon, but pack’s  
the real problem.

---

<div class="post-metadata">

**Author:** ![Ilmari\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a587f6/32.png) [@Ilmari\_H](https://www.ruby-forum.com/u/Ilmari_H)\
**Post date:** [January 7, 2006, 12:51pm UTC](https://www.ruby-forum.com/t/rmagick-exporting-pixels-as-string/51814/3 "2006-01-07T12:51:25Z")

</div>

Am Samstag, den 07.01.2006, 19:29 +0900 schrieb Ilmari H.:

> > image.export\_pixels(0,0, cols, rows, “BGRA”).pack(“c\*”)
> 
> Did some more timing and pinpointed the problem:  
> export-bgra: 0.557612  
> pack: 4.761164
> 
> export\_pixels isn’t quite the speed demon, but pack’s  
> the real problem.

Hi,

try image.to\_blob, that will return the image data as a string.

Cheer  
detlef

---

<div class="post-metadata">

**Author:** ![Ilmari\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a587f6/32.png) [@Ilmari\_H](https://www.ruby-forum.com/u/Ilmari_H)\
**Post date:** [January 7, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/rmagick-exporting-pixels-as-string/51814/4 "2006-01-07T15:05:19Z")

</div>

On 1/7/06, Detlef R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Is there a faster way to do this:
> 
> Hi,
> 
> try image.to\_blob, that will return the image data as a string.
> 
> Cheer  
> detlef

Thank you so much, that did the trick.

Now it’s taking just 0.16s to get the pixels. Also, the image was  
actually 1000x1000 pixels, brainfart on my side.  
(As a sidenote, Imlib2’s doing the same in 0.016s.)
