Difference between revisions of "User:Meyermagic Salome"

From Second Life Wiki
Jump to navigation Jump to search
Line 26: Line 26:


== Some code ==
== Some code ==
My PHP image gallery scripts:<br />
My Single-prim, scrollable Image Gallery:<br />
''config.php'':<br />
<pre>
<pre>
<?php
integer texture_count;
/*General Data*/
list textures;
//$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)
integer current = 0;
{
$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];
string str_repeat(string src, integer count)
$image_mimetype = image_type_to_mime_type($imagetype);
{
if(substr($image_mimetype, 6) == 'gif' || substr($image_mimetype, 6) == 'png' || substr($image_mimetype, 6) =='jpeg')
    string output;
{
    integer i;
    for(i = 0; i < count; i++)
//...add it to the image array
    {
if(!file_exists($dir.'/image_data/'.substr($object, 0, -3).'txt'))
        output += src;
{ //If there is no image data file, default display name to image name
    }
$image_displayname = substr($object, 0, -4);
    return output;
}
}
else
 
{
next()
$image_data = file_get_contents($dir.'/image_data/'.substr($object, 0, -3).'txt');
{
$image_displayname = explode($parseMark, $image_data);
    if(current < texture_count - 1)
$image_displayname = $image_displayname[0];
    {
}
        current++;
$image_array[$dir][filemtime($dir.'/'.$object)] = array($object, $image_mimetype, $image_displayname, $dir);
    }
    else
//Eventually, I'll have it call ksort or krsort, depending on preference
    {
krsort($image_array[$dir], SORT_NUMERIC);//Sort by date modified
        current = 0;
$image_array[$dir] = array_values($image_array[$dir]);//Renumber sorted array
    }
    llSetTexture(llList2String(textures, current), ALL_SIDES);
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);
prev()
create_thumb($dir.'/'.$object, $dir_array[0].'/thumbs/th_'.$object, $thumbX, $thumbY);
{
}
    if(current > 0)
else
    {
{
        current--;
$image_data = getimagesize($dir.'/thumbs/th_'.$object);
    }
if($image_data[0] != $thumbX || $image_data[1] != $thumbY)
    else
{ //Make sure the thumb, if there already was one, has the correct sizes
    {
unlink($dir.'/thumbs/th_'.$object);
        current = texture_count - 1;
$dir_array = explode('/', $dir);
    }
create_thumb($dir.'/'.$object, $dir_array[0].'/thumbs/th_'.$object, $thumbX, $thumbY);
    llSetTexture(llList2String(textures, current), ALL_SIDES);
}
}
}
 
}
//list image_data()
}
//{
//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
//    return [];
if(is_dir($dir.'/'.$object) && $object != 'thumbs' && $object != 'image_data' && $continue  && $object !='.' && $object != '..')
//}
{
 
$image_array += imagelist_create($dir.'/'.$object, false, $thumbX, $thumbY, $parseMark);
 
}
vector grab;
}
integer gc;
closedir($dh);
}
return $image_array;
}
?>
</pre>
Example usage in ''visual.php'':<br />
<pre>
<?php
include('config.php');


/*
default
Okie dokie. I still need to:
{
Add .bmp support to thumbnail generator
    state_entry()
Add unused thumbnail check
    {
Add additional thumbnail generation features
        texture_count = llGetInventoryNumber(INVENTORY_TEXTURE);
Alternate Center Cropping
        integer i;
Scale + Crop
        for(i = 0; i < texture_count; i++)
Rotate + Crop
        {
Thumbnail complexity check (Uses rotation and alternate center to assure thumbnail contains at least a given number of unique pixels)
            textures += [llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTURE, i))];
Add multiple sort setting
        }
Alphabetical
        llSetTexture(llList2String(textures, current), ALL_SIDES);
Date Modified
    }
User defined order preference
   
Try to find a way around the layered .png bug
    touch(integer num_detected)
<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
        grab = llDetectedGrab(0);
Find some way to deal with image titles longer than one thumbnail's width
        gc++;
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)
        float scroll = grab.x;
        //float shift = grab.y;
-As an unrelated note, don't forget the php optimizing script idea (I thought I might be in the programming mood after reading this)-
       
        float trans = scroll * (float)llPow(gc, 0.5);
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.  : )
        //float vtrans = shift * (float)llPow(gc, 0.5);
$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";
       
*/
        if(trans > 5.0)
        {
//Load Data
            next();
$base = implode("", file("base_visual.html"));
            gc = 0;
$template = implode("", file("template.html"));
        }
