circle.ch weblog by Urs Gehrig |
||
|
||
| Academic, Android, Apache, Apple, Art, Best Of, Biotech, Civil Society, Content Management, Cooking, Copyright, Creative Commons, Crosspost, Culture, Database, Deutsch, DRM, Economy, Education, Event, Gadget, General, Geodata, Government, Health, Howto, Humor, Innovation, Intellectual Property, Java, Language, LaTeX, Law, Linux, Media, Moblog, Mozilla, Music, Office, Open Content, Open Source, P2P, PHP, Podcast, Politics, Privacy, Projects, Random Thought, Rant, Science, Search, Social Network, Software, Sport, Talks, Technology, Technology Transfer, Travelling, Weblog, Wiki, Wireless and Mobile, XML
|
||
23. April 2002
Converting an Image to standalone SVG SVG offers the possibility to display images within an SVG viewer by either referencing to the image file or - wich makes the SVG file standalone - embeding the image source within the SVG file [1]. To have a standalone file one needs to encde the image by base64 [2]. The code below is reading the test.jpg file binary safe, which is one of the important parts here, while it is later converted directly by the PHP built-in base64_encode()function [3]. Finally the encoded string and the image size parameters will be applied to an SVG template file. Have a look at the sample script too [4]. Happy SVGin! Script: image2svg.php <?php /** * Topic: Converting an image to standalone SVG * Author: Urs Gehrig * Date: 2002-04-22 * License: GNU General Public License (GPL) * http://www.gnu.org/licenses/gpl.html * * Thanks: Vincent Hardy */ // One never knows, how long it will last... ini_set("max_execution_time", 10000); // Get them from cvs.php.net require_once("HTML/ITX.php" ); // Load a test image $filename = "test.jpg"; $fd = fopen ($filename, "rb" ) or die ("File $file cannot be opened." ); // Read binary-safe $buffer = fread($fd, filesize ($filename) ); fclose ($fd); // Get parameters of the image $par = getimagesize($filename ); // Handle the template file $tpl = new IntegratedTemplate("." ); $tpl->loadTemplatefile("tpl.image.svg", true, true); $content = array ( "img_information" => base64_encode($buffer ), "img_width" => $par[0], "img_height" => $par[1], "script_name" => basename($SCRIPT_NAME) ); $tpl->setVariable($content); // Ouput the SVG file header("Content-type: image/svg+xml"); $tpl->show(); ?> Script: tpl.image.svg <?xml version="1.0" encoding="iso-8859-1" ?> <!-- // ***************************************** // Image To SVG Conversion // Copyright (c) 2002, 2003 by Urs Gehrig // ***************************************** //--> <svg width="{img_width}" height="{img_height}" viewBox="0 0 {img_width} {img_height}" xml:space="preserve"> <g id="image_1"> <image width="{img_width}" height="{img_height}" xlink:href="data:image/jpeg;base64,{img_information}" transform="matrix(1 0 0 1 0 0)"/> </g> <a xlink:href="{script_name}" target="_self"> <text style="font-size:10; stroke:black; stroke-width:0.5" x="5" y="12">circle.ch</text></a> </svg> Links [1] http://www.w3.org/Graphics/SVG/ - Scalable Vector Graphics (SVG) [2] http://www.ietf.org/rfc/rfc2045.txt - Multipurpose Internet Mail Extensions (MIME) [3] http://www.php.net/base64_encode - Base 64 encoding [4] http://circle.ch/projects/image2svg/ - Convert your Image online Comments (1) Permalink del.icio.us 15. April 2002
Authentication with PEAR Auth PEAR offers now a session based authentication using a database container. The sample below should help you to start up with it. Script
Comments (21) Permalink del.icio.us 13. December 2001
Scripts
THIS SOFTWARE IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Comments (2) Permalink del.icio.us 27. March 2001
Removing obsolete session from the DB Somewhere you may have a table with active_session of visitors using your site. From time to time you would like to remove obsolete session. The script below is using mktime() to fit the timestamp stored in the DB. I use to remove session in this example that are older than two days. Script <?php /** * Author: Urs Gehrig <urs_at_circle_ch> * Date: 27-3-2001 * * Subject: how you could remove your sessions older * than _x_ days from your database. */ require_once("prepend.php"); page_open(array( "sess" => "ac_session", "auth" => "ac_default_auth", "perm" => "ac_perm", "user" => "ac_user" )); ?> <?php /** * delete sessions from database older than 2 days * delete ac_user and ac_session */ $db = &new db_yourdb(); $cfg->active_sessions = "ac_active_sessions"; /** * building the reference date * $expired contains something like "20010327231519" */ $expired = strftime("%Y%m%d%H%M%S", mktime( date("H"), date("i"), date("s"), date("m"), date("d")-2, date("Y") ) ); /** * building the sql query */ $sql = "DELETE FROM $cfg->active_sessions WHERE changed < '$expired' AND name LIKE '%ac_%'"; /** * executing the query */ $db->query($sql); ?> <?php page_close(); ?> to be cont'd Links http://phplib.netuse.de - PHPLIB home http://ch.php.net/mktime - PHP function reference Comments (0) Permalink del.icio.us 18. October 2000
Handling nested blocks within Templates The new template class called "Integratedtemplate" by NetUSE is probably, what you have been dreaming of. The author Ulf Wendel <uw@netuse.de> made your dreams come true. Have a look at this introduction sample script. I created two arrays, one containing the section title and another array holding the content. You may of course get your data from a database as well. Pay attention to the parsing of the blocks. Parse an inner block first and then, move to the outer block. Feel free to play around with this example. Scripts <!------- main.php -------> <?php /** * Template: Integrated Template by Ulf Wendel * URL: http://phplib.netuse.de/ * * Authors: Urs Gehrig <urs@circle.ch> * Ulf Wendel <uw@netuse.de> * Date: 18-10-2000 * * Darstellung im Stil: club members muster hans reuter fritz ... customers muster hans reuter fritz ... others muster hans reuter fritz ... */ // ... sollte nicht im webverzeichnis liegen. besser: // include ("c:/web/phplib/integratedtemplate.inc"); include ("integratedtemplate.inc"); $categories = array ( "0" => "club members", "1" => "customers", "2" => "others" ); $adresses = array ( "0" => array ("name" => "muster", "vorname" => "hans"), "1" => array ("name" => "reuter", "vorname" => "fritz"), "2" => array ("name" => "gruner", "vorname" => "rudolf"), "3" => array ("name" => "moser", "vorname" => "björn"), "4" => array ("name" => "amstutz", "vorname" => "michael") ); $tpl = new IntegratedTemplate("."); $tpl->loadTemplatefile("main.tpl.htm", true, true); for($i=0; $i<count($categories); $i++){ // inneren Block _vor_ dem äußeren parsen $tpl->setCurrentBlock("block_2"); for ($j=0; $j<count($adresses); $j++) { $tpl->setVariable( array ( "name" => $adresses[$j]["vorname"] . " " . $adresses[$j]["name"] ) ); $tpl->parseCurrentBlock(); } // äußerer block parsen $tpl->setCurrentBlock("block_1"); $tpl->setVariable( array ( "title" => $categories[$i] ) ); $tpl->parseCurrentBlock(); } $tpl->show(); ?> <!------- main.tpl.htm -------> <html> <table border> <!-- BEGIN block_1 --> <tr> <th>{title}</th> </tr> <tr> <td> <table border> <!-- BEGIN block_2 --> <tr> <td>{name}</td> </tr> <!-- END block_2 --> </table> </td> </tr> <!-- END block_1 --> </table> </html> Download The code is distributed "AS IS" without any warranty! Download: http://circle.ch/dl/integratedtemplate.zip (7KB) Links http://phplib.netuse.de - The famous PHPLib by NetUSE published 19.10.2000 Comments (0) Permalink del.icio.us |
Werbung:Beiträge von Dritten:
Nachfolgende Titel verweisen auf von mir gelesene Weblogs. Feeds:WikiAgenda:Comments:Good question, but...Hi, thank you very... Unter http://www.s... Ich weiss mir nich... ThanQ matthias. Th... in case you just w... ich liebe dir, urs... hi there, sorry i... Hoi Leo. I haven'... Do you know the si... Archives:Blog stack:Bill Humphriesmonorom Wendy M. Seltzer Christian Stocker Roger Fischer Sandro Zic Wez Furlong Ben Hammersley George Schlossnagle Joichi Ito Lawrence Lessig Derek Slater Karl-Friedrich Lenz John Palfrey Bernhard A.M. Seefeld Gregor J. Rothfuss Rainer Langenhan Elke Engel Sebastian Bergmann Simon Willison Jeremy Zwaodny Udo Vetter Axel A. Horns Miguel de Icaza Andreas Halter Silvan Zurbrügg Hannes Gassert Markus Koller
|
|
$Date: 2005/11/05 11:14:30 $ |
||