WinFuture-Forum.de: Bild Anzeigen Geht Nicht? - WinFuture-Forum.de

Zum Inhalt wechseln

Nachrichten zum Thema: Entwicklung
Seite 1 von 1

Bild Anzeigen Geht Nicht?


#1 Mitglied ist offline   -=[Mad]=- 

  • Gruppe: aktive Mitglieder
  • Beiträge: 61
  • Beigetreten: 05. Juli 05
  • Reputation: 0

geschrieben 05. Juli 2005 - 18:26

hallo php freaks,

ich zerbreche mir grade den kopf und komme alleine nicht weiter.

ich möchte eine Bildergalerie mit resize funktion erstellenn und arbeite da nach einer anleitung. nun mein problem:

mache ich alles so wie beschrieben wurde klappt alles wunderbar, nur das layout is gleich 0.

knusper ich die php anweisung aber in eine html tabelle, bekomme ich nur noch den ASCII code angezeigt und das ist wie man sich vorstellen kann wehniger schön

hier der originalcode:in der "class.Thumbnail.php" ist fesgelegt wie das resizen von statten gehen soll.

<?
include("../class.Thumbnail.php");
$tn_image = new Thumbnail("sample.jpg", 0, 200, 0);
$tn_image->show();
?>


und hier meiner in ner tabelle:
<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="middle">
<?
include("../class.Thumbnail.php");
$tn_image = new Thumbnail("sample.jpg", 0, 200, 0);
$tn_image->show();
?>
</td>
</tr>
</table>


und zuguter letzt hab ich das so noch mal probiert, weil es später als arry laufen soll mit mehreren datensätzen:

<?
include("../class.Thumbnail.php");
$tn_image = new Thumbnail("sample.jpg", 0, 200, 0);

echo '<table width="100%" height="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="middle">$tn_image->show();</td>
  </tr>
</table>';
?>


das geht aber garnicht, die ausgabe is lediglich( $tn_image->show(); ) ausgegeben

ich verzweifle bald könnte mir jemand weiterhelfen, allein pack ich das nicht.

gruss

-=[Mad]=-
0

Anzeige



#2 _PelzigesWaldtier_

  • Gruppe: Gäste

geschrieben 05. Juli 2005 - 18:36

Moin,

du muss, wenn du ein Bild anzeigen willst, schon den img-Tag verwenden und nicht die Daten so roh auszugeben. Dazu speicherst du dein durch die Klasse erzeugtes Bild ab und fuegst es dann per img-Tag ein.

Gruesse,
PelzigesWaldtier
0

#3 Mitglied ist offline   -=[Mad]=- 

  • Gruppe: aktive Mitglieder
  • Beiträge: 61
  • Beigetreten: 05. Juli 05
  • Reputation: 0

geschrieben 05. Juli 2005 - 18:44

das hatte ich auch schon ausprobiert mit dem code:
 <?
include("../class.Thumbnail.php");
$tn_image = new Thumbnail("sample.jpg", 0, 200, 0);

echo '<table width="100%" height="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="middle"><img src="$tn_image"></td>
  </tr>
</table>';
?>


geht aber nicht.

aber warum geht die direkt ausgabe im 1. beispiel?

