Jump to content

ExpertAlmost

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Everything posted by ExpertAlmost

  1. Just to close out the thread... My original file was interlaced! Makes for a quicker load but a larger file. I saved my base image as NOT interlaced and threw in a imageinterlace($BscImg, 0); to make sure that anything else I did was not interlaced. Reduced file size from 124KB to 79KB. No other changes in palette or sizes. Best of luck to all of you!
  2. Good morning Experts! My code creates a PNG file output 505 x 600 pixels, 24bit, 96dpi. The average file size is 130kb. No mystery there. Here is the mystery: when I open the file using ACDSee (v10) and then "save as" (even with the same filename), the file size SHRINKS to about 80kb. All the specs remain the same and I can see no difference in the image! How in the world... What could an ACDSee file-save-as be doing and how do I do it in PHP? Doing a file-save-as in Windows Paint has the same result! So I have tried to reduce the filesize in the code using compression and filters: from imagepng($Image, $ImageName) to imagepng($Image, $ImageName, 9, PNG_ALL_FILTERS). No difference. I tried running through PNGCRUSH, file size only goes to 112kb. The mystery is driving me crazy. Any ideas of what to check in my code or image? Any ideas of tricks to try in the code? A 30% filesize reduction is too great to ignore. I've attached a not-yet-shrunk file for your entertainment (It appears that the upload program wont allow my original as it is 120kb) Thank you in advance for all your ideas!
  3. About 20 years ago it occurred to me that software engineering was the Science of Successful Disappointments! That short bright feeling of success followed by the darkening sky of yet another bug... Right now I am enjoying that success brought about by your help! The one star that seems constant however is the communal kindness of fellow coders. Thank you all for sharing your ever precious time, hard-won expertise, and clever ideas. Should any of you ever find yourself in Thailand, let me know. Coffee and dessert are on me Apparently it is possible to create globals within functions. To complete the thread, I opted for the following (pseudo-code) solution which does work in my code: <?php first_function(); second_function() { for ($count = 0; $count < $max; $count++) { global $my_array; // make the variable global here $my_array = array(); // set the variable to an array third_function(); unset($my_array); // unset the variable here } } third_function() { global $my_array; // declare the variable as global here //...fill my global array with stuff... } ?> While I agree with the view that using globals is a dangerous thing, I have three arrays which are used almost everywhere and changed in many places. Hence the globals. Fortunately I am a strong code documenter (from years of repeated experience with "what in the world was I thinking when I wrote this?") so array changes are clearly and explicitly stated. Thank you again everyone! May your coding skies be bright and clear and path behind you littered with the desiccating corpses of vanquished bugs. alexander
  4. Thank you so much mjdamato! I'm in Asia now and time for me to get some rest. But I will try it tomorrow morning first thing. Well, second thing. Coffee first Have a great day and enjoy the good karma you are generating. alexander
  5. Thank you mjdamato! Your explanation is very thorough and instructive! Because I want to resuse the array in the loop I did not think I could create it in the main program scope. But if I can create it in the second function, that would be great. So if I understand correctly, the line in question would be: global $my_array = array[]; in the second function. As shown below? <?php first_function(); second_function() { for ($count = 0; $count < $max; $count++) { global $my_array = array[]; third_function(); unset($my_array); print('End one loop'); } } third_function() { global $my_array; //...fill my global array with stuff... } ?>
  6. Hello Ken! Thank you for your help. Unfortunately, the code is rather complex. I simplified the code considerably to shorten the post. The main question being: if I create an array in a function and declare it global in various sub-functions (which does work as expected as the variables do update), shouldn't an unset delete the array in the initial function? And why, as seen in my output, does the array in the initial calling function appear to have no contents? I have a typo which is corrected to: $my_array = array(); The code seems to work fine on the first pass of the loop. It is only on the second pass where I found that $my_array is appending to the array contents in the first pass. In short, how do I declare and array in a function. Make it global in sub-functions. (That part works already.) And then unset in the declaring function? That is what I am ultimately trying to do. Thank you again for your help! alexander
  7. Good morning! I've spent hours on this to no avail. My understanding is that unset() only deletes the copy of the variable local to the current scope. But I am getting a very different result. I have the following structure and output. What am I doing wrong? <?php first_function(); second_function() { for ($count = 0; $count < $max; $count++) { $my_array = array[]; //initialize my array, local in this scope but can be called global in nested functions print_r($my_array ); //print 1: array should be always empty but is only in empty in FIRST loop. third_function(); //fills the array with numbers, see below, nested function declaring a global array print_r($my_array ); //print 3 of my_array, should be full of numbers from third_function global changes unset($my_array); //delete my array so I can start with new array in next loop print_r($my_array ); //print 4 of my_array, should be unknown variable print('End one loop'); } } third_function() { global $my_array; //declare my global variable //...fill my now global array with stuff... print_r($my_array ); //print 2: should be filled with numbers. And it is. } ?> My output amazingly looks something like this Array() Array(45,48,38...all my numbers...) Array() ERROR: Notice -- Undefined variable: my_array End one loop Array(45,48,38...all my SAME numbers again as if array was NOT unset...) ...... The first and second print lines make sense. But shouldn't the third line be the array filled with numbers generated in third_function? The fourth line error makes sense as the variable is unset. But WHAT did I unset? The next time around in the loop, the array contains the SAME numbers from the previous loop and my new numbers simply get appended to the end of the ever growing array. Why? This should not be that difficult but seems to be driving me crazy. Any help would be greatly appreciated. alexander
  8. That's fantastic Neil! Works great. Thank you for sharing your expertise and time. And so early in the morning also Keep sharing the wealth.
  9. That does help! Thank you very much. I tried using array_search, but the problem is that in many cases, the value is repeated and array_search only returns the first value it finds. The PHP manual suggests using array_keys, but it does not seem to work in 2 dimensional arrays. Example below just returns an empty array when there are three different keys with those values: $FoundKeys = array_keys($MyArray,"ddd"); Any thoughts as to why? //init the array $MyArray['first']['col1'] = 'abc'; $MyArray['first']['col2'] = 'def'; $MyArray['first']['col3'] = 'ghi'; $MyArray['second']['col1'] = 'jkl'; $MyArray['second']['col2'] = 'mno'; $MyArray['second']['col3'] = 'pqr'; $MyArray['third']['col1'] = 'stu'; $MyArray['third']['col2'] = 'vwx'; $MyArray['third']['col3'] = 'yz'; $MyArray['fourth']['col1'] = 'ddd'; $MyArray['fourth']['col2'] = 'b2b'; $MyArray['fourth']['col3'] = 'c3c'; $MyArray['fifth']['col1'] = 'ddd'; $MyArray['fifth']['col2'] = 'eee'; $MyArray['fifth']['col3'] = 'fff'; $MyArray['sixth']['col1'] = 'ggg'; $MyArray['sixth']['col2'] = 'hhh'; $MyArray['sixth']['col3'] = 'iii'; $MyArray['seventh']['col1'] = 'ddd'; $MyArray['seventh']['col2'] = 'kkk'; $MyArray['seventh']['col3'] = 'lll'; //print out values based on key print"{$MyArray['third']['col2']}</br>"; $Keys = array_keys($MyArray); print "{$MyArray[$Keys[2]]['col2']}</br>"; //search for values and return the keys, should be three instances. $FoundKeys = array_keys($MyArray,"ddd"); print_r($FoundKeys);
  10. Good morning! I have a two dimensional array, basically a table (see code below). I want to get a value from the array using two methods: 1) Using the row's key: $NewValue = $MyArray[$UniqueKey]; 2) Using the row's index (row number, so to speak): $NewValue = $MyArray[$RowNumber]; The second print statement in the code below does not work. Both print statements should output the same value. Is there an easy way to do this? The table has hundreds of rows and I will not know the key value of row 879 nor can I generate it. So I cannot use array_keys(). And I DO NOT want to start at the first row and count up to the 879th row. Any clever ideas to share and enlighten? Thanks! <?php // Initialize the array keys and values $MyArray = array(); $MyArray['first']['col1'] = 'abc'; $MyArray['first']['col2'] = 'def'; $MyArray['first']['col3'] = 'ghi'; $MyArray['second']['col1'] = 'jkl'; $MyArray['second']['col2'] = 'mno'; $MyArray['second']['col3'] = 'pqr'; $MyArray['third']['col1'] = 'stu'; $MyArray['third']['col2'] = 'vwx'; $MyArray['third']['col3'] = 'yz'; $MyArray['fourth']['col1'] = 'a1a'; $MyArray['fourth']['col2'] = 'b2b'; $MyArray['fourth']['col3'] = 'c3c'; $MyArray['fifth']['col1'] = 'ddd'; $MyArray['fifth']['col2'] = 'eee'; $MyArray['fifth']['col3'] = 'fff'; // Two methods to get a value. Second one does nothing. print"{$MyArray['third']['col2']}</br>"; print"{$MyArray[2]['col2']}</br>"; ?>
  11. Thank you gizmola! That is helpful. One thing I cannot figure out however is how to include input variables when I do not have a POST/GET/FORM from the client? For example: my_php_program(var1,var2,var3).php The cron examples I find just have my_php.php. Calls the program but no inputs... Thank you again
  12. Good morning! I need a control program that runs continuously on the server and waits for a time/date/file-found trigger to initiate one of several PHP processes. Each PHP process being initiated requires one or more input variables from the control program: My_PHP_Program(Var1, Var2, Var3). No user/client-side calls (no forms) are made with no HTML output being produced. Each PHP process just generates files which are later accessed by user/client-side page calls in the usual manner. Can someone provide me with code examples/pointers? (I am assuming that my host site will run Unix/Linux but I will also want to test this locally on my WinXP Apache server.) Pseude-code example: My_Control_Program waits for new hour to begin then On Hour: My_Control_Program calls PHP program: Collect_Data(HourData) to collect hour data and generate a new file: NewHourDataFile My_Control_Program checks every minute for NewHourDataFile When NewHourDataFile exists, My_Control_Program calls PHP program: Build_Graphics(NewHourDataFileName) to generate new hour graphics for all users. My_Control_Program waits/checks ... Thank you everyone!
  13. It is financial data...so the arguments abound about various curves fitting and various fixes to various curves making things fit, etc. Cubic spline interpertation is certainly close enough. Rather than spend 20 hours coding and testing php splines code, I would go to linear if I had to. I was just hoping for some luck. Cubic splines is not a new process nor is approximating areas under curves using trapezoids (Riemann sums). I am actually a bit suprised these are not in the PHP library! What happened? hahahaha Hoping for the best
  14. "Hardcore" is a great word for it Actually, I have a set of 50 data points, with some of the points clustered. This is not for a graphics application, but for a statistical one. What I eventually need to do is find the points that approximate 5%, 80% and 95% areas under the curve described by those points. Rarely (eg. randomly) will my actual data points hit those values. Similar to an approximation done under a bell curve but I do not have the luxury of that simplicity. Once I figure out how to do the cubic spline interpolation, I was going to use a simple trapazoidal method. Another piece of PHP code I hope to find Of course if I found a piece of code that gave me the solutions for 5%, 80% and 95% areas under a curve given a set of data points.....well....I could....take a nap Any ideas? (for the math or code --- naps I can manage) Thanks
  15. Good morning! I have a set of discrete data points from which I need to interpolate new values. My (neophyte) mathematical research suggests that cubic spline interpolation gives the best result with the least amount of calculation overhead. I expected to find any number of functions in PHP (input two x,y points, and a point to interpolate: output the interpolated point) but cannot find any. I find C/C++ code, Matlab, even VBA. I could probably port some of that code over, but can anyone point me to so tested-ready-to-run code? Thanks!
  16. Thank you everyone for sharing your time, experience and clarity! I have a whole new coding direction to pursue tomorrow (I'm in Asia right now) and feel confident in making great strides--thanks to all of you A large element of my confusion is I keep thinking in terms of "C/C++" when approaching HTML. Experience is helpful, until it's not. Gratefully, ExpertAlmost (Not really, but it sounded a whole lot better than "IdiotAlready.")
  17. Actually, I would consider it a great step forward to get to the "confused" level Thank you! Looks simple enough. But to a simpleton, everything looks simple! 5555 So I do NOT have to use a header redirect? The page, when complete, can point back to itself? And that is the loop? Looks like I missed something critical in my studies. My php code determines file name and location of the next/previous image. So is this correct for the pseudo code in my HTML file: 1) php: Check $_post for any input. 2) php: If input, generate new filename, else use default name. (I can put 1 and 2 in a separate php file right?) 3) HTML: Show image as specified by the name variable. 4) HTML: Form submit buttons for next/previous. 5) ??? Go back to the top of the page when a button is clicked. If that IS correct, the implementation of that last step is not clear. How do I get back to the top of my page when a button is clicked? Is there an HTLM code for that? Do I open another php block? Is there a property I do not understand? WOW! I feel like we are getting so close...to an solution! I've written alot of PHP but no HTML (obviously). You guys are great
  18. Well...when it comes to being stupid...I always wish I was kidding Thank you all for your gracious assistance. Suddenly, "impossible" seems obviously possible. However, it seems I still have a serious conceptual disconnect. Just how would I: Show an image, accept a submit click to determine a new image, show the new image...repeat? In other words: Show_Image-->On_Submit_Calc_Next_Image-->Show_Image-->repeat... And I want to keep my code as modular as possible: the bulk of the php processing in a separate file from the HTML code. Any conceptual assistance, web links to reference pages and/or code snippets would be very much appreciated. And I will try to keep my kidding down to a minimum
  19. Thank you Alex!!! Yes of course I have all that html to output the first page. I broke up the programs functionality between two files so that I could show an image, do some processing, show a new image...so on and so forth. All that header information is on the first page/file: MM_Output2. That page outputs a table with some images and my Next/Previous buttons. It then calls my second file, MM_GetImage, which calculates the next image to display based on either Next or Previous being submitted. Basically we just loops between those two pages. Show_Image--Calc_Next_Image_On_Submit--Show_Image...repeat... Perhaps I have a major conceptual disjunct? How am I not seeing this correctly?
  20. Using IE 7, I get a "Headers Already Sent Error" Even after having checked for all the usual suspects: 1) preceeding output/lines/blank spaces, no blank lines/spaces after my php block in an included file, 2) no BOM set (in Adobe Dreamweaver), 3) no virtual includes, session starts, cookies (header sending functions) I have two stripped down simple test files: MM_Output2.php and MM_GetImage.php. MM_Output2.php, some standard HTML and 3 php lines: <!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>MyTest</title> <body> <?php include("MM_GetImage.php"); ?> </body> </html> And MM_GetImage.php, again 3 lines only!: <?php header("Location: MM_Output2.php"); ?> Any expert ideas why I would be getting a Header already sent message? Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\MM_Output2.php:7) in C:\AppServ\www\MM_GetImage.php on line 2 Interestingly, if I place the header redirect line BEFORE the PHP code block in the second file, my code works fine with NO header error. But oddly it then outputs the text: header("Location: MM_Output2.php"); to the top of the page! Why is that? In brief, I want to use my MM_Output2 file to display a graphic with Next/Previous Submit Form buttons below it. That calls MM_GetImage to determine the name/location of the new image to display and sends that variable back to MM_Output2. Basically allowing a user to scroll through a set of images. I've spent hours playing with this and reading the same "things to look for..." on 15 different websites...and still no success. Please save this sinner from software purgatory :-\ Thank you!!!
  21. Thank you for your reply Russell! I had wondered about that option. I am thinking that that might be why my rectangular arrows from Corel look great at small angles off the horizontal while the PHP lines are so jagged. Have you tried that option? If I create a PNG in PHP, will it behave the same as a PNG with transparent background created in a graphics program? I have had problems in the past wth overlaying one PHP-created graphic onto another... In detail, are you suggesting creating a very large retangular arrow, for example, in PHP, then resizing it to half size using imagecopyresized? Then doing a second image copy using imagelayereffect = overlay? Thanks!
  22. When using PHP to draw lines or rectangles that are neither horizontal nor vertical, the lines are not smooth. Are there any tricks to getting a really fine-grained, smooth, angled-line in PHP? As a work-around, I have drawn hundreds of shapes in Corel Draw and exported them as transparent-background PNG files. When I need a shape, I overlay them onto my PHP created image. Which means I have hundreds of static, uniquely named graphics files. There has to be a better way! Why can I draw and import a smooth-lined rectangle from Corel but can't draw a rectangle as smoothly with PHP? Soon I will have to change graphic sizes forcing me to redraw and resave all those static images. Nightmare! Being able to dynamically draw my images in PHP would be magnificent. Any and all insights are greatly appreciated. Thank you!
  23. Thank you for the kindness of your reply kenrbnsn! That works great. But... Perhaps a more detailed description of what I am trying to do is in order. Rather than show 25 images (in a row or column formation), or one big composite image containing the 25 images -- I want to see in one location on one page, a graphic changing 25 times, once for each iteration of generation. Perhaps thinking of it as an animation makes more sense? If the loop is too fast, I can always put in a delay. Perhaps it is impossible to do this in PHP and all I can do is 25 images in a line? Thanks again to all of you ExpertsAlready for your help!
  24. Good morning! I have some simple test code (below) that generates a random image of 100x100 pixels. I have a loop to generate a new image 25 times. I want to see each of those 25 runs. But this code only shows what may be the last image. What did I do wrong? How can I automatically update newly generated images in PHP? Thank you for your expertise! <?php header ("Content-type: image/png"); $ImageSize = 100; $Img = imagecreatetruecolor($ImageSize, $ImageSize); for ($Runs = 0; $Runs < 25; $Runs++) { for ($XVal = 0; $XVal < $ImageSize; $XVal++) { for ($YVal = 0; $YVal < $ImageSize; $YVal++) { $RedVal = rand(0, 255); $GreenVal = rand(0, 255); $BlueVal = rand(0, 255); $PixelClr = imagecolorallocate($Img, $RedVal, $GreenVal, $BlueVal); imagesetpixel($Img, $XVal, $YVal, $PixelClr); imagecolordeallocate($Img, $PixelClr); } } imagepng($Img); imagedestroy($Img); } ?>
  25. My apologies for the poorly communicated question! How do I use imagecolorallocate() to allocate colors with a GLOBAL scope for a single image across functions (passing the image as a function input)? AND, how can I allocate a single color for multiple images without calling imagecolorallocate() multiple times for the same color but a different image name? Hope this is more clear. Thank you for your patience and guidance!
×
×
  • 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.