Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Thumbnails erzeugen

Empfohlene Antworten

Veröffentlicht

Folgender Code sollte mir eigentlich ein Image aus meiner DB ziehen und ein Thumbnail daraus erzeugen. Das Image kann er auslesen, jedoch scheint im markierten Bereich etwas nicht zu stimmen :( Wenn ich den weglasse läuft es, aber dann habe ich ja den Thumbnaileffekt nicht.


<?php




if(!isset($Id))
{
die("Need 'Id' parameter");
} else
{
$Id=addslashes($Id);
}

include("common.php");


//set up SQL connection
$link = mysql_connect ($server, $user, $password);
if (! $link)
{
die ("Couldn't connect to mySQL server");
}
if (!mysql_select_db ($db, $link) )
{
die ("Coldn't open $db: ".mysql_error() );
}


$query = "SELECT filetype, bin_data FROM tbl_Files WHERE id_files='$Id';";
$result = mysql_query($query);


$query_data = mysql_fetch_array($result);
$bin_data = $query_data[bin_data];
$filetype = $query_data[filetype];

//Beginn des fehlerhaften Bereiches $tmp = ImageCreateFromString

($bin_data);
$image_w = imageSX($tmp);
$image_h = imageSY($tmp);
$new_w = $max_size;
$ratio = ($image_w/$new_w);
$new_h = ($image_h/$ratio);
$out = @ImageCreateTrueColor($new_w, $new_h);//Note: This function was added in PHP 4.0.6 and requires GD 2.0.1 or later
if (!$out) { $out = imageCreate($new_w, $new_h); } //imagecreate kicks in if imagecreatetruecolor could not create the image
//copy the original image info into the new image with new dimensions
//checking to see which function is available
if (function_exists("imageCopyResampled"))
{
if (!@ImageCopyResampled($out, $tmp, 0, 0, 0, 0, $new_w, $new_h, $image_w, $image_h))
ImageCopyResized($out, $tmp, 0, 0, 0, 0, $new_w, $new_h, $image_w, $image_h);
}
else
ImageCopyResized($out, $tmp, 0, 0, 0, 0, $new_w, $new_h, $image_w, $image_h);
if (imageColorExact($out,255,255,255)!=-1)
{
$white=ImageColorAllocate($out,255,255,255);
}
else
{
$white=imageColorClosest($out,255,255,255);
}
if (imageColorExact($out,0,0,0)!=-1)
{
$black=ImageColorAllocate($out,0,0,0);
}
else
{
$black=imageColorClosest($out,0,0,0);
}
//this part adds the string in the lower right hand corner
//comment them out if you don't want to use them
//otherwise make sure you define $smallImageImprint in common.php
//or pass along as a parameter when you call this file
imageString($out,1,$new_w-($max_size/2),$new_h-8,"$smallImageImprint",$black);
imageString($out,1,$new_w-($max_size/2)-1,$new_h-9,"$smallImageImprint",$white);

//Ende des fehlerhaften Bereiches

Header("Content-type: $filetype");
imageJPEG($out);
imageDestroy($out);
?>
[/PHP]

Fehlermeldung:

Warning: Division by zero in thumbnail_img.php on line 37

Warning: Division by zero in thumbnail_img.php on line 38

also

$image_w = imageSX($tmp);

$image_h = imageSY($tmp);

Aber er liest das Image doch aus, oder nicht?

Hat jemand eine Idee? Liegt es an der GD Version? Hier der Auszug aus phpinfo:

gd

GD Support enabled

GD Version bundled (2.0.28 compatible)

FreeType Support enabled

FreeType Linkage with freetype

GIF Read Support enabled

GIF Create Support enabled

JPG Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

Thx, 2-helpless

Hi!

Ohne jetzt den ganzen Code ausprobiert zu haben, aber ich denke der Interpreter meckert diese Zeilen an:


$new_w = $max_size;
$ratio = ($image_w/$new_w);
$new_h = ($image_h/$ratio);
[/PHP]

Und "Division by Zero" weil $max_size nicht existiert, also faktisch 0 ist.

Gruß, Tobias

einfach ma mit error_reporting(E_ALL) ausprobieren und zwischendrinn schritt für schritt ein exit machen. dann siehste auch warnungen/fehler etc.

  • Autor

...das kommt davon, wenn man bis spät in die Nacht probiert .. Tobi hatte recht. Das Problem war .. ich suchte schon seit Wochen nach dem Script und als ich es endlich fand, fehlten dort die Hinweise auf das setzen der gemeinsamen Variablen ... nun funzt es 1a.

Thx a lot

  • 4 Wochen später...

hmpf, ich habe auf neues Thema geklickt nicht auf Antworten...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.