Archive for category Programming

Tidbit: Discovering Xubuntu Distribution from PHP

๐Ÿ“… September 24, 2016
In PHP, we can use php_uname to grab information about the operating system that the server is running on.

echo php_uname(‘s’) will give the name of the OS, but this is a general name. When executed from a server running Xubuntu, it returns the string “Linux.” Is this Ubuntu, Kubuntu, Xubuntu, Linux Mint, or…what?

What if we want to get the specific Linux distribution? Is this possible from PHP without performing host OS system calls or executing Bash scripts? Yes.

Read the rest of this entry »

, ,

Leave a comment

php: Get Random Image

๐Ÿ“… February 4, 2016
randimgUsing a similar technique as the random text PHP code, here is a simple code snippet that chooses an image file at random and displays it in a browser.

This is useful for randomizing a banner image on a web page. Each time the browser refreshes, a different banner image (should) appear. While the same effect can be performed using JavaScript, what if JavaScript is disabled in the browser?

By moving the code to the server side, a random banner image (or any kind of image) will appear in order to add freshness to a page.

Read the rest of this entry »

, ,

Leave a comment

php: Get Random Text

๐Ÿ“… February 3, 2016
img-php-randquoteHere is a simple but fun PHP code snippet that displays one of several text strings chosen at random to add an element of surprise to a page.

First of all, a working PHP server is required in order to process PHP scripts. This could be a virtual machine using VirtualBox, for example, or something else on any platform. This short tutorial assumes that you have one set up and working.

 

 

Read the rest of this entry »

, ,

Leave a comment

Python 3 Quick Code: Get a Random Item from a List with an Even Chance of Being Chosen

๐Ÿ“… June 12, 2015
py001In Python 3, suppose we want to get a random item from a list that contains duplicates, but we do not want to favor the duplicates.

For example, if there are 3 duplicate items in a list of 10, then there is a 3x probability of obtaining that particular item compared to a single occurrence of that item in the list.

The idea is that by eliminating the duplicates, all items should have an equal chance of being chosen. Here is one strategy to achieve this using a set.

Read the rest of this entry »

,

Leave a comment

SweetFX – Levels

002SweetFX Levels sets new black and white points. This means every pixel whose value is below the black point will be converted into pure black, and every pixel whose value is above the white point will be converted into pure white.

Think of this as the equivalent of level adjustment in GIMP using the histogram. Used sparingly, Levels will trim off excess whiteness, and it will darken shadows and other dark areas that appear too “washed out” when they should be darker.

On the other hand, visual detail is lost when used excessively, and drastic scene changes can be produced. This is either good or bad depending upon the desired effect. In short, Levels is an effect best used for minor touchups to the resulting image.

Read the rest of this entry »

, ,

Leave a comment

SweetFX – Vignette

007SweetFX Vignette darkens the corners of the image to produce a peephole or faded corner effect. This can be used with other effects, such as Sepia and Monochrome, to produce a variation of the old-time photo effect.

Of course, Vignette settings can darken an area greater than the corners alone until the entire image is obscured, so use sparingly for the best results.

Read the rest of this entry »

, ,

Leave a comment

SweetFX – Lift Gamma Gain

006Regarding video and images, gamma is an exponential relationship between pixels and luminance. (Luminance is technically not the same as brightness.) The theory and mathematical formulae behind gamma is educational, so theย Gamma FAQย might provide a useful introduction for those interested in grasping the technical principles.

For an inaccurate, simplified description related to video games, we can think of gamma as brightening the bright areas and darkening the dark areas without losing too much detail. Where a simple brightness effect would brighten the entire scene uniformly, gamma handles this with more “intelligence.”

The SweetFX Lift Gamma Gain effect provides a fine amount of control over how gamma is applied to an image. While the SweetFX Tonemap effect provides a basic gamma control for basic gamma application, Lift Gamma Gain allows for more precise gamma control over the brightness of shadow areas, midrange areas, and bright areas, and it can do so at the color level with RGB values.

Read the rest of this entry »

, ,

Leave a comment