Jump to content

Recent Error Message...but script was working fine.


plato2

Recommended Posts

I have been using this script for years. I realise it is a little old and probably not well written, however it has been functional. I suspect the problem is that maybe they have turned the register_globals off at the server and the script is no longer working. I don't know if that is the problem. The error I get when I attempt to upload an image is this:

Error:

MySQL error reported!

Query: INSERT INTO photos values(NULL,'corrobex', 1, 10, , 'makinti', '', '', 'makinti.jpg', 571, 381, 42520, '0', 0, 0, 0, '1', , '0', 'no', '', '', '', '', '')

 

Result: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'makinti', '', '', 'makinti.jpg', 571, 381, 42520, '0', 0, 0, 0, '1', , '0', 'n' at line 1

 

Database handle: Resource id #3

 

Now here is the script:

<?php
include("pp-inc.php");
include("login-inc.php");
include("image-inc.php");

if ( is_array($HTTP_POST_FILES) ) {
    while(list($key,$value) = each($HTTP_POST_FILES)) {
        ${$key} = $value;
    }
}

function handleupload( $location = "data" ) {
    global $HTTP_POST_FILES, $userid, $Globals, $category;
    
    $tmpname = $HTTP_POST_FILES['theimage']['tmp_name'];
    $realname = $HTTP_POST_FILES['theimage']['name'];
    $tmpcloseup = $HTTP_POST_FILES['closeup']['tmp_name'];

    if (is_uploaded_file($tmpname) ) {
        $realname = fixfilenames( $realname );
        $closeup = preg_replace("/(\.[A-Za-z]+)$/", "-closeup\\1", $realname);

        if ( $location != "data" ) {
            $dst_file = $location;
        }
        else {
            $dst_file = $Globals{'datafull'}."$category/$userid$realname";
            $closeup_file = $Globals{'datafull'}."$category/$userid$closeup"; 
       }

        copy($tmpname, $dst_file);
        copy($tmpcloseup, $closeup_file);
    } else {
        dieWell("Uploaded file not found: $realname<br>Typical reason is that the file exceeded allowed limits.");
        exit;
    }

    return;
}

authenticate();

$nolimit = 0;
if ( $Globals{'adminnolimit'} == "yes" && $adminedit == 1 ) {
    $nolimit = 1;
}

$adminexclude = 0;
if ( $Globals{'adminexclude'} == "yes" && $adminedit == 1 ) {
    $adminexclude = 1;
}

if ( $adminedit == 0 ) {
    if ( $Globals{'allowup'} == "no" ) {
        dieWell( "User uploads not allowed" );
    }
}

$querystring = findenv("QUERY_STRING");
if ( ($useruploads == 0 && $gologin==1) || $querystring == "gologin" ) {
    $furl=$Globals{'maindir'};
    $furl= str_replace( $Globals{'domain'}, "", $furl );
    $furl="$furl/uploadphoto.php";

    login( $furl );
    exit;
}

if ( $gologin != 0 ) {
    if ( $useruploads == 0 ) {
        dieWell("Sorry, you don't have permission to upload photos.");
        exit;
    }    
}

topmenu();

