Zur Boardunity Forenstartseite

Zurück   Boardunity & Video Forum » Temporäre Foren » CalitrixWiki Supportforum

Antwort
 
LinkBack Themen-Optionen Thema bewerten
  #1  
Alt 23.04.2005, 09:10
Benutzerbild von Björn
Boardunity Team
 
Registriert seit: 10.2003
Ort: Rhode
Beiträge: 1.205

Plugin: thumbnail erstellen


Ich habe ja bereits ein plugin programmiert, um ein thumb anzuzeigen und dann eine seite oder grafik mit zu verlinken
daraus kam mir die idee, ein script zu erstellen, welches mir automatisch ein thumbnail erstellt und dies auf dem server auch speichert!

syntax:
Code:
{genthumb link="http://www.server.de/bild.jpg" target="_blank" maxheight="200" maxwidth="200"}
link: wird aufjeden fall benötigt, link zur jpg grafik!
target: optional, in welchem fenster die grafik geöffnet werden soll
maxheight: höhe des thumbs, optional, maximalwert kann im plugin auch noch mal difiniert werden als default werd
maxwidth: wie maxheight, nur für die breite des bildes

tja das wars alles schon, ihr müsst dann ein verzeichnis anlegen, in dem die bilder auf eurem server gespeichert werden sollen, mit chmod rechten 0777 versehen.. das wars eigentlich schon.

die thumbs haben namen, welche etwa so aussehen:

"www_server_de_bild_BREITE_HÖHE.jpg" (breite und höhe sind zahlenwerte)#
so kann man sehen, woher die orginal grafik kommt, und man kann die grafik mehrmals als thumb einbinden, zb in unterschiedlicher größe

in dem plugin müsst ihr folgene zeilen anpassen:
PHP-Code:
  var $dir_to_save_thumbs 'C:\Programme\Apache Group\Apache2\htdocs\knight\thumbs';
  var 
$dir_relativ_to_thumbs 'thumbs'
das wars dann eigentlich auchs chon.. nun aber das plugin:

/plugins/plugin_genthumb.php

PHP-Code:
<?PHP
/*
* CalitrixWiki (c) Copyright 2004 by Johannes Klose
* E-Mail: [email protected]
* Project page: http://developer.berlios.de/projects/calitrixwiki
*
* CalitrixWiki is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CalitrixWiki 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.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CalitrixWiki; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
**/

/**
* This is the "thumb"-plugin. Link a pic and shows a thumb, if thumb doesnt exists, it will be create
*
* @author Björn Klein <[email protected]>
* @since 1.0 Beta 3 08.04.05 16:33
**/


/**
* Plugin class.
*
* @author Björn Klein <[email protected]>
* @since 1.0 Beta 3 08.04.05 16:33
**/
class plugin_genthumb {
  
// anpassen!!
  
var $dir_to_save_thumbs 'C:\Programme\Apache Group\Apache2\htdocs\knight\thumbs';
  var 
$dir_relativ_to_thumbs 'thumbs';
  
  
// default values, dont change if you dont know what you do
  
var $name ''// should the thumbs a prefix like "thumb_" then enter hier "thumb_"
  
var $maxwidth 100;
  var 
$maxheight 100;
  var 
$pageText '';
  var 
$download_tmp true;
  function 
plugin_genthumb(&$params)
  {
    if(!isset(
$params['link'])) {
      return;
    }
    if(isset(
$params['maxwidth'])) $this->maxwidth intval($params['maxwidth']);
    if(isset(
$params['maxheight'])) $this->maxheight intval($params['maxheight']);
    
    
$this->name($params['link']);
    if(!
file_exists($this->dir_to_save_thumbs.'/'.$this->name)) {
      if(!
$this->download_tmp($params['link'])) return; // file doesnt exists, sry guys
      
      
$this->resize();  
      
$this->del_tmp();    
    }
    
$this->pageText '<a href="'.$params['link'].'" alt="'.$params['link'].'"'.((isset($params['target']))?' target="'.$params['target'].'"':'').'><img src="'.$this->dir_relativ_to_thumbs.'/'.$this->name.'" border="0"></a>';

  }
  function 
download_tmp($link) {
    
$tmp implode('',file($link));
    if(!
$tmp) {   return false;    }
    
    
$this->download_tmp $this->dir_to_save_thumbs.'\tmp_file_from_script_will_delete_soon';
    if(!
$fp fopen($this->download_tmp,"w")) die("KANN NICHT ÖFFNEN!!!$this->download_tmp");
    
fwrite($fp,$tmp);
    
fclose($fp);
    
chmod($this->download_tmp,0666);
    return 
true;    
  }
  function 
del_tmp() {
    
unlink($this->download_tmp);
    return;
  }
  function 
resize() {
    
$size getimagesize($this->download_tmp);
    
    
$tb $this->maxwidth;
    
    
$w $size[0];
    
$h $size[1];
    
$p_w $w 100;
    
$p2_w $tb $p_w// 19,53125
    
$p_h $h 100;
    
$p2_h $p_h $p2_w;
    
$th round ($p2_h);
    if(
$th $this->maxheight) {
      
$th $this->maxheight;
      
$p_w $w 100;
      
$p_h $h 100;
      
$p2_h $th $p_h;
      
$p2_w $p_w $p2_h;
      
$tb round($p2_w);
    }
    
$src_img imagecreatefromjpeg($this->download_tmp);
    
$dst_img imagecreatetruecolor($tb,$th);
    
imagecopyresized($dst_img,$src_img,0,0,0,0,$tb,$th,imagesx($src_img),imagesy($src_img));
    
imagejpeg($dst_img$this->dir_to_save_thumbs.'/'.$this->name);
    
chmod($this->dir_to_save_thumbs.'/'.$this->name,0666);
  }
  function 
name($link) {
    
$pos strrpos($link,'.');
    
$ext substr($link,$pos);
    
$link substr($link,0,$pos);
    
$this->name .= str_replace(array('http://','.','/'),array('','_','_'),$link).'_'.$this->maxwidth.'_'.$this->maxheight.$ext
    return;  
  }
  function 
getContent()
  {
    return 
$this->pageText;
  }


}
?>
Diese klasse ist für CalitrixWiki 1.0 Beta 3, dafür bzw danach geb ich keine garantie, dass sie funktioniert, einfach testen.
probiert sie mal aus
mfg
__________________
Björn C. Klein
Welt-Held!
PunkRockNews.de
Antwort


Stichworte
-


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.
Gehe zu






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