attachment_fu plugin is the complete package in handling images for your website. It handles image upload, resize, generate thumbnails, storing image info to database and saving the file to physical disk drive
to install attachment_fu, we type
~$ .script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
if you don't have imagemagick and rmagick installed
~$ sudo apt-get install imagemagick
~$ dpkg -l | grep magick
~$ sudo apt-get install libmagick9-dev
~$ sudo gem install rmagick -v=1.15.12
window users: you can go download the imagemagick executable and install rmagick by doing gem install rmagick -v=1.15.12
now let's generate a model to test it out
~$ .script/generate model photo
open up the migration file and enter the following
class CreatePhotos < ActiveRecord::Migration
def self.up create_table :photos do |t|
t.column :user_id, :integer
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
end
end
def self.down
drop_table :photos end
end
:user_id - I'm assuming these photos belong to someone, you can replace it with another model_id depending on the relationship
:parent_id - don't touch, it's reserved for attachment_fu
:content_type - specify the content type of your data, default is image, but it can also be audio, or video the rest are pretty self explanatory, and we'll revisit these fields in a moment. now save your file, and do a quick rake db:migrate
J
Tuesday, February 12, 2008
Ubuntu and MP3s
Using the prepacakged Rhythmbox Music Player, I attempted to import my MP3s. However, I got a GStreamer plugin error that it couldn't handle MP3s.
For MP3 support, do the following:
>sudo apt-get install gstreamer*
Now start your Rhythmbox again. ;)
Rhytmbox also supposedly supports syncing with your iPod. I have yet to try, and will report on this issue once I have tried it out.
W
For MP3 support, do the following:
>sudo apt-get install gstreamer*
Now start your Rhythmbox again. ;)
Rhytmbox also supposedly supports syncing with your iPod. I have yet to try, and will report on this issue once I have tried it out.
W
Ubuntu Input Languages
For those that want to be able to type in Chinese, Japanese, or Korean, Ubuntu comes with a prepackaged application called SCIM. There is, however, a trick needed to get it working properly.
Go to System > Administration > Language Support. Then select the languages you want. Check the Enable support to enter complex characters. If it s already checked, you must uncheck it, click Apply, then recheck it. Hit Apply now. Log out and log back in.
Now you should see a little icon in the top right that looks like a keyboard. That's good. Supposedly, you can now hit Control + Space, and it should toggle through your input options. However, in Ubuntu 7.10, it doesn't.
Do the following:
>sudo gedit /etc/X11/xinit/xinput.d/scim
Change:
GTK_IM_MODULE=xim
QT_IM_MODULE=xim
To:
GTK_IM_MODULE="scim"
QT_IM_MODULE="scim"
Save and exit. Log out and log back in.
Now, when you're at an input, you can simply hit Control + Space, and it will toggle through your input options.
Enjoy!
W
Go to System > Administration > Language Support. Then select the languages you want. Check the Enable support to enter complex characters. If it s already checked, you must uncheck it, click Apply, then recheck it. Hit Apply now. Log out and log back in.
Now you should see a little icon in the top right that looks like a keyboard. That's good. Supposedly, you can now hit Control + Space, and it should toggle through your input options. However, in Ubuntu 7.10, it doesn't.
Do the following:
>sudo gedit /etc/X11/xinit/xinput.d/scim
Change:
GTK_IM_MODULE=xim
QT_IM_MODULE=xim
To:
GTK_IM_MODULE="scim"
QT_IM_MODULE="scim"
Save and exit. Log out and log back in.
Now, when you're at an input, you can simply hit Control + Space, and it will toggle through your input options.
Enjoy!
W
attachment_fu
attachment_fu plugin is the complete package in handling images for your website.
It handles image upload, resize, generate thumbnails, storing image info to database
and saving the file to physical disk drive
to install attachment_fu, we type
~$ .script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
if you don't have imagemagick and rmagick installed
~$ sudo apt-get install imagemagick
~$ dpkg -l | grep magick
~$ sudo apt-get install libmagick9-dev
~$ sudo gem install rmagick -v=1.15.12
window users: you can go download the imagemagick executable
and install rmagick by doing gem install rmagick -v=1.15.12
now let's generate a model to test it out
~$ .script/generate model photo
open up the migration file and enter the following
class CreatePhotos < ActiveRecord::Migration
def self.up create_table :photos do |t|
t.column :user_id, :integer
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
end
end
def self.down
drop_table :photos end
end
:user_id - I'm assuming these photos belong to someone, you can replace it with another model_id depending on the relationship
:parent_id - don't touch, it's reserved for attachment_fu
:content_type - specify the content type of your data, default is image, but it can also be audio, or video the rest are pretty self explanatory, and we'll revisit these fields in a moment. now save your file, and do a quick rake db:migrate
In our model, we'll use the has_attachment command to hook into attachment_fu.
example:
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => '320x200>',
:thumbnails => { :thumb => '100x100>' }
:processor => 'Rmagick'
validates_as_attachment
Let's look at each option in detail
for storage, you have three options, :db_system (default), :file_system, or :S3. If you are using :db_system, attachment_fu will convert and save the image to your db as a BLOB (binary large object). If :file_system is used, the file will be saved to your hard disk. If :S3 is used, image will be saved to Amazon's S3 server.
:max_size lets you specific the maximum size of the photo, and there's also a :min_size which works the other way
:resize_to - resize your image to an acceptable width and height like facebook :) It takes a string called the Geometry String, which has the format:
\x\+-\+-\{%@!\<\>}
where any of the field can be omitted.
By default, width and height are the maximum value. If you enter something like '300x500' the image will expand or contract to fit the width and height value while maintaining the aspect ratio of the image.
If you want to enforce the image size to be exactly the size your specify, you can append an exclamation mark in the end '300x500!'
You can also specify either the width '300' or the height 'x500' where the missing parameter will be chosen to maintain the aspect ratio
You can append % to specify percentage width and height ('110%' - increase, '90%' - decrease, '110%x90%' = increase width, decrease, height)
You can use @ to specify the maxium area in pixels of an image (I don't see how this is gonna be useful)
You can use > or <>' and the image size is '250x250', the image size will not change. However if the image is '1000x1000', the it'll be resized to '300x300' and vice versa.
Finally x and y are offsets for width and height. + causes x and y to be measured from the left or top edges and - measures from the right or bottom edges. And they are always measured in pixels. That took long enough, let's move on
:thumbnails - a set of thumbnails to generate, specified by a has of filename suffixes and resizing options. You can omitted it if you don't want thumbnails. Generating multiple thumbnails will look something like this
:thumbnails => { :thumb_big => '500x500', :thumb_small => '100x100' }
:thumbnail_class - set what class to use for thumbnails (defaulted to whatever model you are in) However, you can generate a seperate model with seperate set of validations
:processor - 'ImageScience', 'Rmagick', or 'MiniMagick'. I like Rmagick cause it has the most features.
:path_prefix - Path to store the uploaded files, which defaults to public/your_table_name
If you are using S3 backend, it defaults to just your_table_name
validates_as_attachment does all the validations for you, so you have nothing to worry about :)
This post is getting way too long. I'll have a seperate post for view and controller
J
It handles image upload, resize, generate thumbnails, storing image info to database
and saving the file to physical disk drive
to install attachment_fu, we type
~$ .script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
if you don't have imagemagick and rmagick installed
~$ sudo apt-get install imagemagick
~$ dpkg -l | grep magick
~$ sudo apt-get install libmagick9-dev
~$ sudo gem install rmagick -v=1.15.12
window users: you can go download the imagemagick executable
and install rmagick by doing gem install rmagick -v=1.15.12
now let's generate a model to test it out
~$ .script/generate model photo
open up the migration file and enter the following
class CreatePhotos < ActiveRecord::Migration
def self.up create_table :photos do |t|
t.column :user_id, :integer
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
end
end
def self.down
drop_table :photos end
end
:user_id - I'm assuming these photos belong to someone, you can replace it with another model_id depending on the relationship
:parent_id - don't touch, it's reserved for attachment_fu
:content_type - specify the content type of your data, default is image, but it can also be audio, or video the rest are pretty self explanatory, and we'll revisit these fields in a moment. now save your file, and do a quick rake db:migrate
In our model, we'll use the has_attachment command to hook into attachment_fu.
example:
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => '320x200>',
:thumbnails => { :thumb => '100x100>' }
:processor => 'Rmagick'
validates_as_attachment
Let's look at each option in detail
for storage, you have three options, :db_system (default), :file_system, or :S3. If you are using :db_system, attachment_fu will convert and save the image to your db as a BLOB (binary large object). If :file_system is used, the file will be saved to your hard disk. If :S3 is used, image will be saved to Amazon's S3 server.
:max_size lets you specific the maximum size of the photo, and there's also a :min_size which works the other way
:resize_to - resize your image to an acceptable width and height like facebook :) It takes a string called the Geometry String, which has the format:
\
where any of the field can be omitted.
By default, width and height are the maximum value. If you enter something like '300x500' the image will expand or contract to fit the width and height value while maintaining the aspect ratio of the image.
If you want to enforce the image size to be exactly the size your specify, you can append an exclamation mark in the end '300x500!'
You can also specify either the width '300' or the height 'x500' where the missing parameter will be chosen to maintain the aspect ratio
You can append % to specify percentage width and height ('110%' - increase, '90%' - decrease, '110%x90%' = increase width, decrease, height)
You can use @ to specify the maxium area in pixels of an image (I don't see how this is gonna be useful)
You can use > or <>' and the image size is '250x250', the image size will not change. However if the image is '1000x1000', the it'll be resized to '300x300' and vice versa.
Finally x and y are offsets for width and height. + causes x and y to be measured from the left or top edges and - measures from the right or bottom edges. And they are always measured in pixels. That took long enough, let's move on
:thumbnails - a set of thumbnails to generate, specified by a has of filename suffixes and resizing options. You can omitted it if you don't want thumbnails. Generating multiple thumbnails will look something like this
:thumbnails => { :thumb_big => '500x500', :thumb_small => '100x100' }
:thumbnail_class - set what class to use for thumbnails (defaulted to whatever model you are in) However, you can generate a seperate model with seperate set of validations
:processor - 'ImageScience', 'Rmagick', or 'MiniMagick'. I like Rmagick cause it has the most features.
:path_prefix - Path to store the uploaded files, which defaults to public/your_table_name
If you are using S3 backend, it defaults to just your_table_name
validates_as_attachment does all the validations for you, so you have nothing to worry about :)
This post is getting way too long. I'll have a seperate post for view and controller
J
Ubuntu + Eclipse 3.3 (Europa)
When using
> sudo apt-get install eclipse
there are several problems. Firstly, eclipse doesn't inherently use Sun's Java. This results in a "slow Eclipse". Secondly, using this command gives you Eclipse 3.2, not 3.3.
So, this is what I did:
Download Eclipse 3.3 straight from the Eclipse website (I got the classic version). Extract the tarball, and you have a working, standalone Eclipse 3.3.
However, it is not integrated into Ubuntu and it's still not using Sun's Java. Follow the instructions from the first post of this thread.
Eclipse should now be integrated into Ubuntu, but this is still version 3.2.
We will now overwrite 3.2 with our downloaded 3.3:
>sudo cp -R ~/Desktop/eclipse/* /usr/lib/eclipse/
Now that we have 3.3 installed and integrated into Ubuntu, there is one more step to do. When doing software updates, Eclipse needs to create and install new files. This can be troublesome with the wrong permissions. I went through a number of hacks, none of which worked, so I finally settled for opening up all permissions in the Eclipse install directory:
>sudo chmod 777 -R /usr/lib/eclipse
Voila! After this is complete, you may start to use Eclipse and install other plugins.
W
> sudo apt-get install eclipse
there are several problems. Firstly, eclipse doesn't inherently use Sun's Java. This results in a "slow Eclipse". Secondly, using this command gives you Eclipse 3.2, not 3.3.
So, this is what I did:
Download Eclipse 3.3 straight from the Eclipse website (I got the classic version). Extract the tarball, and you have a working, standalone Eclipse 3.3.
However, it is not integrated into Ubuntu and it's still not using Sun's Java. Follow the instructions from the first post of this thread.
Eclipse should now be integrated into Ubuntu, but this is still version 3.2.
We will now overwrite 3.2 with our downloaded 3.3:
>sudo cp -R ~/Desktop/eclipse/* /usr/lib/eclipse/
Now that we have 3.3 installed and integrated into Ubuntu, there is one more step to do. When doing software updates, Eclipse needs to create and install new files. This can be troublesome with the wrong permissions. I went through a number of hacks, none of which worked, so I finally settled for opening up all permissions in the Eclipse install directory:
>sudo chmod 777 -R /usr/lib/eclipse
Voila! After this is complete, you may start to use Eclipse and install other plugins.
W
Monday, February 11, 2008
Ubuntu Ruby Gems
From a previous post on moving to Ubuntu by J, there was a mention of installing Ruby Gems.
Well, I came across an error when executing:
> sudo gem update --system
It complained of a Gem::GemNotFoundException. I found a quick fix for this which was to do the following:
> sudo gem update
> sudo gem update --system
This seemed to do the trick.
After the update though, there was another error when executing:
>gem -v
to check the version. The error was "uninitialized constant Gem::GemRunner (NameError)". Another quick fix for this one was to add an extra line to /usr/bin/gem
require 'rubygems/gem_runner'
after
require 'rubygems'
Probably more problems and solutions to come later ^^
W
Well, I came across an error when executing:
> sudo gem update --system
It complained of a Gem::GemNotFoundException. I found a quick fix for this which was to do the following:
> sudo gem update
> sudo gem update --system
This seemed to do the trick.
After the update though, there was another error when executing:
>gem -v
to check the version. The error was "uninitialized constant Gem::GemRunner (NameError)". Another quick fix for this one was to add an extra line to /usr/bin/gem
require 'rubygems/gem_runner'
after
require 'rubygems'
Probably more problems and solutions to come later ^^
W
Ubuntu sources.list
Just an extension to a previous post by J about installing applications in Ubuntu. If the sources in sources.list are giving you troubles, take a look at this Gutsy Gibbon help guide.
Scroll down to the Manual Method for Adding Repositories. After following this, everything installed correctly.
Also, to be noted is that my previous source list all had Canadian mirrors. These mirrors are sometimes not up to date, slow, or down.
W
Scroll down to the Manual Method for Adding Repositories. After following this, everything installed correctly.
Also, to be noted is that my previous source list all had Canadian mirrors. These mirrors are sometimes not up to date, slow, or down.
W
Subscribe to:
Posts (Atom)