if ( !isset($theimage) ) {
    $catdefault = "";

    if ( !empty($cat) ) {
        $query = "SELECT id,catname,thumbs FROM categories WHERE id=$cat LIMIT 1";
        $resultb = ppmysql_query($query,$link);
        while ( list( $subid, $subcatname, $subthumbs ) = mysql_fetch_row($resultb) ) {
            if ( $ugcat{$subid} != 1 ) {
                $catdefault = "<option selected value=\"$subid\">$subcatname</option>";
            }
        }
        ppmysql_free_result( $resultb );
    }

    $header = str_replace( "titlereplace", "Upload Photo", $header );    

    $output = "$header<center><p>
        <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" height=\"40\" width=\"".$Globals{'tablewidth'}."\"><Tr>
        <Td valign=\"middle\" width=\"50%\">$menu2</td>
        <td width=\"50%\" align=\"right\" valign=\"middle\">$menu</td></tr></table>
        <table cellpadding=\"0\" cellspacing=\"0\"
        border=\"0\" bgcolor=\"".$Globals{'bordercolor'}."\"  width=\"".$Globals{'tablewidth'}."\" align=\"center\"><tr><td>
        <table cellpadding=\"4\" cellspacing=\"1\" border=\"0\"  width=\"100%\">
        <tr align=\"center\">
        <td colspan=\"1\" align=\"left\" bgcolor=\"".$Globals{'headcolor'}."\"><font face=\"".$Globals{'headfont'}."\"
        color=\"".$Globals{'headfontcolor'}."\" size=\"".$Globals{'fontmedium'}."\"><B>".$Globals{'galleryname'}." Image
        Upload</font></td>
        <td colspan=\"1\" align=\"right\" bgcolor=\"".$Globals{'headcolor'}."\"><font
        face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'headfontcolor'}."\" size=\"".$Globals{'fontmedium'}."\">
        <a href=\"javascript:PopUpHelp('uploadphoto.php')\">help</a></font>
        </td>            
        </tr>
        <form method=\"post\" action=\"".$Globals{'maindir'}."/uploadphoto.php\" enctype=\"multipart/form-data\">
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'maintext'}."\">Username</font></td><td
        bgcolor=\"".$Globals{'maincolor'}."\">
        <font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'maintext'}."\">$username</td></tr>
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\" width=\"50%\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Choose a
        category</font></td><Td bgcolor=\"".$Globals{'maincolor'}."\"><select
        name=\"category\">$catdefault";

    if (empty($subid)) $subid="";
    $selected = $subid;
    catmoveopt(0);
    $output .= $catoptions;

    $imgdir = $Globals{'zipuploaddir'}."/$userid";
    $skiphtml = "</table><table cellpadding=\"4\" cellspacing=\"0\" border=\"0\"  width=\"100%\">
        <tr><Td bgcolor=\"".$Globals{'headcolor'}."\" align=\"center\">
        <font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'headfontcolor'}."\" face=\"".$Globals{'mainfonts'}."\">
        <b>ADMIN OPTIONS FOR BULK OR ZIP UPLOADS</b></font>
        </td>
        <td align=\"right\" bgcolor=\"".$Globals{'headcolor'}."\"><font
        face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'headfontcolor'}."\" size=\"".$Globals{'fontmedium'}."\">
        <a href=\"javascript:PopUpHelp('adminskip.php')\">help</a></font>
        </td>            
        </tr></table>
        <table cellpadding=\"4\" cellspacing=\"1\" border=\"0\"  width=\"100%\">
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Skip upload and process the files in your upload directory<br><font size=\"".$Globals{'fontsmall'}."\">Files should already be in: <b>$imgdir</b></td>
        <td bgcolor=\"".$Globals{'maincolor'}."\" align=\"center\"><input type=\"checkbox\" name=\"skipupload\" value=\"skipupload\"></td></tr>
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Show thumbnails during processing?</td>
        <td bgcolor=\"".$Globals{'maincolor'}."\" align=\"center\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\"><select name=\"dthumbs\"><option selected>yes</option><option>no</option></select></font></td></tr>
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Number of thumbnails to process next?</td>
        <td bgcolor=\"".$Globals{'maincolor'}."\" align=\"center\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\"><select name=\"numprocess\"><option selected>10</option><option>25</option><option>50</option><option>100</option></select></td></tr>";
            
    $output .= "</select></td></tr>
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'maintext'}."\">Photo to upload:</font><br><b><font size=\"".$Globals{'fontsmall'}."\" face=\"".$Globals{'mainfonts'}."\"
        color=\"red\">$maxfilesize</font></b></td><td bgcolor=\"".$Globals{'maincolor'}."\"><input type=\"file\" name=\"theimage\"></td></tr>
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\" color=\"".$Globals{'maintext'}."\">Matching closeup to upload:</font><br><b><font size=\"".$Globals{'fontsmall'}."\" face=\"".$Globals{'mainfonts'}."\"
        color=\"red\">$maxfilesize</font></b></td><td bgcolor=\"".$Globals{'maincolor'}."\"><input type=\"file\" name=\"closeup\"></td></tr>
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Enter a title for the photo</td><td bgcolor=\"".$Globals{'maincolor'}."\"><input
        type=\"text\" name=\"title\"></td></tr>
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">To help users find your photo, please enter a few (up to 10) descriptive
        keywords (separated by spaces):</td><td bgcolor=\"".$Globals{'maincolor'}."\"><input type=\"text\" name=\"keywords\"></td></tr>
        <tr><Td bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" color=\"".$Globals{'maintext'}."\" face=\"".$Globals{'mainfonts'}."\">Photo Description</td><td bgcolor=\"".$Globals{'maincolor'}."\"><textarea
        name=\"desc\" cols=\"30\" rows=\"5\"></textarea></td></tr>
        $skiphtml
        <Center>
        <Tr><Td colspan=\"2\" bgcolor=\"".$Globals{'maincolor'}."\"><font size=\"".$Globals{'fontmedium'}."\" face=\"".$Globals{'mainfonts'}."\"><center>
        <input type=\"hidden\" name=\"password\" value=\"$password\">
        <input type=\"hidden\" name=\"userid\" value=\"$userid\">
        <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2000000\">
        <input type=\"submit\" value=\"Upload/Submit\">
        <p><b>When you hit SUBMIT, the file you selected will be uploaded.</b><br></font><font size=\"".$Globals{'fontsmall'}."\" face=\"".$Globals{'mainfonts'}."\">
        (Depending on the size of the file and your connection, this may take some time. <b>Please be patient.</b>)</p></font></td></tr></table></td></tr></table><p>".$Globals{'cright'}."$footer";

    print $output;
}
else {
    if (empty($skipupload)) $skipupload="";
    
    if ( $category == "" ) {
        dieWell( "You must choose a category before uploading.");
        exit;
    }

    if ( $skipupload == "skipupload" ) {
        $deftitle = urlencode($title);
        $defdesc = urlencode($desc);
        $furl = $Globals{'zipuploadurl'}."/$userid";

        forward( $Globals{'maindir'}."/bulkupload.php?ppaction=addphotos&do=preview&photopath=$userid&deftitle=$deftitle&defdesc=$defdesc&defcat=$category&keywords=$keywords&numprocess=$numprocess&dthumbs=$dthumbs&furl=$furl", "Preparing to process image list!" );
        exit;
    }

    $realname = $HTTP_POST_FILES['theimage']['name'];
    
    if ( $realname == "" ) {
        dieWell( "You need to enter the name of a file to upload! $thevideo / $theimage" );
        exit;
    }

    $realname = fixfilenames( $realname );
    $theext   = get_ext( $realname );
    
    $filepath = $Globals{'datafull'}."$category/$userid$realname";
    $outfilename = "$userid$realname";

    $query = "SELECT userid,bigimage FROM photos where userid=$userid";
    $resulta = ppmysql_query($query,$link);

    while( list( $uid, $bgimage ) = mysql_fetch_row($resulta) ) {
        if ($uid == $userid && $uid != 0) {
            if ( $bgimage == $realname ) {
                dieWell("Sorry, you already uploaded an image called $realname.  Try a different name.");
                exit;
            }
        }
    }
    ppmysql_free_result($resulta);

    $title = fixmessage( $title );
    $keywords = fixmessage( $keywords );
    $desc = fixmessage( $desc );

    if ( $category == "notcat" ) {
        $emessage = "The category you chose is a top level category.<p>Please go back and choose one of its subcategories to upload your image.";
        dieWell($emessage);
    }

    //####// Write the file to a directory #####
    //#// Do you wish to allow all file types?  yes/no (no capital letters)
    $allowall = "no";

    //#// If the above = "no"; then which is the only extention to allow?
    //#// Remember to have the LAST 4 characters i.e. .ext
    if ($realname != "") {
        $isfilegood = "yes";
        if ( $allowall != "yes" ) {
            if ( !is_image($outfilename) ) {
                $isfilegood = "no";
            }
        }

        if ($isfilegood == "yes") {
            handleupload();
        }

        //
        // ZIP Uploads for Users
        //
        if ( $Globals{'allowzip'} ) {
            if (strtolower(substr($outfilename,strlen($outfilename) - 4,4)) == ".zip" ) {
                $filepath = $Globals{'zipuploaddir'}."/$userid";
                $filedir = "$filepath/$outfilename";

                if ( !file_exists( $filepath ) ) {
                    mkdir( $filepath, 0755 );
                    chmod( $filepath, 0777 );
                }

                chdir( $filepath );

                handleupload( $filedir );

                $sys_cmd = $Globals{'zip_command'}." -qq $filedir";
                system( $sys_cmd );
                unlink( $filedir );

                $deftitle = urlencode($title);
                $defdesc = urlencode($desc);
                $furl = $Globals{'zipuploadurl'}."/$userid";
                if ( empty($numprocess) ) $numprocess = 10;
                if ( empty($dthumbs) ) $dthumbs = "yes";

                forward( $Globals{'maindir'}."/bulkupload.php?ppaction=addphotos&do=preview&photopath=$userid&deftitle=$deftitle&defdesc=$defdesc&defcat=$category&keywords=$keywords&numprocess=$numprocess&dthumbs=$dthumbs&furl=$furl", "Preparing to process image list!" );
                exit;
            }
        }
    }

    if ( file_exists($filepath) ) {
        $insize = filesize( $filepath );
    }
    else {
        dieWell("File upload error. Cannot find uploaded file.<br>Path: [$filepath]");
        exit;
    }

    if ( $isfilegood != "yes" ) {
        dieWell( "Image must be a .jpg, .gif, .tif or .png file." );
        exit;
    }

    $thumbsize = create_thumb( $realname, $filepath, $category );
    process_image( $realname, $filepath, $category );

    $query = "SELECT id FROM photos WHERE userid=$userid AND bigimage='$realname'";
    $resulta = ppmysql_query($query,$link);
    list( $forwardid ) = mysql_fetch_row($resulta);
    ppmysql_free_result($resulta);

    if ( empty($forwardid) ) {
        dieWell( "There was a problem processing your image: $realname.<p>Please notify the System Administrator." );
        exit;
    }
    
    forward( $Globals{'maindir'}."/showphoto.php?photo=$forwardid", "Your image was uploaded successfully!" );
}

?>

 

Do Globals need to be on for this to work? Or is there another problem?

 

thanks

 

Paul

 

MOD EDIT:

 . . . 

tags added.

Link to comment
Share on other sites

The error you're getting is related to the query values. I've marked the area that's the problem with the word HERE.

 

INSERT INTO photos values(NULL,'corrobex', 1, 10, HERE, 'makinti', '', '', 'makinti.jpg', 571, 381, 42520, '0', 0, 0, 0, '1', , '0', 'no', '', '', '', '', '')

 

