Visualize Thumbnails

Asked

Viewed 228 times

2

I have a page in PHP where it contains WHILE that should show thumbnail image according to the images I have in the same directory.

    <?php
while($fetch = mysql_fetch_assoc($select)){
 ?>
        <tr class="row-content1">
           <td class="check"> <label><input type="checkbox" value=""></label></td>
           <td> <?php echo $fetch['nickname']; ?>  </td>
           <td><?php echo $fetch['sala']; ?></td>
           <td><?php "<img  src='thumb.php?img=image/".$fetch['imagem'];"'>"?></td>
           <td><input type="image" src="LOG_29710.png" data-toggle="modal" data-target="#myModal<?php echo $fetch['id']; ?>"></td>
           <td><?php echo $fetch['quote']; ?></td>
           <td><?php echo $fetch['aprovado']; ?></td>

      </a>
</td>
     ?>

The Thumb.php file does all the work to generate the thumbnail. However, the images do not appear, does not generate an error, but in the image/thumbnail field, it is empty. If I set the image outside of Thumb.php, the original image appears. I have another project that works right, I used exactly the same model, but it doesn’t work.

Follow the section of Thumb.pbp

function mimeType($file)
{
    $mimetype = false;

    if (class_exists('finfo')) {//PHP5.4+
        $finfo     = finfo_open(FILEINFO_MIME_TYPE);
        $mimetype  = finfo_file($finfo, $file);
        finfo_close($finfo);
    } else if (function_exists('mime_content_type')) {//php5.3 ou inferiror
        $mimetype = mime_content_type($file);
    }

    return $mimetype;
}

$filename = $_GET['img'];
$percent = 0.10;

//Lê o formato do conteudo da imagem
$mime = mimeType($filename);

if (strpos($mime, 'image/') !== 0) {
    die('Este arquivo não é uma imagem');
}

//Remove o prefixo image/
$mime = substr($mime, 6);

//Remove `x` de x-jpeg, talvez ocorram em alguns servidores antigos
$mime = str_replace('x-', '', $mime);

switch ($mime) {
    case 'jpeg':
        $image = imagecreatefromjpeg($filename);
    break;
    case 'png':
        $image = imagecreatefrompng($filename);
    break;
    case 'gif':
        $image = imagecreatefromgif($filename);
    break;
    default:
        die('Formato não aceito');
}

// Cabeçalho que ira definir a saida da pagina
header('Content-type: image/jpeg');

// pegando as dimensoes reais da imagem, largura e altura
list($width, $height) = getimagesize($filename);

//setando a largura da miniatura
$new_width = 120;
//setando a altura da miniatura
$new_height = 100;

//gerando a a miniatura da imagem
$image_p = imagecreatetruecolor($new_width, $new_height);

imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

//o 3º argumento é a qualidade da imagem de 0 a 100
imagejpeg($image_p, null, 50);
imagedestroy($image_p);
  • Add the end of the PHP error log so we can evaluate it better

  • It does not point out errors, if I force any error, it generates error via output. How do I generate any error file even not showing on screen? Saving in txt?

  • If you pull the thumbnail straight into the browser by placing it in the address bar thumb.php?img=image/".$fetch['imagem'];" replacing the ".$fetch['imagem'];" by a valid value, the image appears?

  • The error generated is: Fatal error: Call to Undefined Function imagecreatefrompng() in /home/httpd/html/juridico/www/denuncias/Thumb.php on line 39 . Researching I realized it is due to lack of a library.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.