Hello,
as a little real-world case study / ruby quiz let's cut up the
single 24000x24000 punks.png image [1] (about 800 kb)
into 10,000 tiles - that is - 24x24 pixel images.
Any recommendations on what gem to use to read/write png images in ruby?
And how to best cut up the image into tiles?
Any tips & tricks more than welcome. Cheers. Prost.
PS: For some background on CryptoPunks, see the Inside the CryptoPunks
Bubble (Anno 2021) [2] page.
[1] cryptopunks/punks.png at master · larvalabs/cryptopunks · GitHub
[2] GitHub - openblockchains/awesome-cryptopunks-bubble: Awesome CryptoPunks Bubble (Anno 2021) - Modern 24x24 Pixel Crypto Art on the Blockchain since 2017 - 10 000 Unique Collectible Characters Generated Algorithmically ++ Bonus: Inside the CryptoPunksMarket Contract Service
I would recommend Pygame for this. Not a rubygem but it would definitely do
the job.
https://www.pygame.org/docs/ref/image.html
https://www.pygame.org/docs/ref/surface.html
* load the main image into memory
* this creates a "surface" object.
* use Surface.subsurface to create the 24x24 map
* save the subsurface pygame.image.save()
* repeat
Maybe there's a Ruby library out there as well.
···
On Tue, Feb 9, 2021 at 7:12 AM Utkarsh Gupta <utkarsh@debian.org> wrote:
Hello,
On Tue, Feb 9, 2021 at 8:34 PM Gerald Bauer <gerald.bauer@gmail.com> > wrote:
> as a little real-world case study / ruby quiz let's cut up the
> single 24000x24000 punks.png image [1] (about 800 kb)
> into 10,000 tiles - that is - 24x24 pixel images.
> Any recommendations on what gem to use to read/write png images in
ruby?
> And how to best cut up the image into tiles?
Looks like mini_magick[1] for resizing and stuff, followed by
tileup[2] for the latter.
[1]: mini_magick | RubyGems.org | your community gem host
[2]:tileup | RubyGems.org | your community gem host
- u
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
A musician must make music, an artist must paint, a poet must write, if he
is to be ultimately at peace with himself.
- Abraham Maslow
Hello,
Thanks for your tips. The tileup gem is looking good.
Spoiler: Here's my little reference script using the chunky_png gem:
require 'chunky_png'
punks = ChunkyPNG::Image.from_file( './punks.png' )
(0..9999).each do |index|
y, x = index.divmod( 100 ) # 100x100 punks
punk = punks.crop( x*24, y*24, 24, 24 )
name = "punk-" + '%04d' % index + ".png" # e.g.
punk-0000.png, punk-0001.png and so on
punk.save( name )
end
Cheers. Prost.
PS: Find out more about the chunky_png gem that lets you read/write
PNG images [1]
PPS: Here's the million dollar alien punk #2890 in its 24x24 pixel glory [2]
[1] GitHub - wvanbergen/chunky_png: Read/write access to PNG images in pure Ruby.
[2] awesome-cryptopunks-bubble/punk-2890.png at master · openblockchains/awesome-cryptopunks-bubble · GitHub
Hello,
how to do it the other way round, meaning composing one large image?
thank you
Opti
···
Am 10.02.21 um 10:22 schrieb Gerald Bauer:
Hello,
Thanks for your tips. The tileup gem is looking good.
Spoiler: Here's my little reference script using the chunky_png gem:
require 'chunky_png'
punks = ChunkyPNG::Image.from_file( './punks.png' )
(0..9999).each do |index|
y, x = index.divmod( 100 ) # 100x100 punks
punk = punks.crop( x*24, y*24, 24, 24 )
name = "punk-" + '%04d' % index + ".png" # e.g.
punk-0000.png, punk-0001.png and so on
punk.save( name )
end
Cheers. Prost.
PS: Find out more about the chunky_png gem that lets you read/write
PNG images [1]
PPS: Here's the million dollar alien punk #2890 in its 24x24 pixel glory [2]
[1] GitHub - wvanbergen/chunky_png: Read/write access to PNG images in pure Ruby.
[2] awesome-cryptopunks-bubble/i/punk-2890.png at master · cryptopunksnotdead/awesome-cryptopunks-bubble · GitHub
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Hello,
how to do it the other way round, meaning composing one large image?
I am a chunky png newbie. I haven't really tried any form of composing.
Here's the example from the readme [1]:
# Compose images using alpha blending.
avatar = ChunkyPNG::Image.from_file('avatar.png')
badge = ChunkyPNG::Image.from_file('no_ie_badge.png')
avatar.compose!(badge, 10, 10)
avatar.save('composited.png' )
Cheers. Prost.
[1] GitHub - wvanbergen/chunky_png: Read/write access to PNG images in pure Ruby.
I'd probably use RCairo - the Ruby interface to Cairo. I've used it more for drawing code in the past and it's quite good. It's a native gem, so there's that 
Best Regards,
Mohit.
2021-2-11 | 11:29 pm.
···
On 2021-2-9 11:03 pm, Gerald Bauer wrote:
Hello,
as a little real-world case study / ruby quiz let's cut up the
single 24000x24000 punks.png image [1] (about 800 kb)
into 10,000 tiles - that is - 24x24 pixel images.
Any recommendations on what gem to use to read/write png images in ruby?
And how to best cut up the image into tiles?
Any tips & tricks more than welcome. Cheers. Prost.
Quoting Mohit Sindhwani (mo_mail@onghu.com):
I'd probably use RCairo - the Ruby interface to Cairo. I've used it more for
drawing code in the past and it's quite good. It's a native gem, so there's
that 
Just to add another datapoint: whenever I need to do plumbing on
images from Ruby, I use Rmagick:
https://rmagick.github.io/
It is the wrapping to ImageMagick (https://imagemagick.org/). WARNING:
Steep learning curve!! But once you learn, there is pretty little you
cannot do.
Carlo
···
Subject: Re: Q: How do cut up a single 24000x24000 png image into 10, 000 tiles / 24x24 pixel png images with ruby?
Date: Thu 11 Feb 21 11:29:59PM +0800
--
* Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)
Just one observation -- the math is wrong. Having looked at the image, I suspect it's 2400x2400, which does yield 10,000 24x24 images, and not the 1,000,000 that the original dimensions would suggest.
···
On 2021-02-09 10:03, Gerald Bauer wrote:
Hello,
as a little real-world case study / ruby quiz let's cut up the
single 24000x24000 punks.png image [1] (about 800 kb)
into 10,000 tiles - that is - 24x24 pixel images.
Hello,
Just one observation -- the math is wrong. Having looked at the image,
I suspect it's 2400x2400, which does yield 10,000 24x24 images, and not
the 1,000,000 that the original dimensions would suggest.
Yes, you are right. Thanks for the correction - the punks.png that
houses all the 10 000 CryptoPunks is a 2400×2400 pixel composite image
(about 830 kb in size) [1].
Cheers. Prost.
PS: For easy sharing and (re)use - I've put together a new little gem
(and command line tool) for easy cryptopunk minting / cropping called
- surprise, surprise - cryptopunks. [2]
[1] cryptopunks/punks.png at master · larvalabs/cryptopunks · GitHub
[2] https://github.com/rubycoco/blockchain/tree/master/cryptopunks
If you don't want, or need to use a library, then the montage program
from ImageMagick may be the quickest way to do this:
HTH.
···
On the February 10, at 15:18 (+0100), Die Optimisten wrote:
Hello,
how to do it the other way round, meaning composing one large image?
thank you
Opti
--
Arnaud
https://cypr.io