php.de

Zurück   php.de > php.de Intern > Beitragsarchiv

Beitragsarchiv Nur gucken, nichts anfassen. Das Archiv der Beiträge vergangener Zeiten.

 
 
LinkBack Themen-Optionen
Alt 21.04.2005, 16:05  
Erfahrener Benutzer
 
Registriert seit: 02.08.2004
Beiträge: 472
duderino
Standard SMARTY Thumbnail Plugin

Hallo, wie der Titel schon sagt bin ich auf der Suche nach einem Smarty Plugin das Thumbs von Bildern erstellt. Es gibt auf jedenfall so ein nettes Plugin. Habe auf verschiedenen Seite Texte dazu gefunden aber nirgendwo nen Link zum Downloaden.

http://www.cerdmann.com/senf/?id=69

Auch auf der offiziellen Smarty Seite konnte ich unter den Plugins nichts finden.

http://smarty.incutio.com/?page=SmartyPlugins

Vielleicht hat jemand das Plugin auf seinem Rechner rumliegen oder kennt einen Link.

Gruß
duderino

PS: Auch google konnte keine konkreten Ergebnisse liefern.
duderino ist offline  
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 21.04.2005, 16:19  
Erfahrener Benutzer
 
Registriert seit: 02.08.2004
Beiträge: 472
duderino
Standard

Hab hier ein bisschen Quellcode gefunden:

PHP-Code:
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/


/**
* Smarty {my_html_thumb_image} function plugin
*
* Type:     function

* Name:     my_html_thumb_image

* Date:     Feb 24, 2003

* Purpose:  format HTML tags for the image

* Input:

*         - file = file (and path) of image (required)
*         - border = border width (optional, default 0)
*         - height = image height (optional, default actual height)
*         - image =image width (optional, default actual width)
*         - basedir = base directory for absolute paths, default
*                     is environment variable DOCUMENT_ROOT
*
* Examples: {my_html_thumb_image file="images/masthead.gif"}
* Output:   [img]images/masthead.gif[/img]
* @author   Markus Staab <kills@t-online.de>
*
* @version  1.0
* @param array
* @param Smarty
* @return string
* @uses smarty_function_escape_special_chars()
*/
function smarty_function_my_html_thumb_image($params, &$smarty)
{
   
    if (!
extension_loaded('gd')) {
      
trigger_error'my_html_thumb_image: gd-extension not loaded!');
      return;
    }
    
    
    require_once 
$smarty->_get_plugin_filepath('shared','escape_special_chars');
    
    
$alt '';
    
$file '';
    
$border 0;
    
$height '';
    
$maxheight 0;
    
$width '';
    
$maxwidth 0;
    
$extra '';
    
$prefix '';
    
$suffix '';
    
$server_vars = ($smarty->request_use_auto_globals) ? $_SERVER $GLOBALS['HTTP_SERVER_VARS'];
    
$basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
    
$thumb_dir 'images/thumbnails/';
    foreach(
$params as $_key => $_val) {
        switch(
$_key) {
            case 
'file':
            case 
'border':
            case 
'height':
            case 
'maxheight':
            case 
'width':
            case 
'maxwidth':
            case 
'dpi':
            case 
'basedir':
                $
$_key $_val;
                break;

            case 
'alt':
                if(!
is_array($_val)) {
                    $
$_key smarty_function_escape_special_chars($_val);
                } else {
                    
$smarty->trigger_error("my_html_thumb_image: extra attribute '$_key' cannot be an array"E_USER_NOTICE);
                }
                break;

            case 
'link':
            case 
'href':
                
$prefix '<a href="' $_val '">';
                
$suffix '</a>';
                break;

            default:
                if(!
is_array($_val)) {
                    
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
                } else {
                    
$smarty->trigger_error("my_html_thumb_image: extra attribute '$_key' cannot be an array"E_USER_NOTICE);
                }
                break;
        }
    }

    if (empty(
$file)) {
        
$smarty->trigger_error("my_html_thumb_image: missing 'file' parameter"E_USER_NOTICE);
        return;
    }

    if (
substr($file,0,1) == '/') {
        
$_image_path $basedir $file;
    } else {
        
$_image_path $file;
    }

    if(!isset(
$params['width']) && !isset($params['height'])) {
        
$smarty->trigger_error("my_html_thumb_image: missing 'width' or 'height' parameter"E_USER_ERROR);
        return;
    }
    
    if(!isset(
$params['width']) || !isset($params['height'])) {
        if (
$smarty->security &&
            (
$_params = array('resource_type' => 'file''resource_name' => $_image_path)) &&
            (require_once(
SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.is_secure.php')) &&
            (!
smarty_core_is_secure($_params$smarty)) ) {
            
$smarty->trigger_error("my_html_thumb_image: (secure) '$_image_path' not in secure directory"E_USER_ERROR);
        }
        
$oImg imageFactory :: getImage$file);
        
$thumb_dir .= $oImg->getFilePath();
        
        if(!isset(
$params['width'])) {
           
$oThumb $oImg->getThumbnail$thumb_dirnull$params['height']);
           
$width $oThumb->getWidth(); 
        }
        
        if(!isset(
$params['height'])) {
           
$oThumb $oImg->getThumbnail$thumb_dir$params['width'], null);
           
$height $oThumb->getHeight();
        }
        
        
