Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function DeleteThumbAndImage($name) {
- unlink('Imgs/'.preg_replace('/(.*)\.[^.]*/','\\1_thumb.jpg',$name));
- unlink('Imgs/'.$name);
- }
- function CreateThumbAndCopyImage($fpath,$name) {
- $tmp = 'Imgs/'.$name;
- if (is_uploaded_file($fpath)) { if (@move_uploaded_file($fpath,$tmp) == false) die('image_process_error_1'); }
- else if (rename($fpath,$tmp) == false) die('image_process_error_1');
- $fpath = $tmp;
- $nameonly = preg_replace('/(.*)\.[^\.]*/','\\1',$name);
- $nameextonly = substr($name,strlen($nameonly));
- switch (strtolower($nameextonly)) {
- case '.jpg':
- case '.jpeg':
- $sourceimg = imagecreatefromjpeg($fpath);
- break;
- case '.png':
- $sourceimg = imagecreatefrompng($fpath);
- break;
- case '.gif':
- $sourceimg = imagecreatefromgif($fpath);
- break;
- }
- if (!$sourceimg) die('image_process_error_2');
- $sourcewidth = imagesx($sourceimg);
- $sourceheight = imagesy($sourceimg);
- $targetwidthlimit = 85;
- $targetheightlimit = 75;
- if (($targetwidthlimit / $sourcewidth) < ($targetheightlimit / $sourceheight)) $sizingpercent = $targetwidthlimit/$sourcewidth;
- else $sizingpercent = $targetheightlimit/$sourceheight;
- $targetwidth = round($sourcewidth*$sizingpercent);
- $targetheight = round($sourceheight*$sizingpercent);
- $destimg = imagecreatetruecolor($targetwidth,$targetheight);
- if (!$destimg) {
- @imagedestroy($sourceimg);
- die('image_process_error_3');
- }
- imagecopyresampled($destimg,$sourceimg,0,0,0,0,$targetwidth,$targetheight,$sourcewidth,$sourceheight);
- @mkdir('Imgs');
- if (imagejpeg($destimg,'Imgs/'.$nameonly.'_thumb.jpg') == false) {
- @imagedestroy($destimg);
- @imagedestroy($sourceimg);
- die('image_process_error_4');
- }
- @imagedestroy($destimg);
- @imagedestroy($sourceimg);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement