Difference between revisions of "User:Meyermagic Salome"

From Second Life Wiki
Jump to navigation Jump to search
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== About me ==
<div id="box">
''Name'': Meyer S. Jacobs
== About ==
<div style="padding: 0.5em;">


''Alias'': Meyermagic, if(x), |-1|
Programmer, photographer, musician, chemist.


''Age'': 472794735 as of 1175103075 (seconds since the Unix Epoch)
Programs in:
 
* Python
''Avoids'': Carbonated drinks, dressing up, political parties, and organized religion
* PHP
 
* LSL
''Is drawn to'': Math, physics, technology, interesting people, old cartoons, sci-fi, anime, good books, things that spin, magnets, food
* Javascript
</div></div>
<div id="box">
== Code ==
<div style="padding: 0.5em;">
In the Library:
* [[Camera Sync]]
* [[Spiral Staircase Generator]]
and [[User:Meyermagic_Salome/Optimizations|some optimizations]].
</div></div>


My plot in TG SL: {{simpleslurl|Nailsworth|116|25|62|TransGrid Corporation HQ}}


== Projects ==
{{visl
''Perception'' - A four part story<br />
|name=Meyermagic Salome
&rArr; Part One: ''The Crystals of Power''<br />
|Mentors=
&rArr; Part Two: ''The Tower Archive''<br />
|Greeters=
&rArr; Part Three: ''Perpetual''*<br />
|LSL=*
&rArr; Part Four: ''Transcend''<br />
|}}
 
{{skills
''The WeFiki'' - A next generation web protocol
|Builder=*
 
|Scripter=*
''null_Void'' - My personal site; not yet online
|}}
 
{{ISO 639-3/cat-speaking|eng|TSL Residents}}
== Some code ==
My PHP image gallery scripts:<br />
''config.php'':<br />
<pre>
<?php
/*General Data*/
//$main_template = "template.html"
//$template_base_prefix = "base_";
//$pages = array('home', 'galleries' => array('composition', 'visual', 'programming'), 'blog', 'about', 'links');
/*Image Gallery Data*/
$img_dir = 'visual';
$separator = '!~.~^~.~!';
$thumbXsize = 128; //128
$thumbYsize = 96; //96
$width = 4;//Table Columns
/*Composition Gallery Data*/
/*Other Data*/
/*Functions*/
//We have a little bit of trouble with layered .png files; the thumbs always seem to come out blank
//Also, there is no .bmp support
//Oh yeah! I'm planning on adding the ability to specify a set of thumbnail rules. Those might include alternate center, rotations, and checks for complexity of thumb
function create_thumb($source, $dest, $sizeX, $sizeY)
{
if(($source_data = getimagesize($source)) !== false)
{
$startX = ($source_data[0] / 2) - ($sizeX / 2);
$startY = ($source_data[1] / 2) - ($sizeY / 2);
if($source_data[2] == 1)
{ //Apparently imagecreatetruecolor won't work with gif images
$thumb = imagecreate($sizeX, $sizeY);
$imgsource = imagecreatefromgif($source);
imagecopymerge($thumb, $imgsource, 0, 0, $startX, $startY, $sizeX, $sizeY, 100);
imagegif($thumb, $dest);
}
elseif($source_data[2] == 2)
{
$thumb = imagecreatetruecolor($sizeX, $sizeY);
$imgsource = imagecreatefromjpeg($source);
imagecopymerge($thumb, $imgsource, 0, 0, $startX, $startY, $sizeX, $sizeY, 100);
imagejpeg($thumb, $dest, 100);
}
elseif($source_data[2] == 3)
{
$thumb = imagecreatetruecolor($sizeX, $sizeY);
$imgsource = imagecreatefrompng($source);
imagecopymerge($thumb, $imgsource, 0, 0, $startX, $startY, $sizeX, $sizeY, 100);
imagepng($thumb, $dest);
}
}
}
 
