Page 1 of 1

Manipulate moon.bmp with PHP

Posted: Fri 13 May 2011 12:33 am
by beteljuice
Prompted by this question: https://cumulus.hosiene.co.uk/viewtopic.php?f=4&t=5097 the beteljuice decided to put his php head on ....
moon_N.png
moon_fill_border.png
moon_N_filled.png
moon_S_transparent.png
When it's next full moon I'll lift a N and S image from someones sites and try a tinted 'dark' mask.
Images produced are typically 0.86kB - 20 times less than the .bmp, much more web friendlier.

Edit: Now with 'dark' tinted moon option:
tinted_border.png
tinted_noborder.png

If there is any interest I'll neaten up and release the code ;)

Re: Manipulate moon.bmp with PHP

Posted: Sun 15 May 2011 12:27 pm
by gemini06720
beteljuice, I am not too sure what you are trying to do... :(

The 'AJAX-PHP Saratoga templates' are using a PHP script that produces not only the different moon phases (using 30 small 2K GIF images) but also the age of the moon as well as its illumination.

On my 'AJAX-PHP Saratoga templates', I have extended the use of that PHP script to give additional information, such as the moon phases for either the northern or the southern hemisphere (using 28 small 2K GIF images, with or without a transparent background) as well the age of the moon (in days, minutes and seconds), the illumination, the phase of the moon (in textual format), the next full moon and the next new moon.

Re: Manipulate moon.bmp with PHP

Posted: Sun 15 May 2011 3:26 pm
by beteljuice
Just a bit of a mental walk-in-the-park solving a posted question.

As you say there are many alternatives, most of which return a 'Moon Day' picture.

;) However; AFAIK Cumulus attempts to redraw the current Moon state every minute, although at this scale a visible difference would only be noticeable approx. every 5 hours. - for this and server processor friendliness I was thinking of a 2 or three hour cache.

So ... It doesn't clog the web, It isn't reliant on anyones elses server, and the user can customise the appearance to suit their demeanour.

I thought of it as a simple option for the out-of-the-box Cumulus templates (just a simple <img> url change).

.... anything else where you would like your darkness lightened :lol:

Re: Manipulate moon.bmp with PHP

Posted: Sun 15 May 2011 3:30 pm
by steve
beteljuice wrote: ;) However; AFAIK Cumulus attempts to redraw the current Moon state every minute,
Once an hour.

Re: Manipulate moon.bmp with PHP

Posted: Mon 23 May 2011 11:13 pm
by gemini06720
Hello beteljuice and sorry for the delay replying to the messages... :oops:
beteljuice wrote:AFAIK Cumulus attempts to redraw the current Moon state every minute...
On my sites, I use both a PHP and a JavaScript to produce and continually update the moon information (phase and image), but as you indicated, continuous (almost real time) updates are certainly not needed for most station (Web site) operators - although, as stated by Steve, a once-an-hour moon image update is more acceptable.

One thing I cannot remember is if Cumulus produces a different moon image for the northern and southern hemisphere! :|

One thing that would be nice would be a moon image produced with a transparent background... ;)

Re: Manipulate moon.bmp with PHP

Posted: Mon 23 May 2011 11:45 pm
by beteljuice
As indicated in the working examples above, (Cumulus) South moon is transposed (Mirror and flip), but to make life interesting is eccentric within the bounding 'square' - thus a mask for each option is required when creating 'dark' fill or 'tinted' image, total transparency option is actually the easiest to do !
One thing that would be nice would be a moon image produced with a transparent background... ;)
Haven't I covered that option ? (Green is 'page' background to prove transparency)

BTW - when I was doing weather reports elsewhere I too used an eclectic PHP / Javascript mix for an almanac to which I introduced the language concept of now, ago, next, tomorrow, etc.

example: (Pity the Moon is all 'today', output is much more interesting when moonday overlaps or restarts in a calendar day)

Sunset yesterday 21:08
Dusk ended: 21:53 - 17:35 hrs daylight

Dawn starts: 04:16
Sunrise today: 05:01
Sunset today: 21:09
Dusk ends: 21:55 - 17:39 hrs daylight

Moon rose at 00:31 and sets at 11:23.
Current altitude is 2° and azimuth 107° E by S.
The disk is now 58% illuminated (Waning).
Next new Moon on 1 June at 21:09
Next full Moon on 15 June at 20:12.

By the way the time is 00:38 and it's night (Dark)

Re: Manipulate moon.bmp with PHP

Posted: Tue 24 May 2011 10:53 am
by hills
I'm interested, I'll use the transparent south if you release it. :D

Re: Manipulate moon.bmp with PHP

Posted: Tue 24 May 2011 3:24 pm
by beteljuice
Any other interest ? (I need a kick-up-the-rear to clean it up :o )

All options will be available from the same code with minimal set-up (hopefully)

Options should be:
  1. Illuminated moon ONLY (full transparency)
    * User defined 'dark' moon colour with or without black square background (If black without background square, user define 'almost' black ;) )
    Tinted 'dark' moon with or without black square background
(* Is that what you meant gemini ?)

User setable vars would be:
  1. Location of moon.bmp
    Image type required
    'Dark' moon colour (If option required)
    North or South (NOT essential if full transparency chosen)
    'Time-to-die' of stored image (default 2hrs ?)
Thoughts please ........

Re: Manipulate moon.bmp with PHP

Posted: Tue 24 May 2011 10:08 pm
by gemini06720
beteljuice wrote:Any other interest ? (I need a kick-up-the-rear to clean it up :o )
OK, if that is what you need ... this is my Internet 'kick-in-the-posterior' action/reaction... :D

