code
2016
2015
Things I did randomly last week
git unhg
2013
Code Tidbits: wrk pt.1
I have this plan to do some write up series related to programming and such, mostly as another form of practicing C systems programming. Just when I wondered about what topic I should write, I found this gem written by Will Glozer. So I think I can study the source code and write some little explanation here and there about the code, hence the tidbits. Feel free to critic and correct things if you find mistakes on this. It would be my honour.
I kinda like the source code for its simplicity and learn a lot from them. The library used from redis including zmalloc
and ae
. I will going into zmalloc, before that, lets see this aprintf
first.
The Hook
2012
imgpop
Now I will going into technical details inside imgpop.
Like I said in the previous post. I extends Brian’s imgpopup and do some makeup to things.
At the backend, I use mini_magick
to actually save the resized image, and use that as preview/thumbnail.
Here’s the snippet.
#...#
# Open the source image, and scale it accordingly.
image = MiniMagick::Image.open(image_path)
vars['full_width'] = image[:width]
vars['full_height'] = image[:height]
image.resize "#{@percent}%"
rpath = source+ resized_image
if not File.exists? rpath
# Actually save the image
image.format "jpg"
image.quality "92"
image.write rpath
# This is the tricky part
# we should register the new created file
# since Jekyll already indexed all files before
context.registers[:site].static_files << StaticFile.new(
context.registers[:site], source, File.dirname(@path.sub(%r{^/}, '')),
"resized_#{File.basename(@path)}")
print "image saved to #{rpath}\n"
end
#...#