Simple Image Resize in GD
5
Two very usefull functions to have around.
(note: dollarfy requires commify to work)
(note: dollarfy requires commify to work)
5
This small snippet will not allow _POST requests from a 'foreign' domain. It relies on the HTTP_REFERER variable.
5
This is the final version of my Javascript serializer targetted at PHP.
The point:
Notes:
Javascript sample of use:
var myObject = {
name:'value',
test:['Array','of','strings'],
bool:false,
timestamp: new Date(),
float: 3.1415926539,
number: 42,
func: function () {
alert('Member functions are always omitted from serialization');
}
}
alert(Object.toPHP(myObject));
Output:
Sample of subsequent unserialization in PHP (passed via POST as 'myobject')
$myObject=unserialize(stripslashes($_POST['myobject']));
var_dump($myObject);
Output:
The point:
Objects are most easily passed over the network as serialized strings. Between serialization and unserialization, serialization is by far the easier of the two. Since object passing can sometimes be a process-hungry thing, we want to do things as quickly as possible.
My solution is to always do the hard part in compiled code, while doing the easy part in script. That is, whichever way you're passing an Object, you want to pass it in a natively decoded format for the target.
Since I work mostly in PHP, this meant writing a module that would be able to generate a string that can be decoded with PHP's unserialize() function into a PHP Associative Array (or other applicable type).
Notes:
This lib REQUIRES the Prototype lib. You can hack prototype out of it, of course (by replacing the references to Object.extend() with explicit assignments), but I can't imagine why you'd want to bother; it's used mostly with Ajax.Request anyway.
Previous versions of this code would add the .toPHP() member to the Object prototype. After trying to enumerate things, I found that this is a REALLY bad thing to do, as toPHP springs up where it's not wanted in ALL objects. As a result, I've opted to go the Prototype route and apply it as a member of the Object object.
Please note that if you pass a serialized string to PHP via GET or POST, you'll need to stripslashes() before unserialization.
Javascript sample of use:
var myObject = {
name:'value',
test:['Array','of','strings'],
bool:false,
timestamp: new Date(),
float: 3.1415926539,
number: 42,
func: function () {
alert('Member functions are always omitted from serialization');
}
}
alert(Object.toPHP(myObject));
Output:
a:7:{s:4:"name";s:5:"value";s:4:"test";a:3:{i:0;s:5:"Array";i:1;s:2:"of";i:2;s:7:"strings";}s:4:"bool";b:0;s:9:"timestamp";i:1190897619824;s:5:"float";d:3.1415926539;s:6:"number";i:42;s:4:"func";null}
Sample of subsequent unserialization in PHP (passed via POST as 'myobject')
$myObject=unserialize(stripslashes($_POST['myobject']));
var_dump($myObject);
Output:
array(7) {
["name"]=>
string(5) "value"
["test"]=>
array(3) {
[0]=>
string(5) "Array"
[1]=>
string(2) "of"
[2]=>
string(7) "strings"
}
["bool"]=>
bool(false)
["timestamp"]=>
int(1192296601)
["float"]=>
float(3.1415926539)
["number"]=>
int(42)
["func"]=>
NULL
}
5
Random String Generato
5
Returns an array of folder/file names in the specified path.
5
The resize_image function allows you to resize a GIF, JPEG or PNG file to any dimension you wish and put an optional black border around the image. Here's an explanation of the arguements:
$image_path: The complete path to the image to be resized
$max_width: Maximum width of the resized image. Leave 0 if you want to specify only the height and have the width auto-scale.
$max_height: Maximum height of the resized image. Leave 0 if you want to specify only the width and have the height auto-scale.
$file_prefix: This will prepend a string onto the resized image filename. If you want to create a thumbnail image and keep the original, set $file_prefix = 'thumb'.
$dir: Allows you to save the resized image to a sub directory under the $image_path directory. If you want to save thumbnail images to images/thumbs, set $dir = 'thumbs'.
$border: boolean, 1 = border, 0 = no border
$mime: Image mime type. (image/jpeg, image/gif, image/png)
$image_path: The complete path to the image to be resized
$max_width: Maximum width of the resized image. Leave 0 if you want to specify only the height and have the width auto-scale.
$max_height: Maximum height of the resized image. Leave 0 if you want to specify only the width and have the height auto-scale.
$file_prefix: This will prepend a string onto the resized image filename. If you want to create a thumbnail image and keep the original, set $file_prefix = 'thumb'.
$dir: Allows you to save the resized image to a sub directory under the $image_path directory. If you want to save thumbnail images to images/thumbs, set $dir = 'thumbs'.
$border: boolean, 1 = border, 0 = no border
$mime: Image mime type. (image/jpeg, image/gif, image/png)
5
I made this script to delete any unneeded files from the server that weren't being used by the database. Of course you can expand this a lot more, but I cut it down a little to put it up here.
5
This is my MySQL database class that I use for all of my sites. Some included features are:
- Get execution time
- Error reporting (screen and email)
- SQL stats
- Get execution time
- Error reporting (screen and email)
- SQL stats
5
A very simple error class that can be pretty handy.
5
This is a simple function to check if an email is valid or not.