$file $oThumb->getFile();
        
        unset( 
$oImg$oThumb);
    }

    if(isset(
$params['dpi'])) {
        if(
strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) {
            
$dpi_default 72;
        } else {
            
$dpi_default 96;
        }
        
$_resize $dpi_default/$params['dpi'];
        
$width round($width $_resize);
        
$height round($height $_resize);
    }

    return 
$prefix '[img]'.$file.'[/img]' $suffix;
}

// Image-Basis-Objekt
class image {
   var 
$sFile;
   var 
$oImage null;

   function 
Image($sFile) {
      
$this->sFile $sFile;
      
$this->oImage $this->getResource();
      
$this->validateFile();
   }
   
   function 
validateFile() {
      if ( !
$this->getResource()) {
         
$sFile $this->getFile();
         if( !
file_exists$sFile)) {
             
trigger_error("unable to find '$sFile'"E_USER_ERROR);
         } else if( !
is_readable$sFile)) {
             
trigger_error("unable to read '$sFile'"E_USER_ERROR);
         } else {
             
trigger_error("'$sFile' is not a valid image file"E_USER_ERROR);
         }
      }
   }
   
   function 
unsupportedImage() {
      
trigger_error("Unsupported imageformat! File: '"$this->getFile() ."'"E_USER_ERROR);
   }

   function 
getResource() {
      
$this->unsupportedImage();
   }

   function 
getHeight() {
      return 
imagesy($this->getResource());
   }

   function 
getWidth() {
      return 
imagesx($this->getResource());
   }

   function 
getFile() {
      return 
$this->sFile;
   }

   function 
getFileName() {
      return 
substr($this->getFile(), strrpos($this->getFile(), '/') + 1strrpos($this->getFile(), '.') - 1);
   }
   
   function 
getFilePath() {
      return 
substr($this->getFile(), 0strrpos($this->getFile(), "/") + );
   }
   
   function 
getFileSuffix() {
      return 
strrchr($this->getFile(), '.');
   }

   function 
getImage() {
      
$this->unsupportedImage();
   }

   function 
saveImage() {
      
$this->unsupportedImage();
   }

   function 
getThumbnail($sDestination$iWidth null$iHeight null) {
      if (
$sDestination strlen($sDestination) - } != "/"$sDestination .= "/";
      
      
$iImgWidth $this->getWidth();
      
$iImgHeight $this->getHeight();
      
      
// Ordnerstruktur anlegen
      
$this->makedir($sDestination);

      if (
$iImgHeight $iImgWidth) {
         
// Hochkanntbilder proportional verkleinern
         
$iHeight $iWidth;
         
$iWidth null;
      }

      if ((
is_null($iWidth) && is_null($iHeight)) || ($iImgWidth <= $iWidth && $iImgHeight <= $iHeight)) {
         
// Weder Höhe noch Breite wurden angegeben oder
         // Die Höhe und Breite des Original Images ist schon kleiner als das Thumbnail das erstellt würde
         
return $this;
      } else if (
is_null($iWidth)) {
         
// Breite wurde angegebene, dazu die Höhe errechen
         
$iWidth round(($iImgWidth $iImgHeight) * $iHeight);
      } else if (
is_null($iHeight)) {
         
// Höhe wurde angegeben, dazu die Breite errechnen
         
$iHeight round(($iImgHeight $iImgWidth) * $iWidth);
      }
      
      
$sFileDestination $sDestination $this->getFileName() .'_'$iWidth .'x'$iHeight $this->getFileSuffix();
      
      
// Wenn schon ein thumbnail vorhanden ist, den Pfad zu diesem zurückgeben
      
if ( file_exists$sFileDestination)) {
         return 
imageFactory :: getImage($sFileDestination);
      }
      
      
$oSrcImg $this->getResource();
      
$oThumbnail imagecreatetruecolor($iWidth$iHeight);
      
imagecopyresized($oThumbnail$oSrcImg0000$iWidth$iHeight$iImgWidth$iImgHeight);

      
$this->saveImage ($oThumbnail$sFileDestination);

      return 