If you just default the insert value for that column to '' or 0 (depending on the data type - like you've done with other fields). It should work fine.

 

Mike.

Link to comment
Share on other sites

MikeDean89..

Thanks, I'm not a PHP guru so I don't fully understand your reply. Could I impose on you to repost the code with what needs to be corrected so I can see if it works. I would really appreciate it, as I have no idea why, all of a sudden it is not working on the server.

Link to comment
Share on other sites

Mike,

 

I'm guessing you're referring to the image-inc.php file. If so here is that code:

 

function resize_jpeg( $image_file_path, $new_image_file_path, $max_width=480, $max_height=1600 )
{
    global $Globals;

    $return_val = 1;

    $image_stats = getimagesize( $image_file_path );
    $FullImage_width = $image_stats[0];
    $FullImage_height = $image_stats[1];
    $img_type = $image_stats[2];

    switch( $img_type ) {
        case 1: $src_img = ImageCreateFromGif($image_file_path); break;
        case 2: $src_img = ImageCreateFromJpeg($image_file_path); break;
        case 3: $src_img = ImageCreateFromPng($image_file_path); break;
        default: diewell("Sorry, this image type ($img_type) is not supported yet."); exit;
    }

    if ( !$src_img ) {
        diewell("Unable to create image [$image_file_path].<br>Please contact system administrator.");
        exit;
    }

    $ratio =  ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ;
    $new_width = ((int)($FullImage_width * $ratio));    //full-size width
    $new_height = ((int)($FullImage_height * $ratio));    //full-size height

    $ratio =  ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ;
    $new_width = ((int)($new_width * $ratio));    //mid-size width
    $new_height = ((int)($new_height * $ratio));    //mid-size height

    if ( $new_width == $FullImage_width && $new_height == $FullImage_height )
        copy ( $image_file_path, $new_image_file_path );

    if ( $Globals{'usegd'} == 1 ) {
        $full_id = ImageCreate( $new_width , $new_height );
        ImageCopyResized( $full_id, $src_img, 0,0,  0,0, $new_width, $new_height,
                    $FullImage_width, $FullImage_height );
    }
    else {
        $full_id = ImageCreateTrueColor( $new_width, $new_height );
        ImageCopyResampled( $full_id, $src_img, 0,0, 0,0, $new_width, $new_height,
                    $FullImage_width, $FullImage_height );
    }

    switch( $img_type ) {
        case 1: $return_val = ImageGIF( $full_id, $new_image_file_path ); break;
        case 2: $return_val = ImageJPEG( $full_id, $new_image_file_path, 90 ); break;
        case 3: $return_val = ImagePNG( $full_id, $new_image_file_path ); break;
        default: diewell("Sorry, this image type is not supported yet."); exit;
    }

    ImageDestroy( $full_id );

    return ($return_val) ? TRUE : FALSE ;
}

function gdwatermark($srcfilename, $watermark) {
    $imageInfo = getimagesize($srcfilename);
    $width = $imageInfo[0];
    $height = $imageInfo[1];

    $logoinfo = getimagesize($watermark);
    $logowidth = $logoinfo[0];
    $logoheight = $logoinfo[1];

    $horizextra =$width - $logowidth;
    $vertextra =$height - $logoheight;
    // middle
    //$horizmargin =  round($horizextra / 2);
    //$vertmargin =  round($vertextra / 2);
    // lower right corner
    $horizmargin =  $horizextra;
    $vertmargin =  $vertextra;

    $photoImage = ImageCreateFromJPEG($srcfilename);
    ImageAlphaBlending($photoImage, true);

    $logoImage = ImageCreateFromPNG($watermark);
    $logoW = ImageSX($logoImage);
    $logoH = ImageSY($logoImage);

    ImageCopy($photoImage, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH);

    //ImageJPEG($photoImage); // output to browser
    ImageJPEG($photoImage, $srcfilename, 90);

    ImageDestroy($photoImage);
    ImageDestroy($logoImage);
}


function create_thumb( $realname, $filepath, $thecat, $thevideo="" ) {
    global $Globals, $userid, $imagewidth, $imageheight, $thumbnail, $resizeorig, $uganno;

    //
    // NEW RESIZE CODE
    //
    $basedir = $Globals{'datafull'};
    $previewwidth = $Globals{'previewwidth'};
    
    if ( $filepath == "default" ) {
        $filepath = $Globals{'idir'}."/video.jpg";
    }

    $image_stats = getimagesize( $filepath );
    $imagewidth = $image_stats[0];
    $imageheight = $image_stats[1];
    $img_type = $image_stats[2];

    // Create thumbnails
    if ( $thevideo == "" ) {
        $filenoext = get_filename( $realname );
        $theext    = get_ext( $realname );
        $thumbnail = "$userid".$filenoext."-thumb.$theext";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    elseif ( $thevideo == "rebuildthumbnail" ) {
        $filenoext = get_filename( $realname );
        $theext    = get_ext( $realname );
        $thumbnail = $filenoext."-thumb.$theext";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    else {
        $filenoext = get_filename( $thevideo );
        $theext = "jpg";
        $thumbnail = "$userid".$filenoext."-thumb.jpg";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    $outthumb = strtolower( $outthumb );
    $thumbnail = strtolower( $thumbnail );
    
    if ( !file_exists( $outthumb ) )  {
        if ( $Globals{'usegd'} != 0 ) {
            if ( $imageheight < $imagewidth ) {
                $scaleFactor = $imagewidth / $previewwidth;
                $newheight = round( $imageheight / $scaleFactor );
                $newwidth = $previewwidth;
            }
            else {
                $scaleFactor = $imageheight / $previewwidth;
                $newwidth = round( $imagewidth / $scaleFactor );
                $newheight = $previewwidth;
            }

            $resize_worked = resize_jpeg($filepath, $outthumb, $newwidth, $newheight);
        }
        else {
            copy ( $filepath, $outthumb );

            // watermark thumbnail before resizing
            // uncomment if you want your thumbnails to have watermarks
            //if ( $uganno{$thecat} != 1 && $Globals{'annotate'} == "yes") {
            //    // stamp the image
            //    watermark( $outthumb );
            //}
            
            // if image is taller than wider, then portrait
            if ( $imageheight < $imagewidth ) {
                $scaleFactor = $imagewidth / $previewwidth;
                $newheight = round( $imageheight / $scaleFactor );
                $newwidth = $previewwidth;
                //$previewwidth = $previewwidth
            }
            else {
                $scaleFactor = $imageheight / $previewwidth;
                $newwidth = round( $imagewidth / $scaleFactor );
                $newheight = $previewwidth;
                //$previewheight = $previewwidth
            }

            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$newwidth."x".$newheight." $outthumb";

            // call ImageMagick mogrify to create the thumbnail
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating thumbnail! Error code: $retval<p>Command: $syscmd");
                unlink( $outthumb );
                unlink( $filepath );
                exit;
            }
        }
    }

    $imagesize = filesize( $outthumb );

    return( $imagesize );
}

function watermark( $filepath, $isadmin=0 ) {
    global $Globals;
    
    $agravity = $Globals{'gravity'};
    $water_image = $Globals{'watermark'};

    // need to execute this command after images:
    // composite -compose over -gravity southeast eblogo.jpg jess.jpg jesslogo.jpg

    if ( $Globals{'usegd'} != 0 ) {
        $retval = gdwatermark( $filepath, $water_image );
    }
    else {
        $composite_cmd = str_replace( "mogrify", "composite", $Globals{'mogrify_command'} );
        $stampcmd = $composite_cmd." -compose over -gravity $agravity $water_image $filepath $filepath";
        system( $stampcmd, $retval );

        if ( $retval != 0 ) {
            if ( $isadmin == 0 ) {
                dieWell("Error creating watermarked original! Error code: $retval<br><br>Command: $stampcmd");
                exit;
            }
            else {
                print "Error creating watermarked original on $filepath [$stampcmd]<br>";
            }
        }
    }
     
    return;
}


function process_image( $realname, $filepath, $thecat ) {
    global $Globals, $userid, $link, $db_link, $uganno;
    global $username, $usergroup, $title, $desc, $keywords;
    global $adminexclude, $keywords, $notify, $resizeorig;

    list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
    $mon = $mon + 1;
    $julian = mktime($hour,$min,$sec,$mon,$mday,$year);

    $filenoext = get_filename( $realname );
    $theext    = get_ext( $realname );
    $outfilename = "$userid$realname";
    $basedir = $Globals{'datafull'};

    $image_stats = getimagesize( $filepath );
    $imagewidth = $image_stats[0];
    $imageheight = $image_stats[1];
    $imagesize = filesize( $filepath );
    
    $resizeorig = 0;
    $maxwidth = $Globals{'maxwidth'};
    $maxheight = $Globals{'maxheight'};        

    if ( $imagewidth > $maxwidth ) {
        if ( $Globals{'resizeorig'} == "yes" ) {
            $resizeorig = 1;
        }
        else {
            dieWell("Your graphic is too wide!  Please upload a smaller one.");
            unlink($realname);
            exit;
        }
    }

    if ( $imageheight > $maxheight ) {
        if ( $Globals{'resizeorig'} == "yes") {
            $resizeorig = 1;
        }
        else {
            dieWell("Your graphic is too tall!  Please upload a smaller one.");
            unlink($realname);
            exit;
        }
    }
    
    // Watermark
    $watermarked = "no";
    if ( $Globals{'annotate'} == "yes") {
        // stamp the image
        watermark( $filepath );
        $watermarked = "yes";
    }

    // Resizing
    if ( $resizeorig == 1 ) {
        // if image is taller than wider, then portrait
        if ( $imagewidth > $maxwidth ) {
            $scaleFactor = $imagewidth / $maxwidth;
            $newheight = round( $imageheight / $scaleFactor );
            $newwidth = $maxwidth;
        }
        else {
            $scaleFactor = $imageheight / $maxheight;
            $newwidth = round( $imagewidth / $scaleFactor );
            $newheight = $maxwidth;
        }

        if ( $Globals{'usegd'} != 0 ) {
            $resize_worked = resize_jpeg($filepath, $filepath, $newwidth, $newheight);
        }
        else {
            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$newwidth."x".$newheight." $filepath";

            // call ImageMagick mogrify to resize the original down
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating resized original! Error code: $retval");
                unlink( $outthumb );
                unlink( $filepath );
                exit;
            }
        }

        $image_stats = getimagesize( $filepath );
        $imagewidth = $image_stats[0];
        $imageheight = $image_stats[1];
        clearstatcache();
        $imagesize = filesize( $filepath );
    }
    //##// end resize original and/or annotate original ###
    
    //##// create a medium sized graphic if the graphic is too big ###
    $createmed = 0;
    $biggraphic = $Globals{'biggraphic'};

    if ( $biggraphic > 0 ) {
        if ( $imagewidth > $biggraphic || $imageheight > $biggraphic )
            $createmed = 1;
    }

    if ( $createmed == 1 ) {
        $medium = $filenoext."-med.$theext";
        $medfile="$basedir$thecat/$userid$medium";

        if ( $imageheight > $imagewidth ) {
            $scaleFactor = $imagewidth / $biggraphic;
            $medwidth = round( $imagewidth / $scaleFactor );
            $medheight = $biggraphic;
        }
        else {
            $scaleFactor = $imageheight / $biggraphic;
            $medheight = round( $imageheight / $scaleFactor );
            $medwidth = $biggraphic;
        }

        if ( $Globals{'usegd'} != 0 ) {
            $resize_worked = resize_jpeg($filepath, $medfile, $medwidth, $medheight);
        }
        else {
            copy ( $filepath, $medfile );
            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$medwidth."x".$medheight." $medfile";

            // call ImageMagick mogrify to create the medium image
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating resized medium image! Error code: $retval<br>Command attempted: $syscmd");
                unlink( $outthumb );
                unlink( $filepath );
                unlink( $medium );
                exit;
            }
        }

        // get the proper stats
        $image_stats = getimagesize( $medfile );
        $medwidth = $image_stats[0];
        $medheight = $image_stats[1];
        $medsize = filesize( $medfile );
    }
    else {
        $medwidth = 0;
        $medheight = 0;
        $medsize = 0;
    }
    //##// end medium sized ###

    $username = addslashes( $username );
    if ( empty($title) ) $title = $filenoext;
    $ititle = urldecode( $title );
    $ititle = addslashes( $title );
    $idesc = urldecode( $desc );
    $idesc = addslashes( $desc );
    $ikeywords = addslashes( $keywords );

    $query = "INSERT INTO photos values(NULL,'$username', $userid, $thecat, $julian, '$ititle', '$idesc', '$ikeywords', '$realname', $imagewidth, $imageheight, $imagesize, '0', $medwidth, $medheight, $medsize, '1', $julian, '0', '$watermarked', '', '', '', '', '')";
    $resulta = ppmysql_query($query, $link);

    if ( !$resulta ) {
        dieWell( "Database error! Please report to System Administrator.<p>$query" );
        exit;
    }

    // end write ##
}

?>

 

thanks

Paul

Link to comment
Share on other sites

I've done some tests and if you replace the process_image function with the code below, it should now work.

 

function process_image( $realname, $filepath, $thecat ) {
    global $Globals, $userid, $link, $db_link, $uganno;
    global $username, $usergroup, $title, $desc, $keywords;
    global $adminexclude, $keywords, $notify, $resizeorig;

    list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
    $mon = $mon + 1;

if( strlen($year) == 3 ) 
	$year = substr($year, 1);

    $julian = mktime($hour,$min,$sec,$mon,$mday,$year);

    $filenoext = get_filename( $realname );
    $theext    = get_ext( $realname );
    $outfilename = "$userid$realname";
    $basedir = $Globals{'datafull'};

    $image_stats = getimagesize( $filepath );
    $imagewidth = $image_stats[0];
    $imageheight = $image_stats[1];
    $imagesize = filesize( $filepath );
    
    $resizeorig = 0;
    $maxwidth = $Globals{'maxwidth'};
    $maxheight = $Globals{'maxheight'};        

    if ( $imagewidth > $maxwidth ) {
        if ( $Globals{'resizeorig'} == "yes" ) {
            $resizeorig = 1;
        }
        else {
            dieWell("Your graphic is too wide!  Please upload a smaller one.");
            unlink($realname);
            exit;
        }
    }

    if ( $imageheight > $maxheight ) {
        if ( $Globals{'resizeorig'} == "yes") {
            $resizeorig = 1;
        }
        else {
            dieWell("Your graphic is too tall!  Please upload a smaller one.");
            unlink($realname);
            exit;
        }
    }
    
    // Watermark
    $watermarked = "no";
    if ( $Globals{'annotate'} == "yes") {
        // stamp the image
        watermark( $filepath );
        $watermarked = "yes";
    }

    // Resizing
    if ( $resizeorig == 1 ) {
        // if image is taller than wider, then portrait
        if ( $imagewidth > $maxwidth ) {
            $scaleFactor = $imagewidth / $maxwidth;
            $newheight = round( $imageheight / $scaleFactor );
            $newwidth = $maxwidth;
        }
        else {
            $scaleFactor = $imageheight / $maxheight;
            $newwidth = round( $imagewidth / $scaleFactor );
            $newheight = $maxwidth;
        }

        if ( $Globals{'usegd'} != 0 ) {
            $resize_worked = resize_jpeg($filepath, $filepath, $newwidth, $newheight);
        }
        else {
            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$newwidth."x".$newheight." $filepath";

            // call ImageMagick mogrify to resize the original down
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating resized original! Error code: $retval");
                unlink( $outthumb );
                unlink( $filepath );
                exit;
            }
        }

        $image_stats = getimagesize( $filepath );
        $imagewidth = $image_stats[0];
        $imageheight = $image_stats[1];
        clearstatcache();
        $imagesize = filesize( $filepath );
    }
    //##// end resize original and/or annotate original ###
    
    //##// create a medium sized graphic if the graphic is too big ###
    $createmed = 0;
    $biggraphic = $Globals{'biggraphic'};

    if ( $biggraphic > 0 ) {
        if ( $imagewidth > $biggraphic || $imageheight > $biggraphic )
            $createmed = 1;
    }

    if ( $createmed == 1 ) {
        $medium = $filenoext."-med.$theext";
        $medfile="$basedir$thecat/$userid$medium";

        if ( $imageheight > $imagewidth ) {
            $scaleFactor = $imagewidth / $biggraphic;
            $medwidth = round( $imagewidth / $scaleFactor );
            $medheight = $biggraphic;
        }
        else {
            $scaleFactor = $imageheight / $biggraphic;
            $medheight = round( $imageheight / $scaleFactor );
            $medwidth = $biggraphic;
        }

        if ( $Globals{'usegd'} != 0 ) {
            $resize_worked = resize_jpeg($filepath, $medfile, $medwidth, $medheight);
        }
        else {
            copy ( $filepath, $medfile );
            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$medwidth."x".$medheight." $medfile";

            // call ImageMagick mogrify to create the medium image
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating resized medium image! Error code: $retval<br>Command attempted: $syscmd");
                unlink( $outthumb );
                unlink( $filepath );
                unlink( $medium );
                exit;
            }
        }

        // get the proper stats
        $image_stats = getimagesize( $medfile );
        $medwidth = $image_stats[0];
        $medheight = $image_stats[1];
        $medsize = filesize( $medfile );
    }
    else {
        $medwidth = 0;
        $medheight = 0;
        $medsize = 0;
    }
    //##// end medium sized ###

    $username = addslashes( $username );
    if ( empty($title) ) $title = $filenoext;
    $ititle = urldecode( $title );
    $ititle = addslashes( $title );
    $idesc = urldecode( $desc );
    $idesc = addslashes( $desc );
    $ikeywords = addslashes( $keywords );

    $query = "INSERT INTO photos values(NULL,'$username', $userid, $thecat, $julian, '$ititle', '$idesc', '$ikeywords', '$realname', $imagewidth, $imageheight, $imagesize, '0', $medwidth, $medheight, $medsize, '1', $julian, '0', '$watermarked', '', '', '', '', '')";
    $resulta = ppmysql_query($query, $link);

    if ( !$resulta ) {
        dieWell( "Database error! Please report to System Administrator.<p>$query" );
        exit;
    }

    // end write ##
}

 

