I needed to copy the EXIF information data from one image to another and I found the nicest program ever: ExifTool, a Perl command-line program by Phil Harvey. It works on Mac and Windows. Once installed, you open your terminal and type:
exiftool image.jpg #To read exif data
exiftool -tagsFromFile original.jpg new.jpg #To copy EXIF tags from original.jpg to new.jpg
You can also read the docs to know how to change any field of the EXIF data and so on. Very handy, thanks Phil Harvey!
Tags: copy exif dataexiftool
1 Comment »
I found odd how few places were talking about reading a WordPress database from a Rails app.
If you want to flash your blog updates somewhere in your Rails app it comes handy to have your WP posts mapped as if they were any other Rails model. How to do so is not complicated so long as you consider a few details.
First off, add a new database in your config/database.yml.
blog:
adapter: mysql
encoding: utf8
host: YOUR HOST
database: DATABASE OF YOUR WP
username: USERNAME
password: PASS
Add your WP model: /app/models/wp_post.rb:
class WpBlogPost < ActiveRecord::Base
establish_connection :blog
set_primary_key 'ID'
set_table_name "wp_XXXXX_posts"
#Only in case you want to add comments as well:
has_many :comments, :class_name => "WpComment", :foreign_key => "comment_post_ID"
end
In case you want to add comments as well, /app/models/wp_comment.rb:
class WpBlogComment < ActiveRecord::Base
establish_connection :blog
set_table_name "wp_XXXXX_comments"
set_primary_key "comment_ID"
belongs_to :post , :class_name => "WpPost", :foreign_key => "comment_post_ID"
end
Attention! You need to tell Rails what field is the primary key since these tables do not follow the Rails convention, and also you need to specify the name of the table within the WP database, something like wp_234f8_posts, or wp_234f8_comments.
When that’s done, you can start using it from your controllers and views. Remember to get all posts marked as “publish”, as WP registers a lot of redundant data in the DB as well. Something like this would work:
@posts = WpBlogPost.find(:all, :conditions => ['post_status = "publish"'], :limit => 10)
One other important thing should be considered. Be sure you configured your host db server to accept access from the outside if you want to try your controllers from your local development server. Also, you need the last MySQL installed as a gem (sudo gem install mysql).
Tags: active recordruby on railsWordpress
6 Comments »
When you’ve got a designer that often makes awesome but heavy PNG designs (I’m talking about 400K-700K for background images!!) you really must get moving if you don’t want your app to take ages to load. I just found something that helps (of course, you still need to talk to her anyway) but doing this won’t harm:
Get the program pngcrush.
#For Linux
apt-get install pngcrush
#For Mac !Get first Macports*
sudo port install pngcrush
* MacPorts
As the name suggests it will crush your PNG images to a smaller size. It won’t do miracles but it will make your loads lighter. The query I found to get most satisfactory results is this one:
pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB -brute originalFile resizedFile
I did a script to make this automatically for all files, take it if you want:
./reduce.sh
#!/bin/bash
crushed="crushed_"
for file in *.png
do
dest="$(echo $crushed$file)"
pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB -brute $file $dest
echo -n "Crushing $src ... "
done
read -p "Files crushed\n Overwrite original files? (y/N) "
if [ "$REPLY" == "y" ]
then
for crushed in $(ls | grep crushed_)
do
original="$(echo $crushed | cut -c 9-)"
mv $crushed $original
done
fi
Execute this script (remember to do chmod +x first) in your images folder. It will let you check the files before overwriting them. If you are happy with the results, type ‘y’ and the lighter PNG images will replace the old ones.
Tags: compress pngspngcrushreduce sizesmaller website images
2 Comments »