imagecopyresampled not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bint

    imagecopyresampled not working

    Hello,

    I'm trying to create thumbnails of PNG images. I have code that used to
    work but doesn't seem to anymore. The resizing just seems to return black
    images, even though my source image is not black. Anyone know what could be
    the problem?

    Here's my code:

    $width = imagesx($im);
    $height = imagesy($im);

    if ($width >= $height) {
    if ($width 32)
    $thumbwidth = 32;
    else $thumbwidth = $width;
    $aspect = $width/$height;
    $thumbheight = $thumbwidth/$aspect;
    }
    else {
    if ($height 32)
    $thumbheight = 32;
    else $thumbheight = $height;
    $aspect = $width/$height;
    $thumbwidth = $thumbheight*$a spect;
    }

    $tim = ImageCreateTrue Color($thumbwid th,$thumbheight );

    imagealphablend ing($tim, FALSE);
    imagesavealpha( $tim, TRUE);
    $myBool = imagecopyresamp led( $tim, $im, 0, 0, 0, 0, $thumbwidth,
    $thumbheight, $width, $height);




  • SrSilveira

    #2
    Re: imagecopyresamp led not working

    On Jun 13, 2:10 pm, "Bint" <b...@csgs.comw rote:
    Hello,
    >
    I'm trying to create thumbnails of PNG images. I have code that used to
    work but doesn't seem to anymore. The resizing just seems to return black
    images, even though my source image is not black. Anyone know what could be
    the problem?
    >
    Here's my code:
    >
    $width = imagesx($im);
    $height = imagesy($im);
    >
    if ($width >= $height) {
    if ($width 32)
    $thumbwidth = 32;
    else $thumbwidth = $width;
    $aspect = $width/$height;
    $thumbheight = $thumbwidth/$aspect;
    }
    else {
    if ($height 32)
    $thumbheight = 32;
    else $thumbheight = $height;
    $aspect = $width/$height;
    $thumbwidth = $thumbheight*$a spect;
    }
    >
    $tim = ImageCreateTrue Color($thumbwid th,$thumbheight );
    >
    imagealphablend ing($tim, FALSE);
    imagesavealpha( $tim, TRUE);
    $myBool = imagecopyresamp led( $tim, $im, 0, 0, 0, 0, $thumbwidth,
    $thumbheight, $width, $height);
    that works for me:


    $im = "forest.png ";

    list($width, $height) = getimagesize($i m);

    if ($width >= $height) {
    if ($width 32)
    $thumbwidth = 32;
    else $thumbwidth = $width;
    $aspect = $width/$height;
    $thumbheight = $thumbwidth/$aspect;
    }else {
    if ($height 32)
    $thumbheight = 32;
    else $thumbheight = $height;
    $aspect = $width/$height;
    $thumbwidth = $thumbheight*$a spect;
    }

    $tim = ImageCreateTrue Color($thumbwid th,$thumbheight );
    $image = imagecreatefrom png($im);
    imagealphablend ing($tim, FALSE);
    imagesavealpha( $tim, TRUE);
    $myBool = imagecopyresamp led($tim, $image, 0, 0, 0, 0, $thumbwidth,
    $thumbheight, $width, $height);

    header('Content-type: image/png');

    imagepng($tim);

    Comment

    • SrSilveira

      #3
      Re: imagecopyresamp led not working

      On Jun 13, 2:10 pm, "Bint" <b...@csgs.comw rote:
      Hello,
      >
      I'm trying to create thumbnails of PNG images. I have code that used to
      work but doesn't seem to anymore. The resizing just seems to return black
      images, even though my source image is not black. Anyone know what could be
      the problem?
      >
      Here's my code:
      >
      $width = imagesx($im);
      $height = imagesy($im);
      >
      if ($width >= $height) {
      if ($width 32)
      $thumbwidth = 32;
      else $thumbwidth = $width;
      $aspect = $width/$height;
      $thumbheight = $thumbwidth/$aspect;
      }
      else {
      if ($height 32)
      $thumbheight = 32;
      else $thumbheight = $height;
      $aspect = $width/$height;
      $thumbwidth = $thumbheight*$a spect;
      }
      >
      $tim = ImageCreateTrue Color($thumbwid th,$thumbheight );
      >
      imagealphablend ing($tim, FALSE);
      imagesavealpha( $tim, TRUE);
      $myBool = imagecopyresamp led( $tim, $im, 0, 0, 0, 0, $thumbwidth,
      $thumbheight, $width, $height);
      that works for me:

      $im = "forest.png ";

      list($width, $height) = getimagesize($i m);

      if ($width >= $height) {
      if ($width 32)
      $thumbwidth = 32;
      else $thumbwidth = $width;
      $aspect = $width/$height;
      $thumbheight = $thumbwidth/$aspect;
      }else {
      if ($height 32)
      $thumbheight = 32;
      else $thumbheight = $height;
      $aspect = $width/$height;
      $thumbwidth = $thumbheight*$a spect;
      }

      $tim = ImageCreateTrue Color($thumbwid th,$thumbheight );
      $image = imagecreatefrom png($im);
      imagealphablend ing($tim, FALSE);
      imagesavealpha( $tim, TRUE);
      $myBool = imagecopyresamp led($tim, $image, 0, 0, 0, 0, $thumbwidth,
      $thumbheight, $width, $height);

      header('Content-type: image/png');

      imagepng($tim);

      Comment

      • Schraalhans Keukenmeester

        #4
        Re: imagecopyresamp led not working

        At Wed, 13 Jun 2007 12:10:16 -0500, Bint let h(is|er) monkeys type:
        Hello,
        >
        I'm trying to create thumbnails of PNG images. I have code that used to
        work but doesn't seem to anymore. The resizing just seems to return black
        images, even though my source image is not black. Anyone know what could be
        the problem?
        >
        At first glance your code seems fine. So the question probably boils down
        to: is there a valid image in $im to begin with?

        When running into the situation: it used to work but now it doesn't, ask
        yourself what might have changed. New host, new PHP version, changed
        php.ini, paths, permissions, changed includes etc.
        Add some debugging steps along the way if you can't think of what has
        changed, set error_reporting (E_ALL) to catch helpful notices and warnings.

        --
        Schraalhans Keukenmeester - schraalhans@the .Spamtrapexampl e.nl
        [Remove the lowercase part of Spamtrap to send me a message]

        "strcmp('apples ','oranges') < 0"

        Comment

        Working...