$thumb_temp_base = implode("", file("visual_thumbTemp.html"));
       
        if(trans < -5.0)
//Prepare table
        {
$base_insert = '';
            prev();
            gc = 0;
/*
        }
List Format:
       
$images[Gallery][Image_Number]
        trans = trans / 5.0;
Returns:
        string prev_char;
array(Image_Filename, Image_Type, Image_Displayname, Image_Gallery);
        string next_char;
*/
       
        if(trans > 0.0)
$images = array_values(imagelist_create($img_dir, true, $thumbXsize, $thumbYsize, $separator));
        {
$gallery_count = count($images);
            next_char = ">";
$current_gallery;
            prev_char = "|";
            trans = llFabs(trans);
            if(trans > 1.0)
            {
/*
                trans = 1.0;
Note for template-based configuration; visual.php currently parses the following terms as described after each one
            }
IMAGE_DIRECTORY - The path to the image
            llSetText(prev_char + str_repeat("-", (integer)(trans * 50)) + next_char + str_repeat("-", 50 - (integer)(trans * 50)) + "|", <1,1,1>, trans);
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'
        if(trans < 0.0)
IMAGE_FILENAME - The source image's filename
        {
GALLERY_TITLE - The current gallery in 'title form'; that is, the directory, with forward slashes, '/', replaced by '->'
            next_char = "|";
*/
            prev_char = "<";
            trans = llFabs(trans);
            if(trans > 1.0)
$thumb_temp = $thumb_temp_base;//Set working thumbnail template
            {
for($current_gallery = 0; $current_gallery < $gallery_count; $current_gallery++)
                trans = 1.0;
{ //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>';
            llSetText("|" + str_repeat("-", 50 - (integer)(trans * 50)) + prev_char + str_repeat("-", (integer)(trans * 50)) + next_char, <1,1,1>, trans);
$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++)
    touch_end(integer num_detected)
{
    {
$base_insert .= '<tr>';
        gc = 0;
$current_column;
        llSetText("", <1,1,1>, 10.0);
for($current_column = 0; $current_column < $width; $current_column++)
     }
{
      
$base_insert .= '<td><center>';
     changed(integer change)
$ImageNumber = ($current_row * $width) + $current_column;//Calculate image position in array
     {
$ImageData = $images[$current_gallery][$ImageNumber];
         if(change == CHANGED_INVENTORY)
$ImageDirectory = $ImageData[3];
         {
$ThumbSource = $img_dir.'/thumbs/th_'.$ImageData[0];
            key old = llList2Key(textures, current);
$ImageTitle = $ImageData[2];
            texture_count = llGetInventoryNumber(INVENTORY_TEXTURE);
             textures = [];
//Start the replacing
             integer i;
$thumb_temp = str_replace("IMAGE_DIRECTORY", $ImageDirectory, $thumb_temp);
             for(i = 0; i < texture_count; i++)
$thumb_temp = str_replace("IMAGE_TITLE", $ImageTitle, $thumb_temp);
             {
$thumb_temp = str_replace("THUMB_SOURCE", $ThumbSource, $thumb_temp);
                textures += [llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTURE, i))];
$thumb_temp = str_replace("SLIDE_NUMBER", $ImageNumber, $thumb_temp);
             }
$thumb_temp = str_replace("IMAGE_FILENAME", $ImageData[0], $thumb_temp);
             if((current = llListFindList(textures, [old])) == -1)
             {
$base_insert .= $thumb_temp;
                current = 0;
$base_insert = str_replace("GALLERY_TITLE", str_replace("/", " -> ", $ImageDirectory), $base_insert);
             }
$base_insert .= '</center></td>';
             llSetTexture(llList2String(textures, current), ALL_SIDES);
$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>
</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 ==
== Notes ==
* *Title tentative
* *Title tentative

Revision as of 14:15, 27 September 2007

About me

Name: Meyer S. Jacobs

Alias: Meyermagic, if(x), |-1|

Age: 472794735 as of 1175103075 (seconds since the Unix Epoch)

Avoids: Carbonated drinks, dressing up, political parties, organized religion

Is drawn to: Math, physics, technology, interesting people, old cartoons, sci-fi, anime, good books, things that spin, magnets, food

My plot in TG SL: TransGrid Corporation HQ🖈
My DeviantART Page: Meyermagic on DeviantART
My last.fm Page: Meyermagic's Music Profile

Projects

Perception - A four part story
⇒ Part One: The Crystals of Power
⇒ Part Two: The Tower Archive
⇒ Part Three: Perpetual*
⇒ Part Four: Transcend

The WeFiki - A next generation web protocol

null_Void - My personal site; not yet online

Some code

My Single-prim, scrollable Image Gallery:

integer texture_count;
list textures;

integer current = 0;

string str_repeat(string src, integer count)
{
    string output;
    integer i;
    for(i = 0; i < count; i++)
    {
        output += src;
    }
    return output;
}

next()
{
    if(current < texture_count - 1)
    {
        current++;
    }
    else
    {
        current = 0;
    }
    llSetTexture(llList2String(textures, current), ALL_SIDES);
}

prev()
{
    if(current > 0)
    {
        current--;
    }
    else
    {
        current = texture_count - 1;
    }
    llSetTexture(llList2String(textures, current), ALL_SIDES);
}

//list image_data()
//{
//    return [];
//}


vector grab;
integer gc;

default
{
    state_entry()
    {
        texture_count = llGetInventoryNumber(INVENTORY_TEXTURE);
        integer i;
        for(i = 0; i < texture_count; i++)
        {
            textures += [llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTURE, i))];
        }
        llSetTexture(llList2String(textures, current), ALL_SIDES);
    }
    
    touch(integer num_detected)
    {
        grab = llDetectedGrab(0);
        gc++;
        
        float scroll = grab.x;
        //float shift = grab.y;
        
        float trans = scroll * (float)llPow(gc, 0.5);
        //float vtrans = shift * (float)llPow(gc, 0.5);
        
        if(trans > 5.0)
        {
            next();
            gc = 0;
        }
        
        if(trans < -5.0)
        {
            prev();
            gc = 0;
        }
        
        trans = trans / 5.0;
        string prev_char;
        string next_char;
        
        if(trans > 0.0)
        {
            next_char = ">";
            prev_char = "|";
            trans = llFabs(trans);
            if(trans > 1.0)
            {
                trans = 1.0;
            }
            llSetText(prev_char + str_repeat("-", (integer)(trans * 50)) + next_char + str_repeat("-", 50 - (integer)(trans * 50)) + "|", <1,1,1>, trans);
        }
        
        if(trans < 0.0)
        {
            next_char = "|";
            prev_char = "<";
            trans = llFabs(trans);
            if(trans > 1.0)
            {
                trans = 1.0;
            }
            llSetText("|" + str_repeat("-", 50 - (integer)(trans * 50)) + prev_char + str_repeat("-", (integer)(trans * 50)) + next_char, <1,1,1>, trans);
            
        }
    }
    
    touch_end(integer num_detected)
    {
        gc = 0;
        llSetText("", <1,1,1>, 10.0);
    }
    
    changed(integer change)
    {
        if(change == CHANGED_INVENTORY)
        {
            key old = llList2Key(textures, current);
            texture_count = llGetInventoryNumber(INVENTORY_TEXTURE);
            textures = [];
            integer i;
            for(i = 0; i < texture_count; i++)
            {
                textures += [llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTURE, i))];
            }
            if((current = llListFindList(textures, [old])) == -1)
            {
                current = 0;
            }
            llSetTexture(llList2String(textures, current), ALL_SIDES);
        }
    }
    
}

Notes

  • *Title tentative