Jump to content

thecommonthread

Members
  • Posts

    20
  • Joined

  • Last visited

Everything posted by thecommonthread

  1. Lol, thanks for the reply. So you're saying I can use an echo in an image then and I'm missing something? Let's just use the example from the PHP Manual (php.net/imagettftext) to create a very simple image with only a text phrase in it: <?php // Set the content-type header('Content-Type: image/png'); // Create the image $im = imagecreatetruecolor(400, 30); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = 'Testing...'; // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to the text imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> If the $font you are loading in this code exists on the server, this will just load a PNG image with the word "Testing..." Now try using a simple echo statement. Echo anything. Now try and run the PHP and it will just load as a broken image. This is why I'm looking for an alternative to echoing a json_encode(). Thanks.
  2. So traditionally you use "echo json_encode(array of data to return)" to return data to AJAX, but the problem is my PHP file is a PNG image - header("Content-type: image/png"); imagepng($image); So I can't echo anything or else the image based from a PHP file will just fail. Is there an alternative way to return data to AJAX without echoing anything? I sure appreciate any help anyone could give me. Thanks!
  3. I figured it out. In case this might help anyone, the solution that worked for me was: $y = (($standardlineheight/2)+48) - (((count($textline)-1)*$maxtextlineheight)/2); "Standard line height" is the height of the text from the top to the baseline, and the "maximum line height" is the height from the full top to the bottom of the text, which includes any descending lowercase letters.
  4. Thanks for the reply. It looks like in imagestring(), I can't specify a font size, which is something that I do need, so unfortunately I am still stuck using imagettftext(). To get a good line height, I am using imagettfbbox() with the user-selected font and font size with a few characters in it like W, f, and j to give the bounding box a chance to calculate just how tall a line could be at it's maximum. This seems to be working pretty well for spacing my lines apart from each other. To incorporate the baseline Y starting coordinate from the imagettftext(), I can basically do the same thing with the imagettfbox(), just have it calculate the height of a capital letter to determine the height from the top to the baseline of the text. But really, my formula is not working though at all before I even get to that point. I thought this would vertically align it, but it doesn't work: $y = 48-(($maxtextlineheight*count($textline))/2); // (48 is half the height of the image, count($textline) is the number of total lines) $y represents the starting Y coordinate for the first line of text, and then of course the additional lines will be $y + ($maxtextlineheight x line number). Can anyone tell me the proper math that I need here?
  5. So I have a textarea in which the typed contents post to an external PHP file using AJAX that creates a PNG image from an existing 208 x 96 PNG image with my dynamic text from the textarea on top (using the existing image as a background). I want this dynamic text to vertically align in the middle, and I have had a ton of trouble with this. First of all I should note that I needed the text horizontally centered too, but because the text needs to span multiple lines of text, I needed to use explode() for each line and tell each line to horizontally center so that my text isn't just a box of left-aligned text that is centered in the middle of the image. Here's a visual example to explain what I'm referring to: I have no problem with the horizontal alignment of the text in my code, so essentially now to properly vertically align my text in the middle, in theory I need to subtract half the total height of all the lines together from half the height of the image (which is 48 px, half of 96 px) to get my starting Y coordinate for the first line of text and then just add the line height to each additional line to flow out underneath each other sequentially. My theory is not working for me; I just can't find the solution to get it right in the middle. Unfortunately for me, this vertical centering has to be dynamic because there is a user option to select from different fonts and font sizes. I also happened to notice that when the starting Y coordinate is zero, all you can see are any tails from lowercase letters that hang down below the normal letters (like y's and p's and g's). In this dynamically created image, the textarea has the words "Example text" typed into it. In the outputted image, all you can see is the "p" hanging down into the image: And when the starting Y coordinate is 96 (the height of the image), the outputted text ends up flush with the bottom of the image, with the "p" hanging below the image: I bring this up because clearly something additionally that needs to be factored in is the fact that the Y coordinate is located at the bottom of the text, and also not underneath any "swooping under" lowercase letters (if that makes sense). So I need a correct formula to create the right Y coordinate. I have a deadline approaching and any help with this would be very much appreciated. Thanks!
  6. I used the code above: $text = preg_replace("|\n+|", "\n", $text); I couldn't get it to work, and I tried using \r or \r\n as well.
  7. I tried your first method and couldn't make it work unfortunately. If I used the explode() method, how would I remove empty lines in the array? Maybe I'm not understanding this method completely.
  8. So I have this textarea in an HTML form that I need to convert the contents of from having multiple line breaks into only one line break for each. Example: I want to convert the following: I went to the store. I had a good time. I ran into a friend. Into this: I went to the store. I had a good time. I ran into a friend. Any help would be super appreciated.
  9. Yes. lol I overlooked it because my mind registered it as some quote or reply that didn't matter. THANK YOU!
  10. Listen, I appreciate your insight on how to program an array, but I understand arrays and I am trying to find a different method. My example was just another example of the same thing: attempting to do close to the same thing as with an array except placing the object that makes the variable dynamic in the middle of the variable, not the end. I was trying to make it simple and this thread has been completely about arrays, which is the opposite of what I am trying to use in this situation. Can this be done?? Can you take the value of a variable and stick it into another variable to specify another certain variable? Another example: $box{$num}detail - what is the proper syntax outside of the array method? Obviously it's different than sticking {$num} in the center of the var.
  11. Sorry for the multiple post, but I couldn't find the answer I was looking for in the past posts. An array is not ideal in the specific placement of my code I am using since using an array I don't know how to stick the array entry number into the middle of a variable (like $the[$color]Pill), so I'm looking for an alternative syntax. So if you could PLEASE help me out, I would appreciate it so much, you have no idea. I am stuck without the arrays option in an odd series of events. So example: If I have two different variables named $theBluePill and $theRedPill and using another variable named $color that equals "Red", I want to dynamically call $theRedPill by sticking $color into the variable.
  12. Hi, so I have an easy problem that for some reason I couldn't find an answer to anywhere. :'( I have a bunch of variables like this: $pic1fileName $pic2fileName $pic3fileName $pic4fileName $pic5fileName...you get the idea So I have another variable I'm pulling from a database that specifies which number to show, so I need a variable something like this: $pic($pic_number)fileName I just don't know what the proper syntax is. Anyone? Thank you freaking much for any help; this is a lame problem.
  13. The page is located at http://www.akapa.org/events/conf_reg.php. As you can see, the javascript should be creating a hidden input tag in the form (using post method) that displays the "total" registration cost: document.getElementById('reg_price_hid_field').innerHTML='<input name="reg_price" id="reg_price" type="hidden" value="'+total+'" />'; This method works in Internet Explorer 8, but I noticed in Firefox that it didn't carry the post variable over.
  14. So I have a script that dynamically edits the innerHTML of a span. <span id="reg_opt_hid_field"><input name="reg_opt_details" id="reg_opt_details" type="hidden" value="" /></span> <span id="reg_price_hid_field"><input name="reg_price" id="reg_price" type="hidden" value="" /> Basically, if you choose certain radio button(s) in my form, it will create a hidden form value that stores the price of a service based upon the option(s) you choose. So this passes the variable fine in Internet Explorer (I tested in v., but for some reason Firefix will not pass this variable over. What the heck is the deal??? Any help would be greatly appreciated.
  15. How do check if a string has only lowercase/uppercase letters and has at least one number in it? Thanks!!
  16. Is there a way I can create an American currency without the "USD" in there? Example: money_format('%i', $number) returns: USD 1,234.56 I'm looking for code to only return: $1,234.56 Any help is much appreciated!! Thank you!
  17. I have a hidden field in my HTML form that has a single quote (') in the value. When I use that value on a next page, it is parsing it with a blackslash automatically, so on the page, it'll like one of the following examples: 4\' Board Sally\'s plate What code do I use to prevent this? I've run into this problem before and it sure seems like an easy fix, but I still haven't been able to crack it. Any help would be greatly appreciated. Thanks, thecommonthread
  18. Thanks. Sorry I wasn't a little more specific, what I meant to ask was how I turn that statement in a PHP variable? Right now I have: $sql="SELECT `local_or_national` FROM `events` WHERE `event_name`='Show 8'"; $result=mysql_query($sql); And $result returns "Resource id #2"
  19. So I'm pretty new to MySQL. I have a table named "events" and two fields, one specifying the event name (event_name) and one specifying if the pricing is based on a national or local price list (local_or_national). So here is an example table I have right now: Event name Pricing My Spectacular Eventlocal A Really Great Eventnational Cool New Showlocal Show 7national Show 8national My Eventlocal My Cool Eventnational Event #2local Event #3local Event #4local Now in a form, I have a dropdown menu box that displays the event names and a button that submits the form. Now when I go to the next page, obviously I have the event title stored in a variable, so how do I use that to ask if that event is local or national? Any help would be SOOO much appreciated. Thanks, thecommonthread
×
×
  • 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.