function imagelist_create($dir, $continue, $thumbX, $thumbY, $parseMark)
{
$image_array = array();
if(is_dir($dir) && ($dh = opendir($dir)))
{
while(($object = readdir($dh)) !== false)
{ //If its an image file...
if(is_file($dir.'/'.$object) && $object !='.' && $object != '..' && ($imagetype = getimagesize($dir.'/'.$object)) !== false)
{ //...with either gif, png, or jpeg type...
 
$imagetype = $imagetype[2];
$image_mimetype = image_type_to_mime_type($imagetype);
if(substr($image_mimetype, 6) == 'gif' || substr($image_mimetype, 6) == 'png' || substr($image_mimetype, 6) =='jpeg')
{
//...add it to the image array
if(!file_exists($dir.'/image_data/'.substr($object, 0, -3).'txt'))
{ //If there is no image data file, default display name to image name
$image_displayname = substr($object, 0, -4);
}
else
{
$image_data = file_get_contents($dir.'/image_data/'.substr($object, 0, -3).'txt');
$image_displayname = explode($parseMark, $image_data);
$image_displayname = $image_displayname[0];
}
$image_array[$dir][filemtime($dir.'/'.$object)] = array($object, $image_mimetype, $image_displayname, $dir);
//Eventually, I'll have it call ksort or krsort, depending on preference
krsort($image_array[$dir], SORT_NUMERIC);//Sort by date modified
$image_array[$dir] = array_values($image_array[$dir]);//Renumber sorted array
if(!file_exists($dir.'/thumbs/th_'.$object))
{ //If there isn't a thumbnail, create one using the thumbnail specifications from config.php
$dir_array = explode('/', $dir);
create_thumb($dir.'/'.$object, $dir_array[0].'/thumbs/th_'.$object, $thumbX, $thumbY);
}
else
{
$image_data = getimagesize($dir.'/thumbs/th_'.$object);
if($image_data[0] != $thumbX || $image_data[1] != $thumbY)
{ //Make sure the thumb, if there already was one, has the correct sizes
unlink($dir.'/thumbs/th_'.$object);
$dir_array = explode('/', $dir);
create_thumb($dir.'/'.$object, $dir_array[0].'/thumbs/th_'.$object, $thumbX, $thumbY);
}
}
}
}
//If you see a directory inside the root image directory, besides the "thumbs" and "image_data" directories, run this function again, on that directory, with continue FALSE
if(is_dir($dir.'/'.$object) && $object != 'thumbs' && $object != 'image_data' && $continue  && $object !='.' && $object != '..')
{
$image_array += imagelist_create($dir.'/'.$object, false, $thumbX, $thumbY, $parseMark);
}
}
closedir($dh);
}
return $image_array;
}
?>
</pre>
Example usage in ''visual.php'':<br />
<pre>
<?php
include('config.php');
 
