Ed Lazor schrieb:
On Oct 30, 2006, at 12:52 AM, Martin Hochreiter wrote:
Hi!
I'm using imagecopyresampled to create thumbnails of
various pictures.
That works well except some pictures that imagecopyresampled
converts to small black thumbnails (although it converts it correctly
to a bigger size)
What is wrong here?
No idea off-hand, but it would probably help if you you included more
information like source code and details about the images that are not
working.
Hi Ed!
I added the upload.php file below and posted the nfs.jpg image file
on http://www.rk-lilienfeld.at/nfs.jpg
Maybe you can have a look at it .
lg
----------------------------- upload.php --------------------------------
<?php
function resize($image,$name,$dir)
{
// $height=0 ... quer
// $height=1 ... hoch
$ori = imagecreatefromjpeg($image);
$smaller=0;
$x=imagesx($ori);
$y=imagesy($ori);
echo "<br>x:".$x.", y:".$y."<br>";
if(imagesx($ori)>imagesy($ori))
{
if(imagesx($ori)<1024)
{
$smaller=1;
$faktor=imagesy($ori)/imagesx($ori);
$thumb = imagecreatetruecolor (150,150*$faktor);
// echo "<br>image: ".$image;
// echo "<br>aktdir: ".$dir."view/".$name;
if(!copy ($image,$dir."view/".$name))
{
imagedestroy($thumb);
imagedestroy($ori);
die("kopie 1 fehlgeschlagen");
}
# imagecopyresized ( $thumb, $ori, 0, 0, 0, 0,
150, round(150*$faktor,0), imagesx($ori), imagesy($ori));
imagecopyresampled ( $thumb, $ori, 0, 0, 0, 0,
150, round(150*$faktor,0), $x, $y);
}
else
{
$faktor=imagesy($ori)/imagesx($ori);
$new = imagecreatetruecolor (1024,1024*$faktor);
$thumb = imagecreatetruecolor (150,150*$faktor);
# imagecopyresized ( $new, $ori, 0, 0, 0, 0,
1024, round(1024*$faktor,0), imagesx($ori), imagesy($ori));
imagecopyresampled ( $new, $ori, 0, 0, 0, 0,
1024, round(1024*$faktor,0), imagesx($ori), imagesy($ori));
# imagecopyresized ( $thumb, $ori, 0, 0, 0, 0,
150, round(150*$faktor,0), imagesx($ori),
imagesy($ori)); imagecopyresampled (
$thumb, $ori, 0, 0, 0, 0, 150, round(150*$faktor,0), imagesx($ori),
imagesy($ori));
}
}
else
{
if(imagesy($ori)<768)
{
$smaller=1;
$faktor=imagesx($ori)/imagesy($ori);
$thumb = imagecreatetruecolor (112*$faktor,112);
if(!copy ($image,$dir."view/".$name))
{
imagedestroy($thumb);
imagedestroy($ori);
die("kopie 2 fehlgeschlagen");
}
# imagecopyresized ( $thumb, $ori, 0, 0, 0, 0,
round(112*$faktor,0),112, imagesx($ori), imagesy($ori));
imagecopyresampled ( $thumb, $ori, 0, 0, 0, 0,
round(112*$faktor,0),112, imagesx($ori), imagesy($ori));
}
else
{
$faktor=imagesx($ori)/imagesy($ori);
$new = imagecreatetruecolor (768*$faktor,768);
$thumb = imagecreatetruecolor (112*$faktor,112);
# imagecopyresized ( $new, $ori, 0, 0, 0, 0,
round(768*$faktor,0), 768, imagesx($ori), imagesy($ori));
imagecopyresampled ( $new, $ori, 0, 0, 0, 0,
round(768*$faktor,0), 768, imagesx($ori), imagesy($ori));
# imagecopyresized ( $thumb, $ori, 0, 0, 0, 0,
round(112*$faktor,0),112, imagesx($ori), imagesy($ori));
imagecopyresampled ( $thumb, $ori, 0, 0, 0, 0,
round(112*$faktor,0),112, imagesx($ori), imagesy($ori));
}
}
imagedestroy($ori);
if($smaller==0)
{
echo '<br>Ausgabebild: '.$dir.'view/'.$name;
imagejpeg($new,$dir.'view/'.$name,85);
imagedestroy($new);
}
echo '<br>Vorschaubild: '.$dir.'thumb/'.$name;
imagejpeg($thumb,$dir.'thumb/'.$name,100);
imagedestroy($thumb);
}
require('connect1.php');
require('inc_query.php');
if(isset($_FILES['userfile']['name']))
{
$name=time().'.jpg';
echo "<br>DEBUGINFORMATION:<br>";
echo "name:".$name."<br>";
echo "tmp name:".$_FILES['userfile']['tmp_name']."<br>";
if(move_uploaded_file($_FILES['userfile']['tmp_name'],'/srv/www/phpup/'.$name))
{
resize('/srv/www/phpup/'.$name,$name,'/srv/www/htdocs/aktuell/');
unlink('/srv/www/phpup/'.$name);
$erg=query($link,"update news set news_pic='".$name."'
where news_id=".$_REQUEST['id'].";");
echo '<div style="text-align:center">';
if(isset($_REQUEST['id']) && $_REQUEST['id']!='')
{
echo '<a
href="newsedit.php?id='.$_REQUEST['id'].'" target="_self">Weiter zur
Verarbeitung</href>';
}
else
{
echo '<a href="shownews.php" target="_self">Zur
Übersicht</href>';
}
echo '</div>';
}
else
{
echo "Fehler beim Upload!";
}
}
else $erg=query($link,"select max(news_id)+1 from news;");
$row=mysql_fetch_row($erg);
if(isset($_REQUEST['id']))
{
if($_REQUEST['pic']=="")
{
$_REQUEST['pic']=="blank.gif";
}
$erg=query($link,"update news set
news_title='".nl2br(htmlentities($_REQUEST['titel']))."',news_shorttext='".nl2br(htmlentities($_REQUEST['shorttext']))."',news_url='"
. ($_REQUEST['anzeigen'] == 0 ? "snews.php?id=".$_REQUEST['id'] : "") .
"',
news_pic='".$_REQUEST['pic']."',news_from='".$_REQUEST['yvon']."-".$_REQUEST['mvon']."-".$_REQUEST['dvon']."
00:00:00',news_to='".$_REQUEST['ybis']."-".$_REQUEST['mbis']."-".$_REQUEST['dbis']."
00:00:00',news_intern=" . $_REQUEST['anzeigen'] . " where
news_id=".$_REQUEST['id'].";");
if($erg)
{
// Dieser Codeteil ist temporaer, fr die Dauer
des NFS-Kurses 2006!
if ($_REQUEST['anzeigen'] == 1)
{
$suberg = query($link, "SELECT groupid FROM
usergroup WHERE groupshort = 'NFS-Kurs'");
if ($suberg && ($row = mysql_fetch_row($suberg)))
query($link, "INSERT IGNORE INTO
news_group VALUES({$_REQUEST['id']},{$row[0]})");
}
else
query($link, "DELETE FROM news_group WHERE
news_id = {$_REQUEST['id']}");
}
$newsid=$_REQUEST['id'];
}
else
{
if($_REQUEST['bild']=="")
{
$_REQUEST['bild']=="blank.gif";
}
$erg=query($link,"Insert into
news(news_date,news_title,news_shorttext,news_url,news_pic,news_width,news_height,news_from,news_to,news_intern)
values('".date("Y-m-d
00:00:00")."','".nl2br(htmlentities($_REQUEST['titel']))."','".nl2br(htmlentities($_REQUEST['shorttext']))."','"
. ($_REQUEST['anzeigen'] == 0 ? "snews.php?id=".$row[0] : "") .
"','".$_REQUEST['pic']."',150,100,'".$_REQUEST['yvon']."-".$_REQUEST['mvon']."-".$_REQUEST['dvon']."
00:00:00','".$_REQUEST['ybis']."-".$_REQUEST['mbis']."-".$_REQUEST['dbis']."
00:00:00',".$_REQUEST['anzeigen'].");");
$newsid=mysql_insert_id();
if($erg)
{
$insertid = mysql_insert_id($link);
if ($_REQUEST['anzeigen'] == 1)
{
$suberg = query($link, "SELECT groupid FROM
usergroup WHERE groupshort = 'NFS-Kurs'");
if ($suberg && ($row = mysql_fetch_row($suberg)))
query($link, "INSERT IGNORE INTO
news_group VALUES($insertid,{$row[0]})");
}
}
}
?>
<div style="text-align:center"><br>
<form enctype="multipart/form-data" action="upload.php"
method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="4000000">
<input type="hidden" name="id" <?php echo 'value="'.$newsid.'"' ?>>
<?php
}
?>
</body>
</html>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php