Jump to content

ExpertAlmost

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ExpertAlmost's Achievements

Member

Member (2/5)

0

Reputation

  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!
×
×
  • 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.