Created
January 5, 2014 03:35
-
-
Save freekrai/8263965 to your computer and use it in GitHub Desktop.
functions.php for live blogging with twilio and simperium demo @ http://rogerstringer.com/2014/01/05/live-blogging-twilio-simperium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function slugify( $string ){ | |
| $string = strtolower( trim($string) ); | |
| $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string); | |
| return $slug; | |
| } | |
| function cropResize($img,$out='',$dSize=170){ | |
| $x = @getimagesize($img); | |
| $sw = $x[0]; | |
| $sh = $x[1]; | |
| $yOff = 0; | |
| $xOff = 0; | |
| if($sw < $sh) { | |
| $scale = $dSize / $sw; | |
| $yOff = $sh/2 - $dSize/$scale/2; | |
| } else { | |
| $scale = $dSize / $sh; | |
| $xOff = $sw/2 - $dSize/$scale/2; | |
| } | |
| $im = @ImageCreateFromJPEG ($img) or // Read JPEG Image | |
| $im = @ImageCreateFromPNG ($img) or // or PNG Image | |
| $im = @ImageCreateFromGIF ($img) or // or GIF Image | |
| $im = false; // If image is not JPEG, PNG, or GIF | |
| if (!$im) { | |
| readfile ($img); | |
| } else { | |
| $thumb = @ImageCreateTrueColor ($dSize,$dSize); | |
| imagecopyresampled($thumb, $im, | |
| 0, 0, | |
| $xOff,$yOff, | |
| $dSize, $dSize, | |
| $dSize / $scale ,$dSize / $scale); | |
| } | |
| if( $out == '' ){ | |
| header('content-type:image/jpeg'); | |
| imagejpeg($thumb); | |
| }else{ | |
| imagejpeg($thumb, $out); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment