Skip to content

Instantly share code, notes, and snippets.

@xkungfu
xkungfu / test.retry.php
Created September 3, 2017 22:20 — forked from mudge/test.retry.php
A retry function for PHP.
<?php
require_once dirname(__FILE__) . '/../lib/simpletest/autorun.php';
function retry($f, $delay = 10, $retries = 3)
{
try {
return $f();
} catch (Exception $e) {
if ($retries > 0) {
sleep($delay);
@xkungfu
xkungfu / imagemagick_php_thumbnail.php
Created May 11, 2017 05:26 — forked from gourneau/imagemagick_php_thumbnail.php
Create a thumbnail or resize an image with Imagemagick in PHP
<?php
//Dynamically resize images
function thumb_create($file, $width , $height ) {
try
{
/*** the image file ***/
$image = $file;
/*** a new imagick object ***/
$args = array(
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>'
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' =>
'<p class="comment-form-author">' .
'<label for="author">' . __( 'Name', 'domainreference' ) . '</label> ' .
( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' /></p>',
@xkungfu
xkungfu / gist:dd1f39261113c8d9dbae3ed5cd4948d3
Created April 22, 2017 12:05 — forked from ericpedia/gist:3583170
PHP crop blank space around image
<?php
/** Loop through all the files in a folder **/
function loop_through_folder_by_extension($path, $extension) {
$processedFiles = array();
$errors = array();
foreach ( "{$path}/*.{$extension}" as $filename ) {
@xkungfu
xkungfu / watermark.imagick.php
Created April 6, 2017 04:05 — forked from rodneyrehm/watermark.imagick.php
Watermark with IMagick
<?php
// Watermark with Imagick
// load images
$image = new Imagick("image.jpg");
$watermark = new Imagick("watermark.png");
// translate named gravity to pixel position
$position = gravity2coordinates($image, $watermark, 'lowerRight', 5, 5);
// compose watermark onto image