Jump to content
Fórum Script Brasil
  • 0

Erro ao exibir imagem via php


ddik
 Share

Question

Olá,

Hoje precisei de criar um código php para exibir as imagem via php. O problema que ele não exibi a imagem via php. Apenas consigo que ele salve a imagem no servidor.

Quando ele é salva mostra imagem normalmente. Mas quando ponho a exibir directo pelo php fica como se a imagem estive-se corrompida.

<?php
$url = $_GET['url'];
$s = $_GET['s'];
$h = $_GET['h'];
$w = $_GET['w'];

if($url)
{
    if (list($image_width, $image_heigth, $image_type) = @getimagesize($url))
    {        
        if($image_type == IMAGETYPE_JPEG)
        {
            $image = imagecreatefromjpeg($url);
        }
        elseif($image_type == IMAGETYPE_GIF)
        {
            $image = imagecreatefromgif($url);
        }
        elseif($image_type == IMAGETYPE_PNG)
        {
            $image = imagecreatefrompng($url);
        }
        
        $image_width_old = round($image_width);
        $image_heigth_old = round($image_heigth);
        
        if($s)
        {
            $image_width = round($image_width * $s/100);
              $image_heigth = round($image_heigth * $s/100);
        }
        elseif($w and $h)
        {
            $image_width = $w;
              $image_heigth = $h;
        }
        elseif($w)
        {
            $ratio = $w / $image_width;
            $image_width = $w;
              $image_heigth = round($image_heigth * $ratio);
        }
        elseif($h)
        {
            $ratio = $h / $image_heigth;
            $image_heigth = $h;
              $image_width = round($image_width * $ratio);
        }
        
        $new_image = imagecreatetruecolor($image_width, $image_heigth);
        imagealphablending($new_image, false);
        imagesavealpha($new_image,true);
        $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 0);
        imagecolortransparent($new_image, $transparent );
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $image_width, $image_heigth, $image_width_old, $image_heigth_old);
        $image = $new_image;
        
        if($image_type == IMAGETYPE_JPEG)
        {
            //header('Content-Type: image/jpeg');
            imagejpeg($image);
        }
        elseif($image_type == IMAGETYPE_GIF)
        {
            //header('Content-Type: image/gif');
            imagegif($image);
            
        }
        elseif($image_type == IMAGETYPE_PNG)
        {
            header('Content-Type: image/png');
            imagepng($image);
        }
    }
}
?>

Alguém me pode dar um ajuda aqui?

Edited by ddik
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.9k
    • Total Posts
      648.7k
×
×
  • Create New...