hier mal der code aus der class.Tumbnai.php zum nachvolziehen was ich meine.
<?
/*
 * class.Thumbnail.php
 *
 * Copyright (C) 2001 - 2005 Hidayet Dogan
 *
 * http://www.hido.net/projects/phpThumbnailer
 *
 * This program 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, or (at your option)
 * any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

class Thumbnail {
    var $errmsg     = "";
    var $error     = false;
    var $format     = "";
    var $file     = "";
    var $max_width  = 0;
    var $max_height = 0;
    var $percent    = 0;

    function Thumbnail($file, $max_width = 0, $max_height = 0, $percent = 0) {
	if (!file_exists($file)) {
     $this->errmsg = "File doesn't exists";
     $this->error  = true;
	}
	else if (!is_readable($file)) {
     $this->errmsg = "File is not readable";
     $this->error  = true;
	}

	if (strstr(strtolower($file), ".gif"))
     $this->format = "GIF";
	else if (strstr(strtolower($file), ".jpg") ||
   strstr(strtolower($file), ".jpeg"))
     $this->format = "JPEG";
	else if (strstr(strtolower($file), ".png"))
     $this->format = "PNG";
	else {
     $this->errmsg = "Unknown file format";
     $this->error  = true;
	}

	if ($max_width == 0 && $max_height == 0 && $percent == 0)
     $percent = 100;

	$this->max_width  = $max_width;
	$this->max_height = $max_height;
	$this->percent   = $percent;
	$this->file   = $file;
    }

    function calc_width($width, $height) {
	$new_width  = $this->max_width;
	$new_wp     = (100 * $new_width) / $width;
	$new_height = ($height * $new_wp) / 100;
	return array($new_width, $new_height);
    }

    function calc_height($width, $height) {
	$new_height = $this->max_height;
	$new_hp     = (100 * $new_height) / $height;
	$new_width  = ($width * $new_hp) / 100;
	return array($new_width, $new_height);
    }

    function calc_percent($width, $height) {
	$new_width  = ($width * $this->percent) / 100;
	$new_height = ($height * $this->percent) / 100;
	return array($new_width, $new_height);
    }

    function return_value($array) {
	$array[0] = intval($array[0]);
	$array[1] = intval($array[1]);
	return $array;
    }

    function calc_image_size($width, $height) {
	$new_size = array($width, $height);

	if ($this->max_width > 0) {
     $new_size = $this->calc_width($width, $height);

     if ($this->max_height > 0) {
  if ($new_size[1] > $this->max_height)
      $new_size = $this->calc_height($new_size[0], $new_size[1]);
     }

     return $this->return_value($new_size);
	}

	if ($this->max_height > 0) {
     $new_size = $this->calc_height($width, $height);
     return $this->return_value($new_size);
	}

	if ($this->percent > 0) {
     $new_size = $this->calc_percent($width, $height);
     return $this->return_value($new_size);
	}
    }

    function show_error_image() {
	header("Content-type: image/png");
	$err_img   = ImageCreate(220, 25);
	$bg_color  = ImageColorAllocate($err_img, 0, 0, 0);
	$fg_color1 = ImageColorAllocate($err_img, 255, 255, 255);
	$fg_color2 = ImageColorAllocate($err_img, 255, 0, 0);
	ImageString($err_img, 3, 6, 6, "ERROR:", $fg_color2);
	ImageString($err_img, 3, 55, 6, $this->errmsg, $fg_color1);
	ImagePng($err_img);
	ImageDestroy($err_img);
    }

    function show($name = "") {
	if ($this->error) {
     $this->show_error_image();
     return;
	}

	$size      = GetImageSize($this->file);
	$new_size  = $this->calc_image_size($size[0], $size[1]);
	#
	# Good idea from Mariano Cano Pérez
	# Requires GD 2.0.1 (PHP >= 4.0.6)
	#
	if (function_exists("ImageCreateTrueColor"))
     $new_image = ImageCreateTrueColor($new_size[0], $new_size[1]);
	else
     $new_image = ImageCreate($new_size[0], $new_size[1]);

	switch ($this->format) {
     case "GIF":
  $old_image = ImageCreateFromGif($this->file);
  break;
     case "JPEG":
  $old_image = ImageCreateFromJpeg($this->file);
  break;
     case "PNG":
  $old_image = ImageCreateFromPng($this->file);
  break;
	}

	ImageCopyResized($new_image, $old_image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);

	switch ($this->format) {
     case "GIF":
  if (!empty($name))
      ImageGif($new_image, $name);
  else {
      header("Content-type: image/gif");
      ImageGif($new_image);
  }
  break;
     case "JPEG":
  if (!empty($name))
      ImageJpeg($new_image, $name);
  else {
      header("Content-type: image/jpeg");
      ImageJpeg($new_image);
  }
  break;
     case "PNG":
  if (!empty($name))
      ImagePng($new_image, $name);
  else {
      header("Content-type: image/png");
      ImagePng($new_image, $name);
  }
  break;
	}

	ImageDestroy($new_image);
	ImageDestroy($old_image);
	return;
    }

    function save($name) {
	$this->show($name);
    }
}
?>


hab die skripte mal mit bei gelegt.

Dieser Beitrag wurde von -=[Mad]=- bearbeitet: 05. Juli 2005 - 18:51

0

Thema verteilen:


Seite 1 von 1

1 Besucher lesen dieses Thema
Mitglieder: 0, Gäste: 1, unsichtbare Mitglieder: 0