imageFactory :: getImage($sFileDestination);
   }
   
   function 
makedir($sDir) {
      
$aDir explode("/"$sDir);
      
$sParentDir "";
      
      foreach (
$aDir as $sDirPart) {
         if ( 
$sDirPart == "") continue;
         
         
$sCurrentDir $sParentDir $sDirPart "/";
         
         if (!
is_dir($sCurrentDir)) {
            
mkdir($sCurrentDir);
         }
         
         
$sParentDir $sCurrentDir;
      }
   }
}


// GIF-Format Objekt
class imageGif extends image {
   function 
getResource() {
      if (
is_null($this->oImage)) {
         
$this->oImage = @imagecreatefromgif($this->getFile());
      }

      return 
$this->oImage;
   }

   function 
getImage() {
      return 
imagegif($this->getResource(), $this->getFile());
   }

   function 
saveImage($oImage$sDestination) {
      
imagegif($oImage$sDestination);
   }
}


// JPG-Format Objekt
class imageJpg extends image {
   function 
getResource() {
      if (
is_null($this->oImage)) {
         
$this->oImage = @imagecreatefromjpeg($this->getFile());
      }

      return 
$this->oImage;
   }

   function 
getImage() {
      return 
imagejpeg($this->getResource(), $this->getFile());
   }

   function 
saveImage($oImage$sDestination) {
      
imagejpeg($oImage$sDestination);
   }
}


// PNG-Format Objekt
class imagePng extends image {
   function 
getResource() {
      if (
is_null($this->oImage)) {
         
$this->oImage = @imagecreatefrompng($this->getFile());
      }

      return 
$this->oImage;
   }

   function 
getImage() {
      return 
imagepng($this->getResource(), $this->getFile());
   }

   function 
saveImage$oImage$sDestination) {
      
imagepng($oImage$sDestination);
   }
}

// Factory zum erstellen von Image-Objekten
class imageFactory {
   function 
getImage$sFileName) {
      
$sFileType substr(strrchr($sFileName"."), 1);

      switch (
$sFileType) {
         case 
"jpeg" :
         case 
"jpg"  : return new imageJpg($sFileName);
         case 
"gif"  : return new imageGif($sFileName);
         case 
"png"  : return new imagePng($sFileName);

         default     : return new 
image($sFileName);
      }
   }
}


/* vim: set expandtab: */ 
?>
duderino ist offline  
 


Themen-Optionen

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Kurze Einführung in Firefox Search Plugin Programmierung PTC Tutorials 5 10.02.2009 01:31
Smarty + MySQL = immer falsche Ausgabe m0use` PHP Tipps 2006 44 21.11.2008 20:30
Smarty: Templatedateien werden nicht aktualisiert! DER_Brain PHP Tipps 2008 9 24.04.2008 22:40
Was ist Aufgabe des Templates (Smarty), was nicht? agrajag PHP Tipps 2007 8 24.02.2007 13:19
Smarty => 1ste allgemeine Verunsicherung Canni PHP Tipps 2006 7 10.10.2006 17:56
Smarty + Oop Problem Komandar PHP Tipps 2006 5 25.07.2006 14:36
problem mit javascript und smarty snatch-ic HTML, Usability und Barrierefreiheit 2 08.06.2006 22:11
Smarty + Oop Komandar PHP Tipps 2006 17 30.05.2006 10:30
Smarty verschachtelt snatch-ic PHP Tipps 2006 16 28.02.2006 20:54
[Erledigt] Navigation auf Smarty umstellen?! PHP-Fortgeschrittene 3 10.01.2006 09:19
Smarty installiert und nun? Cyrus PHP Tipps 2005-2 5 28.10.2005 16:14
Smarty Error Simon9990 PHP Tipps 2005-2 8 07.07.2005 09:34
Smarty und X-Cart Profis gesucht Beitragsarchiv 1 21.05.2005 13:38
[Erledigt] includepathproblem pear blockiert smarty und umgekehrt PHP Tipps 2005 1 08.05.2005 18:46
array_push nur in begrenzter Anzahl ausführen ? PHP Tipps 2004 2 07.09.2004 09:05

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
smarty thumbnail, smarty thumb, smarty plugin, smarty thumbnails, smarty strstr, smarty image, smarty plugin thumb, thumbnail plugin, smarty thumbnail plugin, smarty imagepng, smarty plugins, smarty thumbnail function, smarty maxwidth, image width smarty, smarty img, smarty plugin thumbnail, smarty getimage, smarty thumb plugin, smarty picture php, strstr smarty

Alle Zeitangaben in WEZ +2. Es ist jetzt 04:12 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.