I have been working on a photography website for quite sometime now. One of the requirements from my client is to have a watermark on the images that they upload for their clients to view. An additional requirment (on my end) is to create a thumbnail of every image that gets uploaded.
Codeigniter offers a vast array of helper files and libraries that help push along web development, among these aids is an Image Manipulation class.
In working with this class, I kept running into issues when trying to create a watermarked image and a thumbnail of the same image. Problems included not creating the thumbnail but creating the watermark, creating the watermark but not the thumbnail, creating a watermark and a thumbnail but not resizing the thumbnail, creating a watermark and a thumbnail but resizing the original image without creating a thumbnail size image, and the list goes on...
Here is how I fixed my problem
//Settings to create watermark overlay $config = array(); $config["source_image"] = "/path/to/image"; $config["image_library"] = "gd2"; $config["wm_type"] = "overlay"; $config["wm_overlay_path"] = "/path/to/watermark/overlay"; $config["wm_vrt_alignment"] = "bottom"; $config["wm_hor_alignment"] = "center"; $config["wm_vrt_offset"] = 20; $this->image_lib->initialize($config); $this->image_lib->watermark(); $this->image_lib->clear(); unset($config); //Move watermarked image into user account folder //The below function moves the watermark image into the clients photo directory $this->_moveimage($image, $account, FALSE); $thumb_config["source_image"] = "/path/to/watermarked/image"; //You are supposed to use a brand new image name here, I usually add a prefix of copy_ or thumb_ $thumb_config["new_image"] = "/path/to/new/image"; $thumb_config["maintain_ratio"] = TRUE; $thumb_config["width"] = 125; $thumb_config["height"] = 125; $this->image_lib->initialize($thumb_config); $this->image_lib->resize(); $this->image_lib->clear(); unset($thumb_config);
And there ya go! You have a CodeIgniter script that watermarks and thumbnails an image.
Web DesignWith Over 6½ years of web design experience backed by powerful web 2.0 standards, Dennis Monsewicz is capable of producing a powerful website with explosive results! If you want to increase your web market and increase your customer clientel, contact Dennis Monsewicz today!
DevelopmentWhen wanting a website its not all about fancy lettering and bright flashy colors, but it also has to have a powerful stunning backend to provide dynamic content for frontend user experience. The 3½ years of PHP/MySQL experience Dennis has, can help when wanting to produce results in this ever growing web market.
Codeigniter - Watermark and Thumbnail Creation
I have been working on a photography website for quite sometime now. One of the requirements from my client is to have a w...
posted on 06/30/2010 under Technology
Liferay PHP Installation Script (v. 0.5)
In developing database heavy PHP apps for Liferay, I got tired of having to constantly create Database tables and then loa...
posted on 03/22/2010 under Technology
If you are unfamiliar with the name of Liferay, it is a Java based CMS that is scripting language agnostic, meaning you ca...
posted on 03/02/2010 under Technology
If you are wanting to use the uuencode command line functionality to encode a file for mailing, install the following pack...
posted on 02/23/2010 under Technology
"Friendship makes prosperity more brilliant, and lightens adversity by dividing and sharing it."
-- Cicero (44 B.C.)
"A true friend is someone who thinks that you are a good egg even though he knows that you are slightly cracked."
-- Bernard Meltzer
"It takes a long time to grow an old friend."
-- John Leonard
"Friendship is born at that moment when one person says to another, 'What! You too? I thought I was the only one."
-- C.S. Lewis
