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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts

    JS, AJAX or ?? How do I do this?

    I have PHP Script that uses ImageCreateFromJPEG() to generate a "proof" from URL variables. The script works great, but I need to run this BEFORE the page loads, so that the JPG can be called on the page.

    It's working fine in Firefox, but in IE and Chrome, the page loads before the script finishes and it loads a "missing" link. if you refresh the page, the JPG loads fine, so it's still generating the JPG on the initial load, just not before the Page loads.

    I'm drawing a blank on how to run this. The script uses about 20 variables, and it's apparently too long for require or include.

    Can someone point me in the right direction for how I might accomplish this?
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Can you post the related code?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    which part? The current way that I am calling the script is sooo wrong it's not worth posting.
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    It doesn't matter, at least we can see what you've got so far. I actually don't fully get what you really wanted. And besides, you said it is working in Firefox.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    ok...just don't judge...
    this whole thing has given me nothing but migraines...

    Page:
    Code:
    <?php
    
    $URLioid = urldecode($_GET['ioid']);
    $returnioid = current(explode('-', $URLioid));
    
    $saveHere = "proofs/fcxproof".$returnioid.".jpg";
    	
    $coupon = "imagem.php?opt1value=".$_GET['opt1value']."&opt2value=".$_GET['opt2value']."&opt3value=".$_GET['opt3value']."&opt4value=".$_GET['opt4value']."&opt5value=".$_GET['opt5value']."&opt6value=".$_GET['opt6value']."&opt7value=".$_GET['opt7value']."&opt8value=".$_GET['opt8value']."&opt9value=".$_GET['opt9value']."&opt10value=".$_GET['opt10value']."&opt11value=".$_GET['opt11value']."&opt12value=".$_GET['opt12value']."&opt13value=".$_GET['opt13value']."&opt14value=".$_GET['opt14value']."&opt15value=".$_GET['opt15value']."&opt16value=".$_GET['opt16value']."&opt17value=&ioid=".$_GET['ioid'];
    
    $pressPDF = "pdfgen.php?opt1value=".$_GET['opt1value']."&opt2value=".$_GET['opt2value']."&opt3value=".$_GET['opt3value']."&opt4value=".$_GET['opt4value']."&opt5value=".$_GET['opt5value']."&opt6value=".$_GET['opt6value']."&opt7value=".$_GET['opt7value']."&opt8value=".$_GET['opt8value']."&opt9value=".$_GET['opt9value']."&opt10value=".$_GET['opt10value']."&opt11value=".$_GET['opt11value']."&opt12value=".$_GET['opt12value']."&opt13value=".$_GET['opt13value']."&opt14value=".$_GET['opt14value']."&opt15value=".$_GET['opt15value']."&opt16value=".$_GET['opt16value']."&opt17value=&ioid=".$_GET['ioid'];
    
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <style>
    #floater {
    	padding: 5px;
    	float: left;
    	height: 250px;
    }
    #inputform {
    	padding: 5px;
    	float: left;
    	width: 500px;
    	height: 250px;
    }
    #hideme {
    	display: none;
    	}
    
    </style>
    
    </head>
    
    <body text="#000000">
    
    
    <div id="floater">
        <center>
        <img src="<?php echo $coupon; ?> " alt="" />
        <img src="<?php echo $pressPDF; ?> " alt="" />
        <p>Proof your card here.<br />
        <img src="<?php echo $saveHere; ?> " alt="" /></p>
        <p><img src="<?php if ($_GET['opt3value'] == " ") {
    				echo "images/FCx.jpg";
    				}  
    			if ($_GET['opt3value'] == "Baro Companies") {
    				echo "images/Baro.jpg";
    				}
    			if ($_GET['opt3value'] == "FCx Performance") {
    				echo "images/FCx.jpg";
    				}
    			if ($_GET['opt3value'] == "Hughes Machinery") {
    				echo "images/Hughes.jpg";
    				}
    			if ($_GET['opt3value'] == "Instrumentation Services, Inc.") {
    				echo "images/ISI.jpg";
    				}
    			if ($_GET['opt3value'] == "Pierce Pump") {
    				echo "images/Piece.jpg";
    				}
    			if ($_GET['opt3value'] == "Pump Pro's") {
    				echo "images/Pump-Pros.jpg";
    				}
    			if ($_GET['opt3value'] == "Solares Controls") {
    				echo "images/Solares.jpg";
    				}?> " />
                </p>
        <form id="changeproof" name="changeproof" method="post" action="/store/?action=setitemopts&itemid=<?php echo $returnioid; ?>">
        	<input type="submit" id="needchanges" name="needchanges" value="Need Changes" />
        </form>&nbsp;&nbsp;
        <form id="approvedproof" name="approvedproof" method="post" action="/store/cart/">
        	<input type="submit" id="proofapp" name="proofapp" value="Approve and checkout" />
        </form>
        </center>
    </div>
    
    
    </body>
    </html>
    JPG Script
    Code:
    <?php
    
    //Carregar imagem
    $rImg = ImageCreateFromJPEG("images/back.jpg");
     
    //Definir cor
    $cor1 = imagecolorallocate($rImg, 162, 42, 46);
    $cor2 = imagecolorallocate($rImg, 0, 0, 0);
    
    //original with default system font
    //$text = imagestring($rImg,5,126,22,urldecode($_GET['nome']),$cor);
    
    //custom positioning an font info
    $fontsizeadj = 1.75;
    $angle = 0;
    
    $URLioid = urldecode($_GET['ioid']);
    $returnioid = current(explode('-', $URLioid));
    
    $saveHere = "proofs/fcxproof".$returnioid.".jpg";
    
    $font1 = "fonts/Gotham-Bold.ttf";
    $font2 = "fonts/Gotham-Book.ttf";
    
    $fontSize1 = 10 * $fontsizeadj;
    $fontSize2 = 6 * $fontsizeadj;
    
    $text1 = urldecode($_GET['opt1value']);
    $text1 = strtoupper($text1);
    $dimensions1 = imagettfbbox($fontSize1, $angle, $font1, $text1);
    $x1 = (imagesx($rImg) - $dimensions1[2])-49;
    
    $text2 = urldecode($_GET['opt2value']);
    $text2 = strtoupper($text2);
    $dimensions2 = imagettfbbox($fontSize2, $angle, $font2, $text2);
    $x2 = (imagesx($rImg) - $dimensions2[2])-46;
    
    $text3 = urldecode($_GET['opt3value']);
    $text3 = strtoupper($text3);
    $dimensions3 = imagettfbbox($fontSize2, $angle, $font1, $text3);
    $x3 = (imagesx($rImg) - $dimensions3[2])-46;
    
    $text41 = "E";
    $text41 = strtoupper($text41);
    $dimensions41 = imagettfbbox($fontSize2, $angle, $font1, $text41);
    $x41 = (imagesx($rImg) - ($dimensions41[2]/2))-51;
    
    $text42 = urldecode($_GET['opt4value']);
    $text42 = strtoupper($text42);
    $dimensions42 = imagettfbbox($fontSize2, $angle, $font2, $text42);
    $x42 = (imagesx($rImg) - ($dimensions42[2]))-78;
    
    if ($_GET['opt5value'] == "") {
    	$text51 = "";
    }
    else if ($_GET['opt5value'] == "Office w/Ext") {
    	$text51 = "O";
    }
    else if ($_GET['opt5value'] == "Telephone") {
    	$text51 = "P";
    }
    else if ($_GET['opt5value'] == "Fax") {
    	$text51 = "F";
    }
    else if ($_GET['opt5value'] == "Cell") {
    	$text51 = "C";
    }
    else if ($_GET['opt5value'] == "Toll Free") {
    	$text51 = "TF";
    }
    else {
    	$text51 = "";
    }
    $text51 = strtoupper($text51);
    $dimensions51 = imagettfbbox($fontSize2, $angle, $font1, $text51);
    $x51 = (imagesx($rImg) - ($dimensions51[2]/2))-51;
    
    $text52 = urldecode($_GET['opt6value']);
    $text52 = strtoupper($text52);
    $dimensions52 = imagettfbbox($fontSize2, $angle, $font2, $text52);
    $x52 = (imagesx($rImg) - ($dimensions52[2]))-78;
    
    if ($_GET['opt7value'] == "") {
    	$text61 = "";
    }
    else if ($_GET['opt7value'] == "Office w/Ext") {
    	$text61 = "O";
    }
    else if ($_GET['opt7value'] == "Telephone") {
    	$text61 = "P";
    }
    else if ($_GET['opt7value'] == "Fax") {
    	$text61 = "F";
    }
    else if ($_GET['opt7value'] == "Cell") {
    	$text61 = "C";
    }
    else if ($_GET['opt7value'] == "Toll Free") {
    	$text61 = "TF";
    }
    else {
    	$text61 = "";
    }
    $text61 = strtoupper($text61);
    $dimensions61 = imagettfbbox($fontSize2, $angle, $font1, $text61);
    $x61 = (imagesx($rImg) - ($dimensions61[2]/2))-51;
    
    $text62 = urldecode($_GET['opt8value']);
    $text62 = strtoupper($text62);
    $dimensions62 = imagettfbbox($fontSize2, $angle, $font2, $text62);
    $x62 = (imagesx($rImg) - ($dimensions62[2]))-78;
    
    if ($_GET['opt9value'] == "") {
    	$text71 = "";
    }
    else if ($_GET['opt9value'] == "Office w/Ext") {
    	$text71 = "O";
    }
    else if ($_GET['opt9value'] == "Telephone") {
    	$text71 = "P";
    }
    else if ($_GET['opt9value'] == "Fax") {
    	$text71 = "F";
    }
    else if ($_GET['opt9value'] == "Cell") {
    	$text71 = "C";
    }
    else if ($_GET['opt9value'] == "Toll Free") {
    	$text71 = "TF";
    }
    else {
    	$text71 = "";
    }
    $text71 = strtoupper($text71);
    $dimensions71 = imagettfbbox($fontSize2, $angle, $font1, $text71);
    $x71 = (imagesx($rImg) - ($dimensions71[2]/2))-51;
    
    $text72 = urldecode($_GET['opt10value']);
    $text72 = strtoupper($text72);
    $dimensions72 = imagettfbbox($fontSize2, $angle, $font2, $text72);
    $x72 = (imagesx($rImg) - ($dimensions72[2]))-78;
    
    if ($_GET['opt11value'] == "") {
    	$text81 = "";
    }
    else if ($_GET['opt11value'] == "Office w/Ext") {
    	$text81 = "O";
    }
    else if ($_GET['opt11value'] == "Telephone") {
    	$text81 = "P";
    }
    else if ($_GET['opt11value'] == "Fax") {
    	$text81 = "F";
    }
    else if ($_GET['opt11value'] == "Cell") {
    	$text81 = "C";
    }
    else if ($_GET['opt11value'] == "Toll Free") {
    	$text81 = "TF";
    }
    else {
    	$text81 = "";
    }
    $text81 = strtoupper($text81);
    $dimensions81 = imagettfbbox($fontSize2, $angle, $font1, $text81);
    $x81 = (imagesx($rImg) - ($dimensions81[2]/2))-51;
    
    $text82 = urldecode($_GET['opt12value']);
    $text82 = strtoupper($text82);
    $dimensions82 = imagettfbbox($fontSize2, $angle, $font2, $text82);
    $x82 = (imagesx($rImg) - ($dimensions82[2]))-78;
    
    $text9 = urldecode($_GET['opt13value'])." • ".urldecode($_GET['opt14value']).", ".urldecode($_GET['opt15value'])." ".urldecode($_GET['opt16value']);
    $text9 = strtoupper($text9);
    $dimensions9 = imagettfbbox($fontSize2, $angle, $font2, $text9);
    $x9 = (imagesx($rImg) - $dimensions9[2])-46;
    
    
    
    
    //custom font info
    imagettftext($rImg, $fontSize1, $angle, $x1, 94, $cor1, $font1, $text1);
    
    imagettftext($rImg, $fontSize2, $angle, $x2, 116, $cor2, $font2, $text2);
    
    imagettftext($rImg, $fontSize2, $angle, $x3, 159, $cor2, $font1, $text3);
    
    imagettftext($rImg, $fontSize2, $angle, $x41, 184, $cor2, $font1, $text41);
    
    imagettftext($rImg, $fontSize2, $angle, $x42, 184, $cor2, $font2, $text42);
    
    imagettftext($rImg, $fontSize2, $angle, $x51, 208, $cor2, $font1, $text51);
    
    imagettftext($rImg, $fontSize2, $angle, $x52, 208, $cor2, $font2, $text52);
    
    imagettftext($rImg, $fontSize2, $angle, $x61, 232, $cor2, $font1, $text61);
    
    imagettftext($rImg, $fontSize2, $angle, $x62, 232, $cor2, $font2, $text62);
    
    imagettftext($rImg, $fontSize2, $angle, $x71, 256, $cor2, $font1, $text71);
    
    imagettftext($rImg, $fontSize2, $angle, $x72, 256, $cor2, $font2, $text72);
    
    imagettftext($rImg, $fontSize2, $angle, $x81, 280, $cor2, $font1, $text81);
    
    imagettftext($rImg, $fontSize2, $angle, $x82, 280, $cor2, $font2, $text82);
    
    imagettftext($rImg, $fontSize2, $angle, $x9, 325, $cor2, $font2, $text9);
    
    
    
    // source, size, angle, x, y, colour, font, text
    
    
    //ALWAYS last - Header e output
    header('Content-type: image/jpeg');
    imagejpeg($rImg,$saveHere,100);
    
    
    ?>
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You need to have a dummy image (e.g. an image that says "Loading..." or something) and set it as the default src for the images for coupon and pressPDF. Then load the real images from the background and then set the img src once those real images are completely loaded.

    Code:
    <span id="imgContainer">
         <img src="images/loading.jpg" data-src="<?php echo $coupon; ?> " alt="Loading image..." onload="loadImage(this);" />
         <img src="images/loading.jpg" data-src="<?php echo $pressPDF; ?> " alt="Loading image..." onload="loadImage(this);" />
    </span>
    <script type="text/javascript">
    function loadImage(imgEl) {
        var img = new Image(),
            src = imgEl.getAttribute('data-src');
        img.onload = function() {
            imgEl.onload = null;
            imgEl.src = src;
        }
        img.src = src;
    }
    </script>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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