Skip to main content

RGBA Generator

Nov 18, 2022AustinLeath
Loading...

More PHP Posts

Generate 64K edges

Nov 18, 2022AustinLeath

0 likes • 2 views

<?php
header('Content-Type:text/html');
$jsonData = json_decode(file_get_contents("names.json"));
$namesArray = array();
foreach($jsonData as $data) {
$namesArray[] = $data;
}
for($i = 0; $i < 64000; $i++) {
echo 'D.add_edge("'. $namesArray[array_rand($namesArray)] . '", "' . $namesArray[array_rand($namesArray)]. '")';
echo "<br>";
}
?>

Get File Extension

Nov 19, 2022CodeCatch

0 likes • 0 views

<?php
function getFileExtension($file) {
return end(explode(".", $file));
}
?>

Make Random Number

Nov 19, 2022CodeCatch

0 likes • 0 views

<?php
function getRandomId($min = NULL, $max = NULL) {
if (is_numeric($min) && is_numeric($max)) {
return mt_rand($min, $max);
}
else {
return mt_rand();
}
}
?>

preg_match() username sanitization

Nov 18, 2022AustinLeath

0 likes • 0 views

<?php
$username = "Austin Leath -_#";
$username_err = "no error";
if(preg_match('/[^a-z_\-0-9]/i', $string)) {
$username_err = "Username can only contain alphanumeric characters, dashes, and underscores.";
}
echo $username_err
?>

Get Image Information

Nov 19, 2022CodeCatch

0 likes • 0 views

<?php
/*
* @param string $file Filepath
* @param string $query Needed information (0 = width, 1 = height, 2 = mime-type)
* @return string Fileinfo
*/
function getImageinfo($file, $query) {
if (!realpath($file)) {
$file = $_SERVER["DOCUMENT_ROOT"] . $file;
}
$image = getimagesize($file);
return $image[$query];
}
?>

Crop an image

Nov 19, 2022CodeCatch

0 likes • 0 views

<?php
$im = imagecreatefrompng('example.png');
$size = min(imagesx($im), imagesy($im));
$im2 = imagecrop($im, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]);
if ($im2 !== FALSE) {
imagepng($im2, 'example-cropped.png');
imagedestroy($im2);
}
imagedestroy($im);
?>