Mike.

Link to comment
Share on other sites

Thanks very much Mike,

 

Initially I had an error with a not expected ) here:-

else {            dieWell("Your graphic is too wide!  Please upload a smaller one.");            unlink($realname);            exit;        }    }

 

so i removed the second bracket. However, it now tells me i have  unexpected $end on the last line, which is the end php tag, so not sure what is wrong. Here is the image-inc.php file that I have now ammended... any idea why I am getting this error?

 

<?php
//////////////////////////// COPYRIGHT NOTICE //////////////////////////////
// This script is part of PhotoPost PHP, a software application by        //
// All Enthusiast, Inc.  Use of any kind of part or all of this           //
// script or modification of this script requires a license from All      //
// Enthusiast, Inc.  Use or modification of this script without a license //
// constitutes Software Piracy and will result in legal action from All   //
// Enthusiast, Inc.  All rights reserved.                                 //
// http://www.photopost.com      legal@photopost.com                      //
// Contributing Developer: Michael Pierce (danasoft.com)                  //
//                                                                        //
//            PhotoPost Copyright 2002, All Enthusiast, Inc.              //
////////////////////////////////////////////////////////////////////////////

function resize_jpeg( $image_file_path, $new_image_file_path, $max_width=480, $max_height=1600 )
{
    global $Globals;

    $return_val = 1;

    $image_stats = getimagesize( $image_file_path );
    $FullImage_width = $image_stats[0];
    $FullImage_height = $image_stats[1];
    $img_type = $image_stats[2];

    switch( $img_type ) {
        case 1: $src_img = ImageCreateFromGif($image_file_path); break;
        case 2: $src_img = ImageCreateFromJpeg($image_file_path); break;
        case 3: $src_img = ImageCreateFromPng($image_file_path); break;
        default: diewell("Sorry, this image type ($img_type) is not supported yet."); exit;
    }

    if ( !$src_img ) {
        diewell("Unable to create image [$image_file_path].<br>Please contact system administrator.");
        exit;
    }

    $ratio =  ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ;
    $new_width = ((int)($FullImage_width * $ratio));    //full-size width
    $new_height = ((int)($FullImage_height * $ratio));    //full-size height

    $ratio =  ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ;
    $new_width = ((int)($new_width * $ratio));    //mid-size width
    $new_height = ((int)($new_height * $ratio));    //mid-size height

    if ( $new_width == $FullImage_width && $new_height == $FullImage_height )
        copy ( $image_file_path, $new_image_file_path );

    if ( $Globals{'usegd'} == 1 ) {
        $full_id = ImageCreate( $new_width , $new_height );
        ImageCopyResized( $full_id, $src_img, 0,0,  0,0, $new_width, $new_height,
                    $FullImage_width, $FullImage_height );
    }
    else {
        $full_id = ImageCreateTrueColor( $new_width, $new_height );
        ImageCopyResampled( $full_id, $src_img, 0,0, 0,0, $new_width, $new_height,
                    $FullImage_width, $FullImage_height );
    }

    switch( $img_type ) {
        case 1: $return_val = ImageGIF( $full_id, $new_image_file_path ); break;
        case 2: $return_val = ImageJPEG( $full_id, $new_image_file_path, 90 ); break;
        case 3: $return_val = ImagePNG( $full_id, $new_image_file_path ); break;
        default: diewell("Sorry, this image type is not supported yet."); exit;
    }

    ImageDestroy( $full_id );

    return ($return_val) ? TRUE : FALSE ;
}

function gdwatermark($srcfilename, $watermark) {
    $imageInfo = getimagesize($srcfilename);
    $width = $imageInfo[0];
    $height = $imageInfo[1];

    $logoinfo = getimagesize($watermark);
    $logowidth = $logoinfo[0];
    $logoheight = $logoinfo[1];

    $horizextra =$width - $logowidth;
    $vertextra =$height - $logoheight;
    // middle
    //$horizmargin =  round($horizextra / 2);
    //$vertmargin =  round($vertextra / 2);
    // lower right corner
    $horizmargin =  $horizextra;
    $vertmargin =  $vertextra;

    $photoImage = ImageCreateFromJPEG($srcfilename);
    ImageAlphaBlending($photoImage, true);

    $logoImage = ImageCreateFromPNG($watermark);
    $logoW = ImageSX($logoImage);
    $logoH = ImageSY($logoImage);

    ImageCopy($photoImage, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH);

    //ImageJPEG($photoImage); // output to browser
    ImageJPEG($photoImage, $srcfilename, 90);

    ImageDestroy($photoImage);
    ImageDestroy($logoImage);
}


function create_thumb( $realname, $filepath, $thecat, $thevideo="" ) {
    global $Globals, $userid, $imagewidth, $imageheight, $thumbnail, $resizeorig, $uganno;

    //
    // NEW RESIZE CODE
    //
    $basedir = $Globals{'datafull'};
    $previewwidth = $Globals{'previewwidth'};
    
    if ( $filepath == "default" ) {
        $filepath = $Globals{'idir'}."/video.jpg";
    }

    $image_stats = getimagesize( $filepath );
    $imagewidth = $image_stats[0];
    $imageheight = $image_stats[1];
    $img_type = $image_stats[2];

    // Create thumbnails
    if ( $thevideo == "" ) {
        $filenoext = get_filename( $realname );
        $theext    = get_ext( $realname );
        $thumbnail = "$userid".$filenoext."-thumb.$theext";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    elseif ( $thevideo == "rebuildthumbnail" ) {
        $filenoext = get_filename( $realname );
        $theext    = get_ext( $realname );
        $thumbnail = $filenoext."-thumb.$theext";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    else {
        $filenoext = get_filename( $thevideo );
        $theext = "jpg";
        $thumbnail = "$userid".$filenoext."-thumb.jpg";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    $outthumb = strtolower( $outthumb );
    $thumbnail = strtolower( $thumbnail );
    
    if ( !file_exists( $outthumb ) )  {
        if ( $Globals{'usegd'} != 0 ) {
            if ( $imageheight < $imagewidth ) {
                $scaleFactor = $imagewidth / $previewwidth;
                $newheight = round( $imageheight / $scaleFactor );
                $newwidth = $previewwidth;
            }
            else {
                $scaleFactor = $imageheight / $previewwidth;
                $newwidth = round( $imagewidth / $scaleFactor );
                $newheight = $previewwidth;
            }

            $resize_worked = resize_jpeg($filepath, $outthumb, $newwidth, $newheight);
        }
        else {
            copy ( $filepath, $outthumb );

            // watermark thumbnail before resizing
            // uncomment if you want your thumbnails to have watermarks
            //if ( $uganno{$thecat} != 1 && $Globals{'annotate'} == "yes") {
            //    // stamp the image
            //    watermark( $outthumb );
            //}
            
            // if image is taller than wider, then portrait
            if ( $imageheight < $imagewidth ) {
                $scaleFactor = $imagewidth / $previewwidth;
                $newheight = round( $imageheight / $scaleFactor );
                $newwidth = $previewwidth;
                //$previewwidth = $previewwidth
            }
            else {
                $scaleFactor = $imageheight / $previewwidth;
                $newwidth = round( $imagewidth / $scaleFactor );
                $newheight = $previewwidth;
                //$previewheight = $previewwidth
            }

            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$newwidth."x".$newheight." $outthumb";

            // call ImageMagick mogrify to create the thumbnail
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating thumbnail! Error code: $retval<p>Command: $syscmd");
                unlink( $outthumb );
                unlink( $filepath );
                exit;
            }
        }
    }

    $imagesize = filesize( $outthumb );

    return( $imagesize );
}

function watermark( $filepath, $isadmin=0 ) {
    global $Globals;
    
    $agravity = $Globals{'gravity'};
    $water_image = $Globals{'watermark'};

    // need to execute this command after images:
    // composite -compose over -gravity southeast eblogo.jpg jess.jpg jesslogo.jpg

    if ( $Globals{'usegd'} != 0 ) {
        $retval = gdwatermark( $filepath, $water_image );
    }
    else {
        $composite_cmd = str_replace( "mogrify", "composite", $Globals{'mogrify_command'} );
        $stampcmd = $composite_cmd." -compose over -gravity $agravity $water_image $filepath $filepath";
        system( $stampcmd, $retval );

        if ( $retval != 0 ) {
            if ( $isadmin == 0 ) {
                dieWell("Error creating watermarked original! Error code: $retval<br><br>Command: $stampcmd");
                exit;
            }
            else {
                print "Error creating watermarked original on $filepath [$stampcmd]<br>";
            }
        }
    }
     
    return;
}
function process_image( $realname, $filepath, $thecat ) { 
global $Globals, $userid, $link, $db_link, $uganno;
global $username, $usergroup, $title, $desc, $keywords;
global $adminexclude, $keywords, $notify, $resizeorig;

list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon = $mon + 1;

	if( strlen($year) == 3 ) 
		$year = substr($year, 1);

$julian = mktime($hour,$min,$sec,$mon,$mday,$year);

$filenoext = get_filename( $realname ); 
$theext    = get_ext( $realname );
$outfilename = "$userid$realname"; 
$basedir = $Globals{'datafull'};

$image_stats = getimagesize( $filepath );
$imagewidth = $image_stats[0]; 
$imageheight = $image_stats[1];
$imagesize = filesize( $filepath );

$resizeorig = 0;
$maxwidth = $Globals{'maxwidth'};
$maxheight = $Globals{'maxheight'};

if ( $imagewidth > $maxwidth ) { 
	if ( $Globals{'resizeorig'} == "yes" ) { 
		$resizeorig = 1;       
	}       
		else {      
		dieWell("Your graphic is too wide!  Please upload a smaller one.");            
		unlink($realname);           
		exit;       
	}  


if ( $imageheight > $maxheight ) {    
	if ( $Globals{'resizeorig'} == "yes") {         
		$resizeorig = 1;        
	}       
	else {            
		dieWell("Your graphic is too tall!  Please upload a smaller one.");            
		unlink($realname);           
		exit;       
	}   
}       
// Watermark    
$watermarked = "no";    
if ( $Globals{'annotate'} == "yes") {       
	// stamp the image       
	watermark( $filepath );      
	$watermarked = "yes";   
}   
// Resizing    
if ( $resizeorig == 1 ) {     
	// if image is taller than wider, then portrait       
	if ( $imagewidth > $maxwidth ) {        
		$scaleFactor = $imagewidth / $maxwidth;           
		$newheight = round( $imageheight / $scaleFactor );           
		$newwidth = $maxwidth;       
	}       
	else {            
		$scaleFactor = $imageheight / $maxheight;            
		$newwidth = round( $imagewidth / $scaleFactor );            
		$newheight = $maxwidth;       
	}        

	if ( $Globals{'usegd'} != 0 ) {            
		$resize_worked = resize_jpeg($filepath, $filepath, $newwidth, $newheight);       
	}       
	else {       
		$syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$newwidth."x".$newheight." $filepath"; 

		// call ImageMagick mogrify to resize the original down            
		system( $syscmd, $retval );            
		if ( $retval != 0 ) {                
			dieWell("Error creating resized original! Error code: $retval");               
			unlink( $outthumb );               
			unlink( $filepath );               
			exit;           
		}      
	} 

	$image_stats = getimagesize( $filepath );       
	$imagewidth = $image_stats[0];       
	$imageheight = $image_stats[1];      
	clearstatcache();      
	$imagesize = filesize( $filepath );  
} 
//##// end resize original and/or annotate original ###  

//##// create a medium sized graphic if the graphic is too big ###   
$createmed = 0;   
$biggraphic = $Globals{'biggraphic'};  

if ( $biggraphic > 0 ) {   
	if ( $imagewidth > $biggraphic || $imageheight > $biggraphic )   
		$createmed = 1;   
	} 
	if ( $createmed == 1 ) {      
		$medium = $filenoext."-med.$theext";       
		$medfile="$basedir$thecat/$userid$medium";

		if ( $imageheight > $imagewidth ) {          
			$scaleFactor = $imagewidth / $biggraphic;           
			$medwidth = round( $imagewidth / $scaleFactor );          
			$medheight = $biggraphic;       
		}       
		else {           
			$scaleFactor = $imageheight / $biggraphic;           
			$medheight = round( $imageheight / $scaleFactor );           
			$medwidth = $biggraphic;      
		} 

		if ( $Globals{'usegd'} != 0 ) {        
			$resize_worked = resize_jpeg($filepath, $medfile, $medwidth, $medheight);       
		}     
		else {       
			copy ( $filepath, $medfile );         
			$syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$medwidth."x".$medheight." $medfile";        

			// call ImageMagick mogrify to create the medium image          
			system( $syscmd, $retval );          
			if ( $retval != 0 ) {            
				dieWell("Error creating resized medium image! Error code: $retval<br>Command attempted: $syscmd");             
				unlink( $outthumb );              
				unlink( $filepath );             
				unlink( $medium );             
				exit;         
			}     
		}       

			// get the proper stats       
			$image_stats = getimagesize( $medfile );       
			$medwidth = $image_stats[0];      
			$medheight = $image_stats[1];       
			$medsize = filesize( $medfile );  
		}   
		else {       
			$medwidth = 0;       
			$medheight = 0;      
			$medsize = 0;   
		}   
		//##// end medium sized ###  

		$username = addslashes( $username );    
		if ( empty($title) ) $title = $filenoext;    
		$ititle = urldecode( $title );   
		$ititle = addslashes( $title );  
		$idesc = urldecode( $desc );   
		$idesc = addslashes( $desc );  
		$ikeywords = addslashes( $keywords ); 

		$query = "INSERT INTO photos values(NULL,'$username', $userid, $thecat, $julian, '$ititle', '$idesc', '$ikeywords', '$realname', $imagewidth, $imageheight, $imagesize, '0', $medwidth, $medheight, $medsize, '1', $julian, '0', '$watermarked', '', '', '', '', '')";
		$resulta = ppmysql_query($query, $link);

		if ( !$resulta ) {    
			dieWell( "Database error! Please report to System Administrator.<p>$query" );      
			exit;    
			}   

			// end write ##

		}
?>

 

thanks Paul

Link to comment
Share on other sites

I've added the updated code below, you should be able to just copy and paste this into the file.

 

<?php
function resize_jpeg( $image_file_path, $new_image_file_path, $max_width=480, $max_height=1600 )
{
    global $Globals;

    $return_val = 1;

    $image_stats = getimagesize( $image_file_path );
    $FullImage_width = $image_stats[0];
    $FullImage_height = $image_stats[1];
    $img_type = $image_stats[2];

    switch( $img_type ) {
        case 1: $src_img = ImageCreateFromGif($image_file_path); break;
        case 2: $src_img = ImageCreateFromJpeg($image_file_path); break;
        case 3: $src_img = ImageCreateFromPng($image_file_path); break;
        default: diewell("Sorry, this image type ($img_type) is not supported yet."); exit;
    }

    if ( !$src_img ) {
        diewell("Unable to create image [$image_file_path].<br>Please contact system administrator.");
        exit;
    }

    $ratio =  ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ;
    $new_width = ((int)($FullImage_width * $ratio));    //full-size width
    $new_height = ((int)($FullImage_height * $ratio));    //full-size height

    $ratio =  ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ;
    $new_width = ((int)($new_width * $ratio));    //mid-size width
    $new_height = ((int)($new_height * $ratio));    //mid-size height

    if ( $new_width == $FullImage_width && $new_height == $FullImage_height )
        copy ( $image_file_path, $new_image_file_path );

    if ( $Globals{'usegd'} == 1 ) {
        $full_id = ImageCreate( $new_width , $new_height );
        ImageCopyResized( $full_id, $src_img, 0,0,  0,0, $new_width, $new_height,
                    $FullImage_width, $FullImage_height );
    }
    else {
        $full_id = ImageCreateTrueColor( $new_width, $new_height );
        ImageCopyResampled( $full_id, $src_img, 0,0, 0,0, $new_width, $new_height,
                    $FullImage_width, $FullImage_height );
    }

    switch( $img_type ) {
        case 1: $return_val = ImageGIF( $full_id, $new_image_file_path ); break;
        case 2: $return_val = ImageJPEG( $full_id, $new_image_file_path, 90 ); break;
        case 3: $return_val = ImagePNG( $full_id, $new_image_file_path ); break;
        default: diewell("Sorry, this image type is not supported yet."); exit;
    }

    ImageDestroy( $full_id );

    return ($return_val) ? TRUE : FALSE ;
}

function gdwatermark($srcfilename, $watermark) {
    $imageInfo = getimagesize($srcfilename);
    $width = $imageInfo[0];
    $height = $imageInfo[1];

    $logoinfo = getimagesize($watermark);
    $logowidth = $logoinfo[0];
    $logoheight = $logoinfo[1];

    $horizextra =$width - $logowidth;
    $vertextra =$height - $logoheight;
    // middle
    //$horizmargin =  round($horizextra / 2);
    //$vertmargin =  round($vertextra / 2);
    // lower right corner
    $horizmargin =  $horizextra;
    $vertmargin =  $vertextra;

    $photoImage = ImageCreateFromJPEG($srcfilename);
    ImageAlphaBlending($photoImage, true);

    $logoImage = ImageCreateFromPNG($watermark);
    $logoW = ImageSX($logoImage);
    $logoH = ImageSY($logoImage);

    ImageCopy($photoImage, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH);

    //ImageJPEG($photoImage); // output to browser
    ImageJPEG($photoImage, $srcfilename, 90);

    ImageDestroy($photoImage);
    ImageDestroy($logoImage);
}


function create_thumb( $realname, $filepath, $thecat, $thevideo="" ) {
    global $Globals, $userid, $imagewidth, $imageheight, $thumbnail, $resizeorig, $uganno;

    //
    // NEW RESIZE CODE
    //
    $basedir = $Globals{'datafull'};
    $previewwidth = $Globals{'previewwidth'};
    
    if ( $filepath == "default" ) {
        $filepath = $Globals{'idir'}."/video.jpg";
    }

    $image_stats = getimagesize( $filepath );
    $imagewidth = $image_stats[0];
    $imageheight = $image_stats[1];
    $img_type = $image_stats[2];

    // Create thumbnails
    if ( $thevideo == "" ) {
        $filenoext = get_filename( $realname );
        $theext    = get_ext( $realname );
        $thumbnail = "$userid".$filenoext."-thumb.$theext";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    elseif ( $thevideo == "rebuildthumbnail" ) {
        $filenoext = get_filename( $realname );
        $theext    = get_ext( $realname );
        $thumbnail = $filenoext."-thumb.$theext";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    else {
        $filenoext = get_filename( $thevideo );
        $theext = "jpg";
        $thumbnail = "$userid".$filenoext."-thumb.jpg";
        $outthumb = "$basedir$thecat/$thumbnail";
    }
    $outthumb = strtolower( $outthumb );
    $thumbnail = strtolower( $thumbnail );
    
    if ( !file_exists( $outthumb ) )  {
        if ( $Globals{'usegd'} != 0 ) {
            if ( $imageheight < $imagewidth ) {
                $scaleFactor = $imagewidth / $previewwidth;
                $newheight = round( $imageheight / $scaleFactor );
                $newwidth = $previewwidth;
            }
            else {
                $scaleFactor = $imageheight / $previewwidth;
                $newwidth = round( $imagewidth / $scaleFactor );
                $newheight = $previewwidth;
            }

            $resize_worked = resize_jpeg($filepath, $outthumb, $newwidth, $newheight);
        }
        else {
            copy ( $filepath, $outthumb );

            // watermark thumbnail before resizing
            // uncomment if you want your thumbnails to have watermarks
            //if ( $uganno{$thecat} != 1 && $Globals{'annotate'} == "yes") {
            //    // stamp the image
            //    watermark( $outthumb );
            //}
            
            // if image is taller than wider, then portrait
            if ( $imageheight < $imagewidth ) {
                $scaleFactor = $imagewidth / $previewwidth;
                $newheight = round( $imageheight / $scaleFactor );
                $newwidth = $previewwidth;
                //$previewwidth = $previewwidth
            }
            else {
                $scaleFactor = $imageheight / $previewwidth;
                $newwidth = round( $imagewidth / $scaleFactor );
                $newheight = $previewwidth;
                //$previewheight = $previewwidth
            }

            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$newwidth."x".$newheight." $outthumb";

            // call ImageMagick mogrify to create the thumbnail
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating thumbnail! Error code: $retval<p>Command: $syscmd");
                unlink( $outthumb );
                unlink( $filepath );
                exit;
            }
        }
    }

    $imagesize = filesize( $outthumb );

    return( $imagesize );
}

function watermark( $filepath, $isadmin=0 ) {
    global $Globals;
    
    $agravity = $Globals{'gravity'};
    $water_image = $Globals{'watermark'};

    // need to execute this command after images:
    // composite -compose over -gravity southeast eblogo.jpg jess.jpg jesslogo.jpg

    if ( $Globals{'usegd'} != 0 ) {
        $retval = gdwatermark( $filepath, $water_image );
    }
    else {
        $composite_cmd = str_replace( "mogrify", "composite", $Globals{'mogrify_command'} );
        $stampcmd = $composite_cmd." -compose over -gravity $agravity $water_image $filepath $filepath";
        system( $stampcmd, $retval );

        if ( $retval != 0 ) {
            if ( $isadmin == 0 ) {
                dieWell("Error creating watermarked original! Error code: $retval<br><br>Command: $stampcmd");
                exit;
            }
            else {
                print "Error creating watermarked original on $filepath [$stampcmd]<br>";
            }
        }
    }
     
    return;
}


function process_image( $realname, $filepath, $thecat ) {
    global $Globals, $userid, $link, $db_link, $uganno;
    global $username, $usergroup, $title, $desc, $keywords;
    global $adminexclude, $keywords, $notify, $resizeorig;

    list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
    $mon = $mon + 1;

if( strlen($year) == 3 ) 
    {
	$year = substr($year, 1);
    }

    $julian = mktime($hour,$min,$sec,$mon,$mday,$year);

    $filenoext = get_filename( $realname );
    $theext    = get_ext( $realname );
    $outfilename = "$userid$realname";
    $basedir = $Globals{'datafull'};

    $image_stats = getimagesize( $filepath );
    $imagewidth = $image_stats[0];
    $imageheight = $image_stats[1];
    $imagesize = filesize( $filepath );
    
    $resizeorig = 0;
    $maxwidth = $Globals{'maxwidth'};
    $maxheight = $Globals{'maxheight'};        

    if ( $imagewidth > $maxwidth ) {
        if ( $Globals{'resizeorig'} == "yes" ) {
            $resizeorig = 1;
        }
        else {
            dieWell("Your graphic is too wide!  Please upload a smaller one.");
            unlink($realname);
            exit;
        }
    }

    if ( $imageheight > $maxheight ) {
        if ( $Globals{'resizeorig'} == "yes") {
            $resizeorig = 1;
        }
        else {
            dieWell("Your graphic is too tall!  Please upload a smaller one.");
            unlink($realname);
            exit;
        }
    }
    
    // Watermark
    $watermarked = "no";
    if ( $Globals{'annotate'} == "yes") {
        // stamp the image
        watermark( $filepath );
        $watermarked = "yes";
    }

    // Resizing
    if ( $resizeorig == 1 ) {
        // if image is taller than wider, then portrait
        if ( $imagewidth > $maxwidth ) {
            $scaleFactor = $imagewidth / $maxwidth;
            $newheight = round( $imageheight / $scaleFactor );
            $newwidth = $maxwidth;
        }
        else {
            $scaleFactor = $imageheight / $maxheight;
            $newwidth = round( $imagewidth / $scaleFactor );
            $newheight = $maxwidth;
        }

        if ( $Globals{'usegd'} != 0 ) {
            $resize_worked = resize_jpeg($filepath, $filepath, $newwidth, $newheight);
        }
        else {
            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$newwidth."x".$newheight." $filepath";

            // call ImageMagick mogrify to resize the original down
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating resized original! Error code: $retval");
                unlink( $outthumb );
                unlink( $filepath );
                exit;
            }
        }

        $image_stats = getimagesize( $filepath );
        $imagewidth = $image_stats[0];
        $imageheight = $image_stats[1];
        clearstatcache();
        $imagesize = filesize( $filepath );
    }
    //##// end resize original and/or annotate original ###
    
    //##// create a medium sized graphic if the graphic is too big ###
    $createmed = 0;
    $biggraphic = $Globals{'biggraphic'};

    if ( $biggraphic > 0 ) {
        if ( $imagewidth > $biggraphic || $imageheight > $biggraphic )
            $createmed = 1;
    }

    if ( $createmed == 1 ) {
        $medium = $filenoext."-med.$theext";
        $medfile="$basedir$thecat/$userid$medium";

        if ( $imageheight > $imagewidth ) {
            $scaleFactor = $imagewidth / $biggraphic;
            $medwidth = round( $imagewidth / $scaleFactor );
            $medheight = $biggraphic;
        }
        else {
            $scaleFactor = $imageheight / $biggraphic;
            $medheight = round( $imageheight / $scaleFactor );
            $medwidth = $biggraphic;
        }

        if ( $Globals{'usegd'} != 0 ) {
            $resize_worked = resize_jpeg($filepath, $medfile, $medwidth, $medheight);
        }
        else {
            copy ( $filepath, $medfile );
            $syscmd = $Globals{'mogrify_command'}." -format $theext -geometry ".$medwidth."x".$medheight." $medfile";

            // call ImageMagick mogrify to create the medium image
            system( $syscmd, $retval );
            if ( $retval != 0 ) {
                dieWell("Error creating resized medium image! Error code: $retval<br>Command attempted: $syscmd");
                unlink( $outthumb );
                unlink( $filepath );
                unlink( $medium );
                exit;
            }
        }

        // get the proper stats
        $image_stats = getimagesize( $medfile );
        $medwidth = $image_stats[0];
        $medheight = $image_stats[1];
        $medsize = filesize( $medfile );
    }
    else {
        $medwidth = 0;
        $medheight = 0;
        $medsize = 0;
    }
    //##// end medium sized ###

    $username = addslashes( $username );
    if ( empty($title) ) $title = $filenoext;
    $ititle = urldecode( $title );
    $ititle = addslashes( $title );
    $idesc = urldecode( $desc );
    $idesc = addslashes( $desc );
    $ikeywords = addslashes( $keywords );

    $query = "INSERT INTO photos values(NULL,'$username', $userid, $thecat, $julian, '$ititle', '$idesc', '$ikeywords', '$realname', $imagewidth, $imageheight, $imagesize, '0', $medwidth, $medheight, $medsize, '1', $julian, '0', '$watermarked', '', '', '', '', '')";
    $resulta = ppmysql_query($query, $link);

    if ( !$resulta ) {
        dieWell( "Database error! Please report to System Administrator.<p>$query" );
        exit;
    }

    // end write ##
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.