Would kicking the computer onto which my browser is running be OK... :mrgreen:
beteljuice wrote:(* Is that what you meant gemini ?)
Call me Ray or call me Raymond or call me Mr. R ... but, please, do not call me gemini or gemini06720... :twisted:

Indeed, what I meant was that for most users, a moon image with transparent background (ie: clear, no colour whatsoever) would be the best design - this way the moon image (with a transparent background) could be added to any Web pages without interfering with the background colours/images of that page (that is what I have been doing with the moon script I have been using on my pages).

beteljuice what would the format of the script be, PHP or JavaScript?

OK, the minimum needed settings requirements for the script should be:
  • - the latitude;
    - the longitude;
    - wether the script is operated in the northern or southern hemisphere 1;
    - the relative location (URL/directory) where the 'starting' moon image is located 2;
    - the format of the generated moon image - one of the general accepted image formats of GIF, JPEG and PNG should be used;
    - the generated size of the image;
    - I guess, the colour of the tint used to cover the moon image should be part of the settings;
    - the amount of time, in hours, between image changes.
    - and, obviously, some textual information such as the moon phase, the moon phase angle, the moon elevation, the percentage of illumination, the rising and setting times of the moon, possibly the next new and next full moons, etc.
Note 1: I understand that this information can/could be extracted (calculated) from the latitude, but I do not see the purpose of adding additional code just to do that extraction; I do not understand your statement that the choice of the hemisphere is 'not essential if full transparency chosen' - it is my understanding that the moon position (angle) will always be different depending if it is viewed from the northern or southern hemisphere.

Note 2: From what I have read, it is now my understanding that you will be using the (small at 64*64 pixels) Cumulus-produced 'moon.bmp' image rather than generating your own moon image from a larger (of better definition and of better quality) image such as this northern hemisphere full moon image: ;) ;)

Re: Manipulate moon.bmp with PHP

Posted: Tue 24 May 2011 10:23 pm
by steve
gemini06720 wrote:Note 2: From what I have read, it is now my understanding that you will be using the (small at 64*64 pixels) Cumulus-produced 'moon.bmp' image rather than generating your own moon image from a larger (of better definition and of better quality) image
I was going to suggest that if someone was writing the PHP to manipulate the bitmap produced by Cumulus, would it not be better to expend the effort in writing the code to produce an image from scratch, independent of Cumulus ;)

Re: Manipulate moon.bmp with PHP

Posted: Tue 24 May 2011 10:54 pm
by gemini06720
steve wrote:I was going to suggest that if someone was writing the PHP to manipulate the bitmap produced by Cumulus, would it not be better to expend the effort in writing the code to produce an image from scratch, independent of Cumulus ;)
Great minds think alike... :D Indeed, just my thoughts... :mrgreen:

I really really like the resolution and the subdued colours of the northern hemisphere moon image I posted in a previous message - unfortunately, I could not find such a high quality image for the southern hemisphers... :(

Re: Manipulate moon.bmp with PHP

Posted: Tue 24 May 2011 11:43 pm
by beteljuice
Guys .....
The topic title says "Manipulate moon.bmp with PHP"

So ..
It's a PHP based script.
It's dealing with an already 'calculated' and uploaded Cumulus image.

Yes ..
You could incorporate a duplication of moon almanac code just to overlay textual information on the image (Always looks sharper and better on the 'page' rather than the image I think), and in that case Lat / Long, and for rise/set the Local difference to GMT (including any DST etc.) - then the possible argument of if the calc is realtime or last site observed time, and .... let's not go there :?
(There is already a famous site where you can obtain current moon at what ever size you declare with or without blue 'dark' tint ;) )

Tinted moon colour is not user defined (It is a pre-tinted full moon image with 'current' moon overlayed on top) - It should be possible, but the beteljuice has been getting lost with PHP layered ideas of transparency, not least of which it should be applied to a 'layer' after it has been copied to the canvass :shock:

With total transparency, N/S doesn't need to be defined because it simply makes the (correctly orientated) Cumulus moon black colour transparent, however; with user defined 'dark' option or tinted option moon, it is necessary to apply the correct (eccentric) mask.

For simplicity (and size) I elected to 'limit' output type to .png

Thought on total transparency, On a new moon there would be nothing to see :(

I have half toyed with the ideas of either small overlayed graphics or even animation to depict rising or falling / waxing or waning but this again goes beyond the original intent to simply 'modify' the image and naturally increases the code and additionally requires either posting or look-up data.

Here is the result of transparent bounding box and user defined off-black 'dark' fill (r1, b0, g0)
off-black.png
Edit:
I really really like the resolution and the subdued colours of the northern hemisphere moon image I posted in a previous message - unfortunately, I could not find such a high quality image for the southern hemisphers... :(
Just stand on your head (ie. flip and mirror), although if one was pedantic, you should really calculate the apparent 'tilt' to the observed location - ever thought how it looks at the equator ? - waxes / wanes 'South' / 'North' !

Re: Manipulate moon.bmp with PHP

Posted: Wed 25 May 2011 7:57 pm
by mcrossley
beteljuice wrote:Just stand on your head (ie. flip and mirror), although if one was pedantic, you should really calculate the apparent 'tilt' to the observed location - ever thought how it looks at the equator ? - waxes / wanes 'South' / 'North' !
And the tilt away from the equator varies with time of day - being approximately vertical when it crosses the meridian. At the equator what is the tilt when the Moon crosses the meridian? It is (approximately) overhead so the angle of tilt is meaningless!