Part of the EllisLab Network
   
 
On the fly image
Posted: 30 January 2007 10:46 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  67
Joined  11-07-2006

Hi to all,
  my goal is to keep code short and things simple.
My approach to manage a small user’s image gallery is to let them upload image files of arbitrary size within max, then provide in views img sources generated by another controller.

That controller’s job is to check if user is logged, then read the file and serve it with image/jpg headers.

Until now there isn’t any resizing/cropping/watermarking. Images are served raw as uploaded. I don’t want to show the raw source image but a controller generating image on the fly, to use first as thumbailer, then as in layout image with website name watermarked.

To to this I’ve read in user_guide about a not well documented dynamic_output option of watermarking.

The goal is to write a controller “http://website.tld/image/thumb/12/345.jpg” and “http://website.tld/image/full/12/345.jpg”, having image as controller, thumb/full as method, 12 as user_id, 345 as raw image filename.

I’m wondering about storing images into user_id directory with arbitrary or random filename in it, to catch with CI’s file helper.

Some help?
Best Regardz!

 Signature 

cool hmm mmmmh…

Profile
 
 
Posted: 31 January 2007 05:38 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  5
Joined  01-04-2007

i have setup a directory structure like

filebase/original/
filebase/fullsize/
filebase/thumb1/
filebase/thumb2/

When a user requests my imagecontroller/imageid i fetch the file info from my image table. Then i check if the file i want to show exists, if not I scale it, store it then output it to the browser.


In my cms i have an image cache instead.

filebase_cache/imageid.scaledwidth.scaledheight

When a user requests showimage/123/100/100   (imageid/width/height) i check if the file exists in cache, generates it and caches it if it doesnt exist and outputs it to the browser.

Profile
 
 
Posted: 31 January 2007 05:59 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  67
Joined  11-07-2006

I’ve managed to write the image generator controller easily because It’s outputting headers on the fly it’s impossible to do resizing and watermark both. So I’ve chosen to do thumb with resize and serve resized images in theire full size.

Yes i resize the upload ;_; and i don’t want that. I resize only because creation onthefly is really resource expensive. So maybe the right choice doing some caching system i never did before. how to make a cache system of this kind?

Wich suggestion for caching? my variables are user_id who referer the images, and “the slot” it’s the key got with the file helper method: get_filenames(mydir/id_user).

So I’ve managed to serve the first image for user 999 with that url: http://domain.tld/image/full/999/0

 Signature 

cool hmm mmmmh…

Profile
 
 
Posted: 31 January 2007 08:17 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

Theres a script I wrote that you may find useful. It auto resizes/crops images and caches them to the disk. I just posted it to the wiki. I’ll add more detail later. I hope it helps.

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 10 February 2007 03:13 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  01-21-2007
joeles - 31 January 2007 08:17 AM

Theres a script I wrote that you may find useful. It auto resizes/crops images and caches them to the disk. I just posted it to the wiki. I’ll add more detail later. I hope it helps.

ok, I did everything… Linked to it via: http://www.clubaddict.co.uk/avatar/size/100x100/<?= $row->avatar; ?>

but no image shows up… but it does if I link directly like: http://www.clubaddict.co.uk/avatars/<?= $row->avatar; ?>

Any ideas?

Profile
 
 
Posted: 10 February 2007 03:47 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

Did you save it as avatar.php in your controllers directory and change the name of the class and constructor be be Avatar? The filename, class, and constructer names must match the name of the directory that is stores your images.

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 10 February 2007 04:10 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  01-21-2007

hi Joeles… just checked…
My images are stored at http://www.clubaddict.co.uk/avatar so I set it like this: $this->img_dir = $_SERVER[‘DOCUMENT_ROOT’] . site_url(’/avatar’); and my controller is called avatar.php with Class and Contructor both Avatar

When I goto something like
http://www.clubaddict.co.uk/avatar/size/100x100/bf652fd61c7854b6c90eaf505f14aa6b.jpg I get No Input File Specified

Profile
 
 
Posted: 10 February 2007 04:34 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

Is your /avatar directory chmod’ed to 777?

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 10 February 2007 04:39 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  01-21-2007

yeah

Profile
 
 
Posted: 10 February 2007 04:39 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  01-21-2007

do I need to create any folders inside the /avatar directory?

Profile
 
 
Posted: 10 February 2007 05:33 PM   [ Ignore ]   [ # 10 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

I tried visiting the link above, but I got a PHP error. Are you missing a semicolon somewhere around line 40?

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 10 February 2007 05:33 PM   [ Ignore ]   [ # 11 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  01-21-2007

may have found the problem…

Profile
 
 
Posted: 10 February 2007 05:38 PM   [ Ignore ]   [ # 12 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  01-21-2007

I copied the code and did the file and replace and now Im getting this:

Parse error: syntax error, unexpected ‘}’ in /home/clubaddi/public_html/system/application/controllers/avatar.php on line 181

so I add a ; to the end of
if ($src_file == dirname($cache_file).’/_’.basename($cache_file)) unlink($src_file) and then I get:


Parse error: syntax error, unexpected T_EXIT in /home/clubaddi/public_html/system/application/controllers/avatar.php on line 206

Profile
 
 
Posted: 29 November 2007 06:30 AM   [ Ignore ]   [ # 13 ]  
Grad Student
Rank
Total Posts:  63
Joined  10-08-2006

I also would like to use this class and am at the same stage.

I put a semicolon on the end of “die” on line 208.

It just doesnt seem to work. I am certain i have it set up correctly.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64453 Total Logged-in Users: 17
Total Topics: 80961 Total Anonymous Users: 0
Total Replies: 435692 Total Guests: 197
Total Posts: 516653    
Members ( View Memberlist )