Jump to content
Sign in to follow this  
EirikO

Problemer med resize

Recommended Posts

Har lenge brukt koden under for å resize bilder på siden min. Men i dag oppdaget jeg plutselig at det ikke lenger fungerer...

 

Koden er:

<?php

function sizeImage($image, $w, $h, $proportional) {
  if (!$attr = getimagesize($image)) {
      trigger_error("GD: Image does not exist.  Must be gif, jpeg, or png!",E_USER_ERROR);
  }
 
  switch ($attr[2]) {
      case 1:
          $image = imagecreatefromgif($image);
          break;
      case 2:
          $image = imagecreatefromjpeg($image);
          break;
      case 3:
          $image = imagecreatefrompng($image);
          break;
      default:
          trigger_error("GD: Image type wrong.  Must be gif, jpeg, or png!",E_USER_ERROR);
  }
  if ($proportional) {
      if ($attr[0]<$attr[1]){
          $w = $h * ($attr[0]/$attr[1]);
      }
      else{
          $h = $w / ($attr[0]/$attr[1]);
        }   
  }
  $newimage = imagecreatetruecolor($w,$h);
  imagecopyresampled($newimage, $image, 0, 0, 0, 0, $w, $h, $attr[0], $attr[1]);
  imagepng($newimage);
  imagedestroy($image);
  imagedestroy($newimage);
}

$image = $_GET['image']; //image location

$image = "http://www.opsanger.com/bilder/" . $image;
$proportional = TRUE; //proportional or not
$w=150;
$h=150;
header("Content-type: image/jpeg");

sizeImage($image, $w, $h, $proportional);

?>

 

Bruker så:

<img src="resize_bilde.php?image=nokkel.jpg">

får å printe ut bildet...

 

(Ja, http://www.opsanger.com/bilder/nokkel.jpg finnes)

 

 

Noen som har noen gode forslag?? :innocent:

Share this post


Link to post

Ingen feilmelding. Bildet blir bare ikke vist. Kommer bare en blank ramme, med et rødt kryss. Samme som når stien til et bilde er feil..

Share this post


Link to post

Join the conversation

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

Guest
Reply to this topic...

×   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.

Loading...
Sign in to follow this  

×
×
  • Create New...