/*
Okie dokie. I still need to:
Add .bmp support to thumbnail generator
Add unused thumbnail check
Add additional thumbnail generation features
Alternate Center Cropping
Scale + Crop
Rotate + Crop
Thumbnail complexity check (Uses rotation and alternate center to assure thumbnail contains at least a given number of unique pixels)
Add multiple sort setting
Alphabetical
Date Modified
User defined order preference
Try to find a way around the layered .png bug
<Update>It appears that the bug is not in the layers, as they are not present in all the images, but rather that <b><i>most of the images have alpha channel backgrounds</i></b>, with black content. <b><i>The black content does not appear against the page's black background.</i></b></Update>
--Another update-- The clear areas read black
Find some way to deal with image titles longer than one thumbnail's width
Incorporate gallery with Tom's slideshow code (This will require some modification on both sides)
Have image data be stored in a .xml file, just to be fancy (And to gain experience with php's XML functions)
-As an unrelated note, don't forget the php optimizing script idea (I thought I might be in the programming mood after reading this)-
Oh! Tidy is awesome, but kind of sucks when I want verbatim output. I wish you could set some directive at the beggining of the script to define wether or not the output should be repaired by Tidy.  : )
$meta_thought = "I geuss I could load the extension manually, but I'm not sure if I can turn on and off auto-tidy at the same time, as that is specified the php.ini file";
*/
//Load Data
$base = implode("", file("base_visual.html"));
$template = implode("", file("template.html"));
$thumb_temp_base = implode("", file("visual_thumbTemp.html"));
//Prepare table
$base_insert = '';
/*
List Format:
$images[Gallery][Image_Number]
Returns:
array(Image_Filename, Image_Type, Image_Displayname, Image_Gallery);
*/
$images = array_values(imagelist_create($img_dir, true, $thumbXsize, $thumbYsize, $separator));
$gallery_count = count($images);
$current_gallery;
/*
Note for template-based configuration; visual.php currently parses the following terms as described after each one
IMAGE_DIRECTORY - The path to the image
IMAGE_TITLE - The image's title, as described in the imagedata file, or, if the imagedata file is not present, the image's filename without the extension
THUMB_SOURCE - The image thumbnail path and filename; For example, 'visual/thumbs/th_someimage.jpg'
SLIDE_NUMBER - The image's location in the image list, as described by the following formula: 'Slide_Number = Current_Row * Row_Width + Current_Column'
IMAGE_FILENAME - The source image's filename
GALLERY_TITLE - The current gallery in 'title form'; that is, the directory, with forward slashes, '/', replaced by '->'
*/
$thumb_temp = $thumb_temp_base;//Set working thumbnail template
for($current_gallery = 0; $current_gallery < $gallery_count; $current_gallery++)
{ //More of the formatting, including the location of gallery titles and other structure data, will be migrated to a template file
$base_insert .= '<p>GALLERY_TITLE</p>';
$base_insert .= '<table class="gallery">';
$extra_images = count($images[$current_gallery]) % $width; //Extra images
$full_rows = (count($images[$current_gallery]) - $extra_images) / $width; //Number of full rows
$current_row;
for($current_row = 0; $current_row < $full_rows; $current_row++)
{
$base_insert .= '<tr>';
$current_column;
for($current_column = 0; $current_column < $width; $current_column++)
{
$base_insert .= '<td><center>';
$ImageNumber = ($current_row * $width) + $current_column;//Calculate image position in array
$ImageData = $images[$current_gallery][$ImageNumber];
$ImageDirectory = $ImageData[3];
$ThumbSource = $img_dir.'/thumbs/th_'.$ImageData[0];
$ImageTitle = $ImageData[2];
//Start the replacing
$thumb_temp = str_replace("IMAGE_DIRECTORY", $ImageDirectory, $thumb_temp);
$thumb_temp = str_replace("IMAGE_TITLE", $ImageTitle, $thumb_temp);
$thumb_temp = str_replace("THUMB_SOURCE", $ThumbSource, $thumb_temp);
$thumb_temp = str_replace("SLIDE_NUMBER", $ImageNumber, $thumb_temp);
$thumb_temp = str_replace("IMAGE_FILENAME", $ImageData[0], $thumb_temp);
$base_insert .= $thumb_temp;
$base_insert = str_replace("GALLERY_TITLE", str_replace("/", " -> ", $ImageDirectory), $base_insert);
$base_insert .= '</center></td>';
$thumb_temp = $thumb_temp_base;//Revert thumbnail template for next generation
}
$base_insert .= '</tr>';
}
if($extra_images > 0)//Slightly modified generation for incomplete image rows
{
$current_row = $full_rows;
$base_insert .= '<tr>';
for($current_column = 0; $current_column < $extra_images; $current_column++)
{   //The difference is right ^here^. I'm ashamed to have this as a separate block of code.
$base_insert .= '<td><center>';
$ImageNumber = ($current_row * $width) + $current_column;
$ImageData = $images[$current_gallery][$ImageNumber];
$ImageDirectory = $ImageData[3];
$ThumbSource = $img_dir.'/thumbs/th_'.$ImageData[0];
$ImageTitle = $ImageData[2];
$thumb_temp = str_replace("IMAGE_DIRECTORY", $ImageDirectory, $thumb_temp);
$thumb_temp = str_replace("IMAGE_TITLE", $ImageTitle, $thumb_temp);
$thumb_temp = str_replace("THUMB_SOURCE", $ThumbSource, $thumb_temp);
$thumb_temp = str_replace("SLIDE_NUMBER", $ImageNumber, $thumb_temp);
$thumb_temp = str_replace("IMAGE_FILENAME", $ImageData[0], $thumb_temp);
$base_insert .= $thumb_temp;
$base_insert = str_replace("GALLERY_TITLE",  str_replace("/", " -> ", $ImageDirectory), $base_insert);
$base_insert .= '</center></td>';
$thumb_temp = $thumb_temp_base;
}
$base_insert .= '</tr>';
}
$base_insert .= '</table>';
$base_insert .= '<p>-----------------------------------</p>';
}
//Perform Substitution
$template = str_replace("SECTION_TITLE", "Visual", $template);
$template = str_replace('&nbsp;_<a href="visual.php">Visual</a><br />', '&nbsp;#<strong>Visual</strong><br />', $template);
$base = str_replace("IMAGE_GALLERY", $base_insert, $base);
//Print
print(str_replace("PAGE_CONTENT", $base, $template));
?>
</pre>
Along with the file ''base_visual.html'':<br />
<pre>
IMAGE_GALLERY
</pre>
And ''template.html'':<br />
<pre>
<<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="icon" type="image/png" href="0.png" />
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <title>
      Welcome to The Void ~::~ SECTION_TITLE
    </title>
  </head>
  <body>
    <table align="center" cellspacing="10" cellpadding="0" width="760" class="maintable">
      <tr>
        <th colspan="2" class="header">
          <img src="null_Void.png" alt="null_Void" />
        </th>
      </tr>
      <tr>
        <td width="190" valign="top" rowspan="2" class="sidebar">
          <div align="center">
            <p>
              Navigation
            </p>
            <p align="left">
              _<a href="home.php">Home</a><br />
            </p>
            <p align="left">
              Galleries:<br />
              _<a href="visual.php">Visual</a><br />
              _<a href="composition.php">Composition</a><br />
              _<a href="programming.php">Programming</a>
            </p>
            <p align="left">
              _<a href="blog.php">Blog</a><br />
              _<a href="about.php">About</a><br />
              _<a href="links.php">Links</a>
            </p>
            <p>
              <a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0 Transitional</a>
            </p>
          </div>
        </td>
        <td width="570" valign="top" class="content">
          <div align="center">
            <p>
              -----------------------------------
            </p>
            <p>
              --SECTION_TITLE--
            </p>PAGE_CONTENT
          </div>
        </td>
      </tr>
      <tr>
        <td valign="bottom" class="footer">
          © 2006 - 2010, All Rights Reserved.
        </td>
      </tr>
    </table>
  </body>
