[cms_easythumb]

Description

Link: [cms_easythumb]
Author: Dominique Guardiola
Category: Image
Version: 8.5.x
License: Public Domain
Posted: Jan. 19, 2008
Updated: May. 28, 2008
More by this author...

Use the WebThumb snapshot Service to create a JPEG snapshot of a given URL. It requires you sign up for the service.
Returns a HTML tag containing the URL to the JPEG thumbnail. This simple GET method permits 3 differents type of snapshots

  • small = 80 x 60 pixels
  • medium = 160 x 120 pixels
  • medium2 = 320 x 240 pixels

The image can be long to show (few seconds), so saving the file for future use using the -file option can be useful.

 

A XML API is availble at WebThumb, with more options (excerpts, PNG support, custome sizes, etc)

Parameters

-apikey string, required your webthumb API key
-cache integer, optional the cache time in days on webthumb server, max 7. default to 1.
-file string, optional The thumbnail is saved to the filepath+filename given, overwriting a previous file with the same name. Requires the tag to be run with File Tag permission (you can edit the tag to modifiy your user/pass in the inline).
-size string, optional supported values : small, medium and medium2. default to small.
-url string, required the URL of the website
-userid string, required your Webthumb userID
-class string, optional a CSS class selectot for the <img> output
-id string, optional a CSS ID selector for the <img> output
-debug optional id used, print out the params and errors

Sample Usage

cms_easythumb(
        -url= 'http://www.example.com',
	-userid= 'xxxx',
	-apikey= 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');


To display the <img> with custom CSS class an ID ,and 
download the thumbnail in a given path.

cms_easythumb(
        -url= 'http://www.example.com',
	-file='/my/absolute/file/path/myfilename.jpg',
	-size='medium2',
	-userid= 'xxxx',
	-apikey= 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//lasso

/*----------------------------------------------------------------------------

Use the WebThumb Service to create a JPEG snapshot of a given URL
It requires you sign up for the service at http://webthumb.bluga.net/
Returns the URL to pickup the snapshot.

-file='/filepath/image.jpg'
If you use this option, a file will be created or overwrited and the tag
will return the filepath.

small = 80 x 60
medium = 160 x 120
medium2 = 320 x 240
larger = ?

----------------------------------------------------------------------------*/

define_tag: 'easythumb',
	-namespace='cms_',
	-priority='replace',	
	-required='url',
	-required='apikey',
	-required='userid',
	-optional='file',
	-optional='size',
	-optional='cache',
	-optional='content_keyvalue',
	-optional='id',
	-optional='class',
	-optional='debug',
	-encodenone;
	
	Lasso_ExecutionTimeLimit: 60;
	
	local('service_url') = 'http://webthumb.bluga.net/easythumb.php'; //can change some day
	!local_defined('size')? local('size') = 'small';  //  {small | medium | medium2}		
	!local_defined('cache')? local('cache') = '1';
	local('datestamp') = date_format((Date_LocalToGMT:date),-Format='%Y%m%d');

	local('string_url') = string(#service_url + '?user=' + #userid + '&url=' + encode_url(#url) + '&size=' + #size + '&cache=' + #cache + '&hash=' + encrypt_MD5(#datestamp + #url + #apikey));

	local('response') = include_url(#string_url, -timeout=0);

	if: string_extract(#response, -startposition='7', -endposition='11') !>> 'JFIF';


		//the long french error message is here to explain with a link that
		//perhaps the targeted web site uses some strange redirection
		//the system could not follow, it says : check the real URL before.
		Error_SetErrorMessage( 'Error: '+string(#response));
		return('<b>Erreur:</b> '#response'<br/>Relancez la création d'icône en cliquant sur l'onglet «texte» puis à nouveau sur l'onglet «icône».<br/>
		<b>Attention:</b> Il se peut que l'adresse de siteque vous avez fournie ('#url') ne soit pas vraiment celle de la page d'accueil. <a href="'#url'" target="_blank">Essayez de cliquer ici.</a><br/>
		Si le site utilise une <b>redirection</b>, c'est à dire si l'adresse figurant dans la barre d'dresse est différente de celle que vous avez fournie, recopiez la véritable adresse pour que notre système puisse prendre une photo d'écran correctement.');
	
	else;		
			
		local('result') = '<img src="';
			
		if: local_defined('file');
		
		
			//change this to your DB credentials
			//I use a text field to hold the path to the JPEG
			//and file write but you could use a BLOB field in MySQL
			Inline(	-Update,
					-Username='xxxxxxxxx',
					-Password='xxxxxxxxx',
					-Database='db',
					-Table='table',
					-KeyValue=local('content_keyvalue'),
					'img_path_field'= 'thumb_'+field('id')+'.jpg',
					-NoValueLists);
					
					error_code != '0'  ?  error_currenterror;
					file_write(#file, #response, -fileoverwrite);
					
			/Inline;
			#result += #file'" ';
			
		else;
		
			#result += #string_url'" ';
			
		/if;
		
		select(#size);
			case('small');#result += 'width="80" height="60" ';
			case('medium');#result += 'width="160" height="120" ';
			case('medium2');#result += 'width="320" height="240" ';
		/select;	
		!local_defined('id')? #result += 'id="'local('id')'" ';
		!local_defined('class')? #result += 'class="'local('class')'" ';
		
		//'Congratulations' !
		#result += '/><br/><b>Icône créée !</b><br/>';
		
		//debug option print out params
		local_defined('debug')? 
		#result +='-file='local('file')'<br/>
		-userid= '#userid'<br/>
		-size='#size'<br/>
		-content_keyvalue='local('content_keyvalue')'<br/>
		-url='#url'<br/>
		-apikey='#apikey'<br/>
		URL = '#string_url'<br/>'error_currenterror' 'file_currenterror;	
			
		error_code != '0'  ? return(error_currenterror' 'file_currenterror)|return(#result);
		
	/if;
	
/define_tag;

 

Comments

none

Email:


Password:



Newest

Most Popular