Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't call method "color resolve" on an undefined value

    Hello:

    I'm getting a "Can't call method 'colorResolve' on an undefined value..." software error message from my perl/cgi script. Here is some of the code (I highlighted the problem code in red below):

    Code:
    #!/usr/local/bin/perl5 
    
    use CGI':standard';
    use CGI::Carp qw(fatalsToBrowser);
    use GD;
    use DBI;
    use CommonSubs;
    use arrData;
    use dbInfo;
    
    
    
    
    
    
    $q = new CGI;
    
    
    
    $recId = time();
    
    $userId = $ENV{'REMOTE_USER'};
    $userInfo = &CommonSubs::DirInfo($userId);
    
    
    $from_sender = $q->param('from');
    $to_recip = $q->param('to');
    $cc_manager = $q->param('cc_manager');
    $bcc = "xxxx@xxx.com";
    $card = $q->param('card');
    $message = $q->param('message');
    
    
    
    
    my %availableCards = ("card1"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_1.jpg",
    									 "card2"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_2.jpg",
    									 "card3"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_3.jpg",
    									 "card4"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_4.jpg",
    									 "card5"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_5.jpg",
    									 "card6"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_6.jpg",
    									 "card7"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_7.jpg",
    									 "card8"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_8.jpg",
    									 "card9"		=>		"/tech/performance-culture/rewards/ecards-master/images/large_card_9.jpg");
    
    
    my $emailContent = "";
    
    
    
    
    $text = $message;
    $text=~ s/\r//g;
    @rows = split(/\n/, $text);
    
    $selCard = $q->param('card_design');
    $cardToUse = $availableCards{$selCard};
    
    @lines = ();
    
    foreach $row (@rows){
    	
    	$totalCharsInLine = $row =~ s/(.)/$1/sg;
    	
    	if ($totalCharsInLine < 35){ push (@lines, $row);}
    	else{
    		@words = split(/\s/,$row);
    		$charCntInLine = 0;
    		$line = "";
    		
    		foreach $word (@words){
    			my $charCntInWord = $word =~ s/(.)/$1/sg;
    			if(($charCntInLine + $charCntInWord)<35){
    				$line .= $word." ";
    				$charCntInLine += $charCntInWord + 1;
    			}
    			else{
    				push (@lines, $line);
    				$charCntInLine = $charCntInWord + 1;
    				$line = $word." ";
    			}
    		}
    		push (@lines, $line);
    	}
    }
    
    $lCnt .= $#lines+1;
    $lineStart = 90;
    $lineHeight = 20;
    $txtColor = $image->colorResolve(0,0,0);
    
    $container = "/opt/httpd/root-wwwin/htdocs".$cardToUse;
    $font = "/opt/httpd/root-wwwin/htdocs/tech/performance-culture/rewards/ecards-master/templ/verdana.ttf";
    
    
    $image = GD::Image->newFromJpeg($container);
    
    
    
    
    for ($i=0; $i<$lCnt; ++$i){
    	$xPos = 390;
    	$yPos = $lineStart + ($lineHeight*$i);
    	@bounds = $image->stringTTF($txtColor,$font,13,0,$xPos,$yPos,@lines[$i]);
    	}
    The strange part about this code is that I never received an error message like this when it was used in another setting where all the variables were the same as posted here.

    The web log does not reveal any error message like this.

    Thanks in advance for your help.

    Regards,
    seeker7805

  • #2
    Regular Coder
    Join Date
    Jun 2003
    Location
    Silicon Forest
    Posts
    155
    Thanks
    0
    Thanked 5 Times in 5 Posts
    It looks to me that $image hasn't been set at that line that you have highlighted, it has been set later.
    Code:
    $txtColor = $image->colorResolve(0,0,0);
    ...
    $image = GD::Image->newFromJpeg($container);
    You probably meant to have that after the $image has been created.

    As to why you saw different errors, it's entirely possible that you moved the script around or perl was updated or different arguments were used. Perl is very forgiving, to the point that you may never see an error even if there are many.

    I would suggest that you try this to catch more issues in your code:
    Code:
    use strict;
    use warnings;
    Use strict is a lot more helpful to me, but for some people it makes them have to be too specific in their perl code and that bothers them. I figure it's worth it to catch more errors.
    Whats the point of a signature?

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks CrzySdrs.

    I made the change but I'm still getting the error message:

    Code:
    $container = "/opt/httpd/root-wwwin/htdocs".$cardToUse;
    $font = "/opt/httpd/root-wwwin/htdocs/tech/performance-culture/rewards/ecards-master/templ/verdana.ttf";
    
    
    $image = GD::Image->newFromJpeg($container);
    
    $lCnt .= $#lines+1;
    $lineStart = 90;
    $lineHeight = 20;
    $txtColor = $image->colorResolve(0,0,0);
    When I run it using strict and warnings I get a bunch of needs explicit package declaration warnings, but no reference to the specific can't call method "colorResolve" on an undefined value error message.

    When I run it from the command line I get the following message:

    gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts with 0x00 0x00
    <h1>Software error:</h1>
    <pre>Can't call method &quot;colorResolve&quot; on an undefined value at addMsgToCard.cgi line 100.

    When I google this issue it is apparent that the gd-jpeg lib does not see a jpeg, when in fact the images are jpegs using the jpg extension. I changed the names of the extensions to "jpeg" but still get the same error messages.

    Again, thanks in advance for your help.

    Regards,
    seeker7805

  • #4
    Regular Coder
    Join Date
    Jun 2003
    Location
    Silicon Forest
    Posts
    155
    Thanks
    0
    Thanked 5 Times in 5 Posts
    I don't know much about GD::Image, but is it possible that you meant to do:
    Code:
    $txtColor = GD::Image->colorResolve(0,0,0);
    Whats the point of a signature?


  •  

    Tags for this Thread

    Posting Permissions

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