</html>
</pre>
<div id="box">
  <div align="center" style="background:#eee;border:1px solid #ccc;padding:6px;" class="licensebox">
  <!-- Creative Commons License -->
  [http://creativecommons.org/licenses/GPL/2.0/ [[Image:Cc-GPL-a.png|CC-GNU GPL]]]
  <br />
  This software is licensed under the [http://creativecommons.org/licenses/GPL/2.0/ CC-GNU GPL].
  <!-- /Creative Commons License -->
  <!--
    <rdf:RDF xmlns="http://web.resource.org/cc/"
      xmlns:dc="http://purl.org/dc/elements/1.1/"
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <Work rdf:about="">
        <license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" />
        <dc:type rdf:resource="http://purl.org/dc/dcmitype/Software" />
      </Work>
      <License rdf:about="http://creativecommons.org/licenses/GPL/2.0/">
        <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
        <permits rdf:resource="http://web.resource.org/cc/Distribution" />
        <requires rdf:resource="http://web.resource.org/cc/Notice" />
        <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
        <requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
        <requires rdf:resource="http://web.resource.org/cc/SourceCode" />
      </License>
    </rdf:RDF>
  -->
  </div>
</div>
== Notes ==
* *Title tentative

Latest revision as of 21:32, 10 May 2008

About

Programmer, photographer, musician, chemist.

Programs in:

  • Python
  • PHP
  • LSL
  • Javascript