Jump to content
Larry Ullman's Book Forums

Necuima

Members
  • Posts

    359
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Necuima

  1. Hi Larry, HartleySan, Do you know how to include a simple link to a website owner's Facebook page in PHP? Or where I can find out? Many thanks in anticipation, Necuima.
  2. To make it even more efficient, I have now combined the resize and crop into one method. Cheers
  3. To get over the file save then read inefficiency, I have now extended the SimpleImage class to include a crop method. It is working fine:-) Cheers
  4. Yes, it was a bit funny but also a bit embarassing! It just so happened that the jpg image that I was experimenting with had a patch of pale blue sky in the left hand top corner - it was almost white. So what I was mis-interpreting was that crop, which looked blank, was not working but in fact it was a perfectly good grop of near-white sky! Traps for young players!! Thanks again for your interest and help. Cheers from Oz.
  5. Hi HartleySan, Thank you for your interest and willingness to help. I may not have been clear in what I was trying to accomplish - it was to be able to take any reasonable-sized jpg image of whatever (rectangular) shape and from that create a square thumbnail jpg file of a specified (smallish) size. I found out that my code was sort of working though I did not realise it at the time. After much trial and error I found that what works for me is to first resize the largish jpg file down to a smaller one and I do this with the SimpleImage class from Simon Jarvis (thanks Simon) and then crop the smaller image by either chopping off equal parts of the left and right sides if it's landscape or chopping off equal parts of the top and bottom if it's portrait. I then end up with a nice thumbnail with most of the scene in it though small and square. The process is not very efficient as the SimpleImage processing first reads the larger file and then saves it back into its original directory though smaller now. Then the cropping logic reads the just-created small jpg image file, crops it and then writes the cropped file back out to the original directory though I give it a modified name. It all works though there's probably a more efficient way. Cheers from Oz.
  6. Hi HartleySan, I tried to reply with the code that I finally got to work but it would not let me post my reply. If you have an email address or other means of communication, I will be happy to send you my code. Thanks again for your help. Cheers from Oz.
  7. Hi Larry, I have another piece of code that I just can't make work properly. I have Googled and I think that I'm using the correct code but all I get is a jpg image of the correct size and shape but it is blank. $newname is a relative URL to a large jpg image file that I know is there. I need a square thumbnail jpg image so I'm trying to crop the original image correctly to a square and also downsize it. I definitely have the GD library in my PHP. // crop and resize the image file // Get dimensions of the original image list($current_width, $current_height) = getimagesize($newname); echo "<p><font color='yellow'>Current width is $current_width, current height is $current_height.</font></p>"; // now work out the x and y coordinates on the original image where we // will begin cropping the image if ($current_width > $current_height) { // image type = "Landscape" $left = ($current_width - $current_height) / 2; $top = 0; $new_width = $current_width - (2 * $left); $new_height = $current_height; } elseif ($current_height > $current_width) { // image type = "Portrait" $top = ($current_height - $current_width) / 2; $left = 0; $new_width = $current_width; $new_height = $current_height - (2 * $top); } else { // image is square $top = 0; $left = 0; } // This will be the final size of the image (e.g. how many pixels // left and down we will be going) $crop_width = (int) $_POST['size']; $crop_height = (int) $_POST['size']; echo "<p><font color='yellow'>Parameters are left: $left, top: $top, new width: $new_width, new height: $new_height.</font></p>"; // Resample the image $canvas = imagecreatetruecolor($crop_width, $crop_height); $current_image = imagecreatefromjpeg($newname); imagecopy($canvas, $current_image, 0, 0, $left, $top, $new_width, $new_height); // imagecopy($canvas, $current_image, 0, 0, 0, 0, $current_width, $current_height); /* the imagecopy parameters are: 1) Destination image link resource 2) Source image link resource 3) x-coordinate of destination point 4) y-coordinate of destination point 5) x-coordinate of source point 6) y-coordinate of source point 7) Source width 8) Source height */ header('Content-Type: image/jpeg'); imagejpeg($canvas, $newname, 100); Any help will be appreciated. Cheers from Oz.
  8. Hi HartleySan, Larry, So obvious!!! You know that I looked at that code till I was blue in the face, to use a local colloquialism, and didn't see that spurious semi-colon!! Many many thanks!! Cheers from Oz:-)
  9. Hi Larry, I'd like to ask help with a problem that I am experiencing with an HTML table which is generated by PHP echos. When it renders in a browser, four spurious sem-colons appear at the top of the table - in Firefox they are aligned horizontally; in IE9 they are aligned vertically, both on the left hand side of the area immediately above the table itself. Maybe relatedly the table has four columns. It does not need or have a header but I have tried adding blank <th></th> pairs but it makes no difference. The table itself renders perfectly. echo '<table>'; .... other MySQL code here ... echo "<tr> <td rowspan='2'> <div align='center' class='index_table_icon'> <a href='./link to the page that this icon refers to'> <img src='$icon1' alt=''> </a> </div> </td> <td valign='bottom'> <a class='text_link' href='./link to the page that this icon refers to'> $cats[2] </a> </td> <td rowspan='2'> <div align='center' class='index_table_icon'> <a href='./link to the page that this icon refers to'> <img src='$icon2' alt=''> </a> </div> </td> <td valign='bottom'> <a class='text_link' href='./link to the page that this icon refers to'> $cats[4] </a> </td> </tr>; <tr> <td> <p class='index_maintext'> $cats[5] </p> </td> <td> <p class='index_maintext'> $cats[6] </p> </td> </tr> <tr> <td> </td> </tr>"; echo "</table>"; My environment is a Win 7 64 bit PC, Firefox, IE9, Apache, PHP, MySQL. All executions are via localhost. Many thanks in anticipation for any assistance that can be provided. Best regards, Necuima
  10. Hi HartleySan, Many thanks for this information. In this particular program, I will use Larry's PHP REDUX approach (pp 91 and onwards) instead of the AJAX approach. Cheers from Oz.
  11. Hi Larry, I regularly use the move_uploaded_file function as described in chapter 11 of the book. However the other day I wanted to use it in a form the data of which gets processed via a JQuery AJAX POST call. The form enables the user to select a file for uploading and I was wanting the AJAX-called PHP script to then process it including the move-uploaded_file logic. But it seems that the $_FILES super global values are not visible to the AJAX-called PHP script. Does this sound right? FYI the $_FILES data are visible if I use your technique where the form script calls itself with an 'is submitted' check. (Page 91....). Your insights will be appreciated. Thanks, and Cheers from Oz.
  12. Hi Larry, Thanks for checking this out. I was wondering if I was going a bit crazy!! I have tried putting an hour (an integer) in gmmktime and it gives varying results depending on what integer you use and what time of day you run the script. Your echo above works just fine for the time differential, but the gmmktime(n) function on its own will not give you a timestamp for GMT unless you use the correct value for 'n', and that value is not the time differential between your time zone and GMT (well it may be for one particular hour of the day). Weird eh! I suggest that we close this thread. From my tinkering about I can reliably get the timestamp for GMT/UTC via the code in an earlier post. Thank you for your interest. Best regards from Oz.
  13. Hi Larry, It is not a silly question at all - in fact I have been pondering this in some depth over the last few days. Here's my logic: 1) I do gmdate("Y-m-d H:i:s") and then print it out and it is indeed UTC/GMT. 2) I parse out the values and then do $utcxx = mktime($hour, $min, $sec, $mm, $dd, $yr) (page 114 of your PHP & MySQL book 2nd edition) 3) I var_dump $utcxx and it gives me a timestamp. 4) I then do $utcU = gmmktime() and then var_dump it out and it gives me a different timestamp. 5) I then subtract the step 2 timestamp value from the step 4 timestamp value, divide by 3600, and it gives the correct time differential between my time zone and UTC (+10 hours). Thus I conclude that the gmmktime function gives me a timestamp value for my location, not GMT/UTC. Am I going nuts?? Thanks, Necuima.
  14. Hi Larry, I tried: $utcU = gmmktime(); but it returns the timestamp for my timezone, not GMT/UTC? I can't see where/if a parameter needs to be supplied to indicate that I'm wanting GMT/UTC? To make my question clear, I am looking for the current UTC/GMT time, i.e., the GMT/UTC UNIX timestamp for the time at which I run the script. Again, any advice will be appreciated. Thanks, Necuima.
  15. Hi Larry, I have been experimenting with PHP and dates and have the following query: If I code: $utc = strtotime(gmdate("Y-m-d H:i:s")); I get a Unix timestamp for UTC. But if I code: $utcU = gmdate("U"); I get a Unix timestamp for my local time zone. I am obviously mis-understanding gmdate with the "U" parameter. I thought that gmdate returns UTC and that the "U" parameter gives you a Unix timetstamp. Can you please help me understand this? Thanks, and cheers.
  16. Hi Larry, OK, I have modified the query and also put in a crude test to change the 'closes' heading message to 'closed' if the auction close date/time has passed. I'm not particularly happy with my 'crude' test but it seems to work OK. I need to do some more study to better understand the UTC date-time / local date-time approach (which makes good sense in this context) and how to code for it appropriately! Thanks again for a great book! Cheers from Oz.
  17. Hi Larry, After quite a bit of delay, I have been working through the book - great!! I have managed to get both the non-AJAX and AJAX auction sites working but have a question re closed bids (page 567). The index script only lists open auctions, so, without fiddling, how does one get the 'auction closed' message? Thanks, Necuima.
  18. Hi Larry, Have you had a chance to have a look at this yet? Cheers from Oz.
  19. Hi Larry, I thought that I'd post this in case anyone else wants to try JPEG encoders within the Flex 4 framework (I have been using FlashBuilder 4.6). In a nutshell, I found 3 encoders that I managed to get working: 1. The standard Actionscript 3 encoder 2. A vector-based version of the standard encoder by Thibault Imbert (http://www.bytearray.org/?p=775) (though apparently that site was hacked yesterday). 3. An Alchemy encoder from Jens Kraus (http://www.websector...-using-alchemy/) In my environment, the Alchemy encoder was the best by far, though not quite as good as PHP/GD in image quality, but not too far behind. Again, in my environment, the Alchemy encoder is also very fast, about 5 times as fast as the standard encoder, and 4 times as fast as Thibault's, for similar image sizes. For what it's worth! Cheers from Oz.
  20. Hi again, Larry, After more googling and quite a bit of trial and error, I have solved the two problems listed above. I made a new variable to contain the native path of the input directory and declared it to be bindable. Then in the HTTPService I changed the parameter to be that variable's name. That works A-OK now. In the result handler, i just type-casted the event.result to be a string, and now that works A-OK too. The learning continues... Cheers from Oz, Necuima.
  21. Hi Larry, I feel that I am being a bit of a pest with this one but it is driving me crazy! I have the simplest of calls to a small PHP routine which returns a simple string. Here's the PHP code: <?php if ($_POST['dirIn']) { $dirin = $_POST['dirIn']; echo "$dirin"; } else { echo "Unidentified request"; } ?> The (part of) flex code is: <fx:Declarations> <s:HTTPService id="service" url=" http://localhost/Resizer_Flex_PHP/service.php" useProxy=" false" method=" POST" resultFormat=" text" fault="service_faultHandler(event)" result="service_resultHandler(event)" > <s:request> <dirIn>{displayDirin.text} </dirIn> </s:request> </s:HTTPService> </fx:Declarations> and... protected function service_resultHandler(event:ResultEvent):void { processingStatus.text = event.result.value; } I am experiencing two problems - firstly the request dirIn bind won't bind the data which is in a form element (I checked, and a string with the value I want is there). How else can I pass the data to the PHP script? Secondly, the result handler seems to work OK - via debug I can see the value of "Unidentified request" in the event.result from the debugger variables with the status code being 200. But I get an error message when I try to put that into the form text area. These are probably obvious and simple problems but I can't figure out the corrections. Any assistance will be mightily appreciated. Thanks in anticipation, Necuima.
  22. Hi again, Larry, It works just fine if you tell FlashBuilder that it is a windowed application!!! Previously I had just copied the code and created the app as a windowed app without changing the opening and closing app tags in the mxml!! Sorry to have bothered you!! Cheers, Necuima has learnt something else today!
  23. Hi Larry, Mmmm - I am using the same URL as in the browser app - <s:HTTPService id="getEmployeesService" url="http://localhost/Flex_CH08/getEmployees.php" In the project's properties I have selected PHP in the Flex Server category and the web root and URL validate OK. I am a bit of a 'babe in the woods' with this so far! Again, any advice/suggestions will be muchly appreciated. Cheers, Necuima.
  24. Hi Larry, It is related, so let's close this thread - OK? I have been Googling like mad and there seems to be lots of evidence that a windowed Flex app can indeed communicate with a PHP script. As always, I am very appreciative of your advice. Cheers from Oz. P.S., I did look into the jpeg encoder options as you suggested earlier, but it is not clear to me how to actually use them, so for the time being at least, I am not pursuing that option, rather focusing on using the PHP / GD functionality that I already have but accessing it from a Flex/windowed app..
  25. Hi Larry, The form validators source code listed on pages 256 and 257 inludes 'enabled="{validatorsEnabled}"' for each element but the code that I have downloaded from the book's website does not include those parameters. Which is correct? Thanks, Necuima.
×
×
  • Create New...