SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot JagXJ220's Avatar
    Join Date
    Mar 2001
    Location
    Not worth the drive
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    I'm having some really weird problems with GD. I'm using these scripts to display some sample images before I design my thumbnail system.

    Here is imagetest2.php:
    PHP Code:
    <?
    Header
    ("Content-Type: image/jpeg");
    $im ImageCreateFromJPEG($imgsrc);
    $white ImageColorAllocate($im000);
    $red ImageColorAllocate($im25500);
    $points[0] = 30$points[1] = 30;
    $points[2] = 15$points[3] = 45;
    $points[4] = 30$points[5] = 60;
    $points[6] = 45$points[7] = 45;
    ImageFilledPolygon($im$points4$red);
    ImageJPEG($im);
    ImageDestroy($im);
    ?>
    & here is the script that calls it, imagetest.php:
    PHP Code:
    <html>
    <
    head>
        <
    title>Untitled</title>
    </
    head>

    <
    body bgcolor="#000000" text="#ffffff">
    Image Testing Page<br>
    <
    img src="imagetest2.php?imgsrc=s1.jpg">&nbsp;&nbsp;&nbsp;&nbsp;<img src="s1.jpg">
    <
    br><br>
    <
    img src="imagetest2.php?imgsrc=s2.jpg">&nbsp;&nbsp;&nbsp;&nbsp;<img src="s2.jpg">
    </
    body>
    </
    html
    Whenever I go to imagetest.php in my browser, the php images work fine and have a rotated square near the middle of them, but instead of the square being red, it's different colors, depending on the image. It's almost like the square color is the inverted color of the center pixel of the square. To see this, go to http://www.phpnetwork.com/sco/imagetest.php. The images on the left are the php ones, and on the right are the originals.

    Can someone please help me figure this out?

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This exchange in the PHP Manual page for ImageColorAllocate might help:

    info@powerdesign.at
    28-Apr-2001 05:26
    When working with JPEG's, imagecolorallocate seems not always to do, what is expected.
    e.g.: after "imagecreatefromjpeg(...)", I use "imagecolorallocate($img,0,0,0)" and writing some text into the image with "imagestring(...)". This doesnt always have to be necessarily black.
    Seems like it tries to interpret the colors in the JPEG the same like in the GIF-Palette.


    schwab@makronomic.com
    03-May-2001 12:08
    RE: info@powerdesign.at
    I experienced the same, but i use following workaround:
    Create a new Jpeg, Allocate your colours, and copy your original jpg into the new one. then you have all the colours you have allocated in your new pic...
    Last edited by Kevin Yank; May 16, 2001 at 23:21.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Zealot JagXJ220's Avatar
    Join Date
    Mar 2001
    Location
    Not worth the drive
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the method that you listed, but it didn't seem to work. I probably used the wrong code or something to copy the existing image to the new one. Here's the code I used.
    PHP Code:
    <?
    Header
    ("Content-Type: image/jpeg");
    $im ImageCreate(12090);
    $white ImageColorAllocate($im000);
    $red ImageColorAllocate($im25500);
    $im ImageCreateFromJPEG($imgsrc);
    $points[0] = 30$points[1] = 30;
    $points[2] = 15$points[3] = 45;
    $points[4] = 30$points[5] = 60;
    $points[6] = 45$points[7] = 45;
    ImageFilledPolygon($im$points4$red);
    ImageJPEG($im);
    ImageDestroy($im);
    ?>
    Is there something wrong with this code? When I went to the test page in my browser, the images still work, except the top left image now has a green box now instead of a purple one that it had prior to changing the code. Can someone please help me?

  4. #4
    SitePoint Zealot JagXJ220's Avatar
    Join Date
    Mar 2001
    Location
    Not worth the drive
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't mind my last post. I figured out what I was doing wrong and now it's fixed.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •