Help fixing lightbox code

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by ben reilly tribute, Aug 2, 2013.

  1. ben reilly tribute

    ben reilly tribute New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Hey guys,

    Very recently images that needed to be resized to fit the screen (and become links to view the full size image) on my lightbox site have stopped loading:

    http://www.benreillytribute.x10host.com/enforcer/

    Could anyone let me know where to fix my code so this stop happening?
     
  2. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    The problem is in the image resizer PHP page; it's throwing the following errors instead of an image:

     
  3. ben reilly tribute

    ben reilly tribute New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    it must be due to some update, right? Any idea how I fix the code?
     
  4. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    I can't see the code, just the results of the code. The first error you can get rid of by setting the error reporting levels ("Strict standards" means that that part of the code is stylistically and idiomatically wrong and may break altogether in a future PHP version, but it's working for now); but the other two mean that the code is actually broken (the first warning means that output has begun before a header() call is made; the second warning is a less-subtle error). You would need to post the code if you want help.
     
  5. ben reilly tribute

    ben reilly tribute New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Sure, can you tell me which file you need the code from?
     
  6. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    I'd say it's /home/enforcer/public_html/enforcer/libraries/thumb.display.php, going by the error messages I posted above. (And I despair somewhat that you needed to ask. That doesn't bode well for any follow-on problems that may arise.)
     
  7. ben reilly tribute

    ben reilly tribute New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    I'm sure i'll be able to handle it.
    PHP:
    <?php

     
    /**
      * THUMBS DISPLAY
      */

        //// import init file ////
        
    require_once("general.bootstrap.php");
       
        
    error_reporting(E_ALL);
       
        
    //// debug mode
        
    $th_debug_flag false;//$settings['thumbnail_debug'];
       
        
    $error_msg '';
        
    $center_image true;
       
        
    $img_types = array(
            
    "",
            
    "GIF",
            
    "JPG",
            
    "PNG",
            
    "SWF",
            
    "PSD",
            
    "BMP",
            
    "TIFF",
            
    "TIFF",
            
    "JPC",
            
    "JP2",
            
    "JPX",
            
    "JB2",
            
    "SWC",
            
    "IFF",
            
    "WBMP",
            
    "XBM"
        
    );
       
        
    // debug
        
    $th_debug = (isset($settings['thumbnail_debug']))
            ? 
    $settings['thumbnail_debug']
            : 
    false;
       
        
    // check if image path is encoded
        
    $en = (isset($_GET["en"]))
            ? 
    true
            
    false;
       
        
    //// receives the original image as [?img=relative/path/to/image.jpg] ////
        // get image path
        
    $img false;
        if (isset(
    $_GET["img"])) {
            if (
    $settings['set_double_encoding']) {
                
    $img "../".Url_decode(htmlentities($_GET["img"]));
            } else {
                
    $img "../".str_replace("\\","",htmlentities($_GET["img"]));
            }
        } else {
            
    $img false;
        }
       
        
    // check if big image to cache
        
    $pic = (isset($_GET["pic"]))
            ? 
    true
            
    false;
       
        
    $_prefix = ($pic)
            ? 
    $settings['image_prefix']
            : 
    $settings['thumbnail_prefix'];
       
        
    // image is square?
        
    $sq = (isset($_GET["sq"]))
            ? 
    htmlentities($_GET["sq"])
            : 
    false;
       
        
    // image is preview thumbnail
        
    $pr = (isset($_GET["pr"]))
            ? 
    htmlentities($_GET["pr"])
            : 
    false;
       
        
    // image max size
        
    $img_maxsize = (isset($_GET["max"])) ? htmlentities($_GET["max"]) : 80;
       
        
    // image quality
        
    $img_quality = (isset($_GET["q"]))
            ? 
    htmlentities($_GET["q"])
            : ((
    $sq)
                ? ((
    $pr)
                    ? 
    $settings['preview_thumbnail_quality']
                    : 
    $settings['thumbnail_quality'])
                : 
    $settings['thumbnail_quality']);
       
        
    // cache thumbnail
        
    $cache_thumb = (isset($_GET["c"]))
            ? 
    true
            
    false;
       
        
    // delete existing thumbnail
        
    $unlink = (isset($_GET["u"]))
            ? 
    true
            
    false;
       
        
    $thumb '';   
        
    $image '';
       
        if (
    $img && file_exists($img)) {
           
            
    //// get image size ////
            
    $img_info getimagesize($img);
           
            if (
    $img_info) {
               
                
    //// resize image ////
                
    $img_type $img_types[$img_info[2]];
                
    $th_w $img_info[0];
                
    $th_h $img_info[1];
                
    $move_w $move_h 0;
                
    $w $h 0;
               
                if (
    $th_w >= $th_h) {
                   
                    
    //// Landscape Picture ////
                    
    if ($sq) {
                        
    $h $img_maxsize;
                        
    $w = (($th_w $h) / $th_h);
                        
    $move_w = (($th_w $th_h) / 2);
                        
    $w $img_maxsize;
                        
    $th_w $th_h;
                    } else {
                        
    $w $img_maxsize;
                        
    $h = (($th_h $w) / $th_w);
                    }
                   
                } else {
                   
                    
    //// Portrait Picture ////
                    
    if ($sq) {
                        
    $w $img_maxsize;
                        
    $h = (($th_h $w) / $th_w);
                        
    $move_h = (($th_h $th_w) / 2);
                        
    $h $img_maxsize;
                        
    $th_h $th_w;
                    } else {
                        
    $h $img_maxsize;
                        
    $w = (($th_w $h) / $th_h);
                    }
                }
               
                
    //// create image ////
                
    $thumb imagecreatetruecolor($w$h);
                
    imagefill($thumb255255255);
               
                
    //// copy image ////
                
    if (($img_type == "JPG") && (imagetypes() & IMG_JPG)) {
                    
    $image imagecreatefromjpeg($img);
                   
                } else if ((
    $img_type == "GIF") && (imagetypes() & IMG_GIF)) {
                    
    $image imagecreatefromgif($img);
                   
                } else if ((
    $img_type == "PNG") && (imagetypes() & IMG_PNG)) {
                    
    $image imagecreatefrompng($img);
                   
                }
            } else {
                
    $error_msg "!! BAD IMG";
            }
        }
       
        
    //// if there's an error reading the original image
        //// output an error image
        // see if it failed
        
    if (!$th_debug_flag && (!$image $image=='' $error_msg!='')) {
           
            
    // do not cache
            
    $cache_thumb '';
            
    $error_size $img_maxsize;
            
    // create a white image
            
    $thumb  imagecreatetruecolor($error_size$error_size);
            
    $lightgrey imagecolorallocate($thumb234234234);
            
    $grey imagecolorallocate($thumb666666);
            
    $black  imagecolorallocate($thumb000);
            
    $white  imagecolorallocate($thumb255255255);
            
    $orange  imagecolorallocate($thumb255660);
            
    $bg_color $grey;
            
    $fg_color $white;
            
    imagefilledrectangle($thumb00$error_size$error_size$bg_color);
               
            
    // output an errmsg
            
    $fnum = ($img_maxsize >= 70) ? 1;
            
    $msg_height 12;
            
    $msg_array explode(":",$error_msg);
            for (
    $i=0$i<count($msg_array); $i++) {
                
    imagestring($thumb$fnum22+($msg_height*$i), $msg_array[$i], $fg_color);
            }
       
            
    /// up the image quality
            
    $img_quality 100;
           
        } else {
            
    $created imagecopyresampled($thumb$image00$move_w$move_h$w$h$th_w$th_h);
           
        }
       
        
    //// cache images (if enabled)
        //$current_gallery = array_pop(split("/", dirname($img)));
        
    $current_gallery array_pop(explode("/"dirname($img)));
        
    $cache_thumb_dir "../cache/"
            
    .$settings['gallery_prefix']
            .
    $current_gallery;
           
        
    $thumb_url $cache_thumb_dir."/"
            
    .$_prefix
            
    .basename($img);
           
        if (
    $unlink$delete = @unlink($thumb_url);
       
        if (
    $cache_thumb) {
            
    $thumbCreated imagejpeg($thumb$thumb_url$img_quality);
        }
       
        
    //// display created image ////
        
    header("Content-type: image/jpeg");
        
    imagejpeg($thumb''$img_quality);
       
        
    //// destroy images (free memory)
        
    imagedestroy($image);
        
    imagedestroy($thumb);
       
        
    /* END */
    ?>
     
    Last edited by a moderator: Aug 5, 2013
  8. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    Okay. The "headers already sent" is happening because there is whitespace before the opening <?php tag. That is already echoed to the browser as a literal string, including (at least) the line break with the default MIME type for a PHP page (which is likely text/html), so you cannot later try to change the headers/MIME type for the response.

    The "Fileneame cannot be empty" is happening because the call to imagejpg() looks like this:

    PHP:
       imagejpeg($thumb''$img_quality);
    ... with the filename parameter set to an empty string. The "Strict standards" warning is because you are using dirname($img) as an argument to the explode() function instead of setting a variable to the result of dirname($img) and feeding that to explode. Again, that's a stylistic matter, which you can safely suppress by setting the warning levels on line 10 (or 11, depending on how you count it) to:

    PHP:
        error_reporting(E_ALL E_STRICT);
    (XOR-ing out E_STRICT from E_ALL will report all errors except the "strict standards" errors.)
     
  9. Skizzerz

    Skizzerz Contributors Staff Member Contributors

    Messages:
    2,929
    Likes Received:
    118
    Trophy Points:
    63
    @essellar: The headers already sent was from array_pop throwing a warning due to being passed the return value of explode() instead of a variable containing an array, the whitespace above the <?php was a mistake I made when editing in [php] around the code so it was actually readable, fixed that up now.
     
  10. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    That still leaves the other two.
     
  11. ben reilly tribute

    ben reilly tribute New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for the thorough review... I'm not sure what changes I need to make outside of adding

    PHP:
    error_reporting(E_ALL E_STRICT);
    to line 10. I have added this code to the live site.

    Will this address the problem or simply help figure out exactly what the issue is? I appreciate your thorough response and feedback, however I will require guidance on what exactly you'd like for me to do in order to proceed.
     
  12. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    You'll need to give the image a filename instead of the empty string in the line I noted above as well.
     
  13. ben reilly tribute

    ben reilly tribute New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Should I be renaming the files to some sort of specific naming convention then? I think the string is empty because it's variable...?

    It seems that the functionality has now gotten worse, with thumbnails in the top carousel no longer loading.
     
  14. ben reilly tribute

    ben reilly tribute New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Anyone? What filename should I give it that won't cause an error?
     
  15. gomarc

    gomarc Member

    Messages:
    516
    Likes Received:
    18
    Trophy Points:
    18
    Hello ben reilly tribute,

    Try renaming your folder /Action Photos/ to /action_photos/ or something without the white space.

    You may have missed these instructions on the installation guide: http://minishowcase.net/instructions/#installing
     
  16. ben reilly tribute

    ben reilly tribute New Member

    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Thanks gomarc.

    This didn't fix it. Not sure if I mentioned... this site all worked perfectly for a couple years and only recently started to have issues.
     

Share This Page