Up till now to put pictures in this blog I have had to:
- go into an image editor to resize the file to suit the blog (about 450-500 pixels wide).
- fire up an sftp program to upload the file to /var/www/PetersBlogger/public/images
-
add a tag such as
to the wilki.
[/images/TheNewPicture.jpg]
It was a bit laborious, especially the SFTP bit which is why I didn't do it very often.
I've now added better support for pictures to PetersBlogger. Here is an example:
if you click on this you should be treated to a larger version of the image, thanks to lightbox a javascript library.
PetersBlogger now supports a database of pictures so I can add a new picture, give it a name and upload it through the administration pages. The code uses the name as a caption under the photo and as alt text. I can use the name directly in my wilki text to choose which pictures to display.
The database of pictures is handled by the attachmentfu rails plugin. This article gives the steps required to get attachmentfu up and running.
The setup automatically handles resizing images to three sizes: thumbnail for listing in my picture admin page, a version that is no more than 500 pixels in either dimension for showing in the blog and a version that is no more than 800x600 for showing zoomed when you click on a picture. Attachmentfu has the sense to keep the aspect ratio correct automatically so I don't have to worry about portrait/landscape. I had to hack the imagescience library that does the resizing as it was hard-wired to save jpegs using JPEG_QUALITYSUPERB mode so the blog-sized images were taking up 150k. I changed this to JPEG_QUALITYAVERAGE and the size dropped to 15k or so, but it was a bit noisy so I've settled on JPEG_QUALITYGOOD and 38k images. You are on broadband?
I was slightly worried about how to change pictures, i.e. to upload a different version of a picture to replace an existing one, since the attachmentfu article I mentioned does not cover this. The answer is to use the exact same view code in the 'edit' page as in the 'new' page. Combined with rails scaffold code it Just Works! It even handles deleting the three old pictures and creating the new files.
My main motivation for doing this was so I can do it on the websites I host for other people and make it easier for them to upload pictures. PetersCMS is still in the planning stages but one problem has been cracked.


