| @@ -9,7 +9,7 @@ discard block | ||
| 9 | 9 | */ | 
| 10 | 10 | namespace Bulletproof; | 
| 11 | 11 | |
| 12 | - function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight){
 | |
| 12 | + function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight) {
 | |
| 13 | 13 | |
| 14 | 14 |      switch ($mimeType) {
 | 
| 15 | 15 | case "jpg": | 
| @@ -37,7 +37,7 @@ discard block | ||
| 37 | 37 | // Can't crop to a bigger size, ex: | 
| 38 | 38 | // an image with 100X100 can not be cropped to 200X200. Image can only be cropped to smaller size. | 
| 39 | 39 |      if ($widthTrim < 0 && $heightTrim < 0) {
 | 
| 40 | - return ; | |
| 40 | + return; | |
| 41 | 41 | } | 
| 42 | 42 | |
| 43 | 43 | $temp = imagecreatetruecolor($newWidth, $newHeight); | 
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | */ | 
| 10 | 10 | namespace Bulletproof; | 
| 11 | 11 | |
| 12 | - function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight){
 | |
| 12 | + function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight) { | |
| 13 | 13 | |
| 14 | 14 |      switch ($mimeType) {
 | 
| 15 | 15 | case "jpg": | 
| @@ -11,57 +11,57 @@ | ||
| 11 | 11 | |
| 12 | 12 |   function crop($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight){
 | 
| 13 | 13 | |
| 14 | -    switch ($mimeType) {
 | |
| 15 | - case "jpg": | |
| 16 | - case "jpeg": | |
| 17 | - $imageCreate = imagecreatefromjpeg($image); | |
| 18 | - break; | |
| 14 | +	switch ($mimeType) {
 | |
| 15 | + case "jpg": | |
| 16 | + case "jpeg": | |
| 17 | + $imageCreate = imagecreatefromjpeg($image); | |
| 18 | + break; | |
| 19 | 19 | |
| 20 | - case "png": | |
| 21 | - $imageCreate = imagecreatefrompng($image); | |
| 22 | - break; | |
| 20 | + case "png": | |
| 21 | + $imageCreate = imagecreatefrompng($image); | |
| 22 | + break; | |
| 23 | 23 | |
| 24 | - case "gif": | |
| 25 | - $imageCreate = imagecreatefromgif($image); | |
| 26 | - break; | |
| 24 | + case "gif": | |
| 25 | + $imageCreate = imagecreatefromgif($image); | |
| 26 | + break; | |
| 27 | 27 | |
| 28 | - default: | |
| 29 | -            throw new \Exception(" Only gif, jpg, jpeg and png files can be cropped ");
 | |
| 30 | - break; | |
| 31 | - } | |
| 28 | + default: | |
| 29 | +			throw new \Exception(" Only gif, jpg, jpeg and png files can be cropped ");
 | |
| 30 | + break; | |
| 31 | + } | |
| 32 | 32 | |
| 33 | - // The image offsets/coordination to crop the image. | |
| 34 | - $widthTrim = ceil(($imgWidth - $newWidth) / 2); | |
| 35 | - $heightTrim = ceil(($imgHeight - $newHeight) / 2); | |
| 33 | + // The image offsets/coordination to crop the image. | |
| 34 | + $widthTrim = ceil(($imgWidth - $newWidth) / 2); | |
| 35 | + $heightTrim = ceil(($imgHeight - $newHeight) / 2); | |
| 36 | 36 | |
| 37 | - // Can't crop to a bigger size, ex: | |
| 38 | - // an image with 100X100 can not be cropped to 200X200. Image can only be cropped to smaller size. | |
| 39 | -    if ($widthTrim < 0 && $heightTrim < 0) {
 | |
| 40 | - return ; | |
| 41 | - } | |
| 37 | + // Can't crop to a bigger size, ex: | |
| 38 | + // an image with 100X100 can not be cropped to 200X200. Image can only be cropped to smaller size. | |
| 39 | +	if ($widthTrim < 0 && $heightTrim < 0) {
 | |
| 40 | + return ; | |
| 41 | + } | |
| 42 | 42 | |
| 43 | - $temp = imagecreatetruecolor($newWidth, $newHeight); | |
| 44 | - imageAlphaBlending($temp, false); | |
| 45 | - imageSaveAlpha($temp, true); | |
| 46 | - imagecopyresampled( | |
| 47 | - $temp, | |
| 48 | - $imageCreate, | |
| 49 | - 0, | |
| 50 | - 0, | |
| 51 | - $widthTrim, | |
| 52 | - $heightTrim, | |
| 53 | - $newWidth, | |
| 54 | - $newHeight, | |
| 55 | - $newWidth, | |
| 56 | - $newHeight | |
| 57 | - ); | |
| 43 | + $temp = imagecreatetruecolor($newWidth, $newHeight); | |
| 44 | + imageAlphaBlending($temp, false); | |
| 45 | + imageSaveAlpha($temp, true); | |
| 46 | + imagecopyresampled( | |
| 47 | + $temp, | |
| 48 | + $imageCreate, | |
| 49 | + 0, | |
| 50 | + 0, | |
| 51 | + $widthTrim, | |
| 52 | + $heightTrim, | |
| 53 | + $newWidth, | |
| 54 | + $newHeight, | |
| 55 | + $newWidth, | |
| 56 | + $newHeight | |
| 57 | + ); | |
| 58 | 58 | |
| 59 | 59 | |
| 60 | -    if (!$temp) {
 | |
| 61 | -        throw new \Exception("Failed to crop image. Please pass the right parameters");
 | |
| 62 | -    } else {
 | |
| 63 | - imagejpeg($temp, $image); | |
| 64 | - } | |
| 60 | +	if (!$temp) {
 | |
| 61 | +		throw new \Exception("Failed to crop image. Please pass the right parameters");
 | |
| 62 | +	} else {
 | |
| 63 | + imagejpeg($temp, $image); | |
| 64 | + } | |
| 65 | 65 | |
| 66 | 66 | } | 
| 67 | 67 | |
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | */ | 
| 10 | 10 | namespace Bulletproof; | 
| 11 | 11 | |
| 12 | -function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE){           
 | |
| 12 | +function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE) {           
 | |
| 13 | 13 | |
| 14 | 14 | // First, calculate the height. | 
| 15 | 15 | $height = intval($newWidth / $imgWidth * $imgHeight); | 
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | */ | 
| 10 | 10 | namespace Bulletproof; | 
| 11 | 11 | |
| 12 | -function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE){           
 | |
| 12 | +function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE) { | |
| 13 | 13 | |
| 14 | 14 | // First, calculate the height. | 
| 15 | 15 | $height = intval($newWidth / $imgWidth * $imgHeight); | 
| @@ -11,79 +11,79 @@ | ||
| 11 | 11 | |
| 12 | 12 |  function resize($image, $mimeType, $imgWidth, $imgHeight, $newWidth, $newHeight, $ratio = FALSE, $upsize = TRUE){           
 | 
| 13 | 13 | |
| 14 | - // First, calculate the height. | |
| 15 | - $height = intval($newWidth / $imgWidth * $imgHeight); | |
| 14 | + // First, calculate the height. | |
| 15 | + $height = intval($newWidth / $imgWidth * $imgHeight); | |
| 16 | 16 | |
| 17 | - // If the height is too large, set it to the maximum height and calculate the width. | |
| 18 | -    if ($height > $newHeight) {
 | |
| 17 | + // If the height is too large, set it to the maximum height and calculate the width. | |
| 18 | +	if ($height > $newHeight) {
 | |
| 19 | 19 | |
| 20 | - $height = $newHeight; | |
| 21 | - $newWidth = intval($height / $imgHeight * $imgWidth); | |
| 22 | - } | |
| 20 | + $height = $newHeight; | |
| 21 | + $newWidth = intval($height / $imgHeight * $imgWidth); | |
| 22 | + } | |
| 23 | 23 | |
| 24 | - // If we don't allow upsizing check if the new width or height are too big. | |
| 25 | -    if (!$upsize) {
 | |
| 26 | - // If the given width is larger then the image height, then resize it. | |
| 27 | -        if ($newWidth > $imgWidth) {
 | |
| 28 | - $newWidth = $imgWidth; | |
| 29 | - $height = intval($newWidth / $imgWidth * $imgHeight); | |
| 30 | - } | |
| 24 | + // If we don't allow upsizing check if the new width or height are too big. | |
| 25 | +	if (!$upsize) {
 | |
| 26 | + // If the given width is larger then the image height, then resize it. | |
| 27 | +		if ($newWidth > $imgWidth) {
 | |
| 28 | + $newWidth = $imgWidth; | |
| 29 | + $height = intval($newWidth / $imgWidth * $imgHeight); | |
| 30 | + } | |
| 31 | 31 | |
| 32 | - // If the given height is larger then the image height, then resize it. | |
| 33 | -        if ($height > $imgHeight) {
 | |
| 34 | - $height = $imgHeight; | |
| 35 | - $newWidth = intval($height / $imgHeight * $imgWidth); | |
| 36 | - } | |
| 37 | - } | |
| 32 | + // If the given height is larger then the image height, then resize it. | |
| 33 | +		if ($height > $imgHeight) {
 | |
| 34 | + $height = $imgHeight; | |
| 35 | + $newWidth = intval($height / $imgHeight * $imgWidth); | |
| 36 | + } | |
| 37 | + } | |
| 38 | 38 | |
| 39 | - if ($ratio == true) | |
| 40 | -    {
 | |
| 41 | - $source_aspect_ratio = $imgWidth / $imgHeight; | |
| 42 | - $thumbnail_aspect_ratio = $newWidth / $newHeight; | |
| 43 | -        if ($imgWidth <= $newWidth && $imgHeight <= $newHeight) {
 | |
| 44 | - $newWidth = $imgWidth; | |
| 45 | - $newHeight = $imgHeight; | |
| 46 | -        } elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
 | |
| 47 | - $newWidth = (int) ($newHeight * $source_aspect_ratio); | |
| 48 | - $newHeight = $newHeight; | |
| 49 | -        } else {
 | |
| 50 | - $newWidth = $newWidth; | |
| 51 | - $newHeight = (int) ($newWidth / $source_aspect_ratio); | |
| 52 | - } | |
| 53 | - } | |
| 39 | + if ($ratio == true) | |
| 40 | +	{
 | |
| 41 | + $source_aspect_ratio = $imgWidth / $imgHeight; | |
| 42 | + $thumbnail_aspect_ratio = $newWidth / $newHeight; | |
| 43 | +		if ($imgWidth <= $newWidth && $imgHeight <= $newHeight) {
 | |
| 44 | + $newWidth = $imgWidth; | |
| 45 | + $newHeight = $imgHeight; | |
| 46 | +		} elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
 | |
| 47 | + $newWidth = (int) ($newHeight * $source_aspect_ratio); | |
| 48 | + $newHeight = $newHeight; | |
| 49 | +		} else {
 | |
| 50 | + $newWidth = $newWidth; | |
| 51 | + $newHeight = (int) ($newWidth / $source_aspect_ratio); | |
| 52 | + } | |
| 53 | + } | |
| 54 | 54 | |
| 55 | - $imgString = file_get_contents($image); | |
| 55 | + $imgString = file_get_contents($image); | |
| 56 | 56 | |
| 57 | - $imageFromString = imagecreatefromstring($imgString); | |
| 58 | - $tmp = imagecreatetruecolor($newWidth, $newHeight); | |
| 59 | - imagecopyresampled( | |
| 60 | - $tmp, | |
| 61 | - $imageFromString, | |
| 62 | - 0, | |
| 63 | - 0, | |
| 64 | - 0, | |
| 65 | - 0, | |
| 66 | - $newWidth, | |
| 67 | - $newHeight, | |
| 68 | - $imgWidth, | |
| 69 | - $imgHeight | |
| 70 | - ); | |
| 57 | + $imageFromString = imagecreatefromstring($imgString); | |
| 58 | + $tmp = imagecreatetruecolor($newWidth, $newHeight); | |
| 59 | + imagecopyresampled( | |
| 60 | + $tmp, | |
| 61 | + $imageFromString, | |
| 62 | + 0, | |
| 63 | + 0, | |
| 64 | + 0, | |
| 65 | + 0, | |
| 66 | + $newWidth, | |
| 67 | + $newHeight, | |
| 68 | + $imgWidth, | |
| 69 | + $imgHeight | |
| 70 | + ); | |
| 71 | 71 | |
| 72 | -    switch ($mimeType) {
 | |
| 73 | - case "jpeg": | |
| 74 | - case "jpg": | |
| 75 | - imagejpeg($tmp, $image, 90); | |
| 76 | - break; | |
| 77 | - case "png": | |
| 78 | - imagepng($tmp, $image, 0); | |
| 79 | - break; | |
| 80 | - case "gif": | |
| 81 | - imagegif($tmp, $image); | |
| 82 | - break; | |
| 83 | - default: | |
| 84 | -            throw new \Exception(" Only jpg, jpeg, png and gif files can be resized ");
 | |
| 85 | - break; | |
| 86 | - } | |
| 72 | +	switch ($mimeType) {
 | |
| 73 | + case "jpeg": | |
| 74 | + case "jpg": | |
| 75 | + imagejpeg($tmp, $image, 90); | |
| 76 | + break; | |
| 77 | + case "png": | |
| 78 | + imagepng($tmp, $image, 0); | |
| 79 | + break; | |
| 80 | + case "gif": | |
| 81 | + imagegif($tmp, $image); | |
| 82 | + break; | |
| 83 | + default: | |
| 84 | +			throw new \Exception(" Only jpg, jpeg, png and gif files can be resized ");
 | |
| 85 | + break; | |
| 86 | + } | |
| 87 | 87 | |
| 88 | 88 | } | 
| 89 | 89 | |
| @@ -11,86 +11,86 @@ | ||
| 11 | 11 | |
| 12 | 12 |   function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center"){
 | 
| 13 | 13 | |
| 14 | - // Calculate the watermark position | |
| 15 | -    switch ($position) {
 | |
| 16 | - case "center": | |
| 17 | - $marginBottom = round($imgHeight / 2); | |
| 18 | - $marginRight = round($imgWidth / 2) - round($watermarkWidth / 2); | |
| 19 | - break; | |
| 20 | - | |
| 21 | - case "top-left": | |
| 22 | - $marginBottom = round($imgHeight - $watermarkHeight); | |
| 23 | - $marginRight = round($imgWidth - $watermarkWidth); | |
| 24 | - break; | |
| 25 | - | |
| 26 | - case "bottom-left": | |
| 27 | - $marginBottom = 5; | |
| 28 | - $marginRight = round($imgWidth - $watermarkWidth); | |
| 29 | - break; | |
| 30 | - | |
| 31 | - case "top-right": | |
| 32 | - $marginBottom = round($imgHeight - $watermarkHeight); | |
| 33 | - $marginRight = 5; | |
| 34 | - break; | |
| 35 | - | |
| 36 | - default: | |
| 37 | - $marginBottom = 2; | |
| 38 | - $marginRight = 2; | |
| 39 | - break; | |
| 40 | - } | |
| 41 | - | |
| 42 | - | |
| 43 | - $watermark = imagecreatefrompng($watermark); | |
| 44 | - | |
| 45 | -    switch ($mimeType) {
 | |
| 46 | - case "jpeg": | |
| 47 | - case "jpg": | |
| 48 | - $createImage = imagecreatefromjpeg($image); | |
| 49 | - break; | |
| 50 | - | |
| 51 | - case "png": | |
| 52 | - $createImage = imagecreatefrompng($image); | |
| 53 | - break; | |
| 54 | - | |
| 55 | - case "gif": | |
| 56 | - $createImage = imagecreatefromgif($image); | |
| 57 | - break; | |
| 58 | - | |
| 59 | - default: | |
| 60 | - $createImage = imagecreatefromjpeg($image); | |
| 61 | - break; | |
| 62 | - } | |
| 63 | - | |
| 64 | - $sx = imagesx($watermark); | |
| 65 | - $sy = imagesy($watermark); | |
| 66 | - imagecopy( | |
| 67 | - $createImage, | |
| 68 | - $watermark, | |
| 69 | - imagesx($createImage) - $sx - $marginRight, | |
| 70 | - imagesy($createImage) - $sy - $marginBottom, | |
| 71 | - 0, | |
| 72 | - 0, | |
| 73 | - imagesx($watermark), | |
| 74 | - imagesy($watermark) | |
| 75 | - ); | |
| 76 | - | |
| 77 | - | |
| 78 | -    switch ($mimeType) {
 | |
| 79 | - case "jpeg": | |
| 80 | - case "jpg": | |
| 81 | - imagejpeg($createImage, $image); | |
| 82 | - break; | |
| 83 | - | |
| 84 | - case "png": | |
| 85 | - imagepng($createImage, $image); | |
| 86 | - break; | |
| 87 | - | |
| 88 | - case "gif": | |
| 89 | - imagegif($createImage, $image); | |
| 90 | - break; | |
| 91 | - | |
| 92 | - default: | |
| 93 | -            throw new \Exception("A watermark can only be applied to: jpeg, jpg, gif, png images ");
 | |
| 94 | - break; | |
| 95 | - } | |
| 14 | + // Calculate the watermark position | |
| 15 | +	switch ($position) {
 | |
| 16 | + case "center": | |
| 17 | + $marginBottom = round($imgHeight / 2); | |
| 18 | + $marginRight = round($imgWidth / 2) - round($watermarkWidth / 2); | |
| 19 | + break; | |
| 20 | + | |
| 21 | + case "top-left": | |
| 22 | + $marginBottom = round($imgHeight - $watermarkHeight); | |
| 23 | + $marginRight = round($imgWidth - $watermarkWidth); | |
| 24 | + break; | |
| 25 | + | |
| 26 | + case "bottom-left": | |
| 27 | + $marginBottom = 5; | |
| 28 | + $marginRight = round($imgWidth - $watermarkWidth); | |
| 29 | + break; | |
| 30 | + | |
| 31 | + case "top-right": | |
| 32 | + $marginBottom = round($imgHeight - $watermarkHeight); | |
| 33 | + $marginRight = 5; | |
| 34 | + break; | |
| 35 | + | |
| 36 | + default: | |
| 37 | + $marginBottom = 2; | |
| 38 | + $marginRight = 2; | |
| 39 | + break; | |
| 40 | + } | |
| 41 | + | |
| 42 | + | |
| 43 | + $watermark = imagecreatefrompng($watermark); | |
| 44 | + | |
| 45 | +	switch ($mimeType) {
 | |
| 46 | + case "jpeg": | |
| 47 | + case "jpg": | |
| 48 | + $createImage = imagecreatefromjpeg($image); | |
| 49 | + break; | |
| 50 | + | |
| 51 | + case "png": | |
| 52 | + $createImage = imagecreatefrompng($image); | |
| 53 | + break; | |
| 54 | + | |
| 55 | + case "gif": | |
| 56 | + $createImage = imagecreatefromgif($image); | |
| 57 | + break; | |
| 58 | + | |
| 59 | + default: | |
| 60 | + $createImage = imagecreatefromjpeg($image); | |
| 61 | + break; | |
| 62 | + } | |
| 63 | + | |
| 64 | + $sx = imagesx($watermark); | |
| 65 | + $sy = imagesy($watermark); | |
| 66 | + imagecopy( | |
| 67 | + $createImage, | |
| 68 | + $watermark, | |
| 69 | + imagesx($createImage) - $sx - $marginRight, | |
| 70 | + imagesy($createImage) - $sy - $marginBottom, | |
| 71 | + 0, | |
| 72 | + 0, | |
| 73 | + imagesx($watermark), | |
| 74 | + imagesy($watermark) | |
| 75 | + ); | |
| 76 | + | |
| 77 | + | |
| 78 | +	switch ($mimeType) {
 | |
| 79 | + case "jpeg": | |
| 80 | + case "jpg": | |
| 81 | + imagejpeg($createImage, $image); | |
| 82 | + break; | |
| 83 | + | |
| 84 | + case "png": | |
| 85 | + imagepng($createImage, $image); | |
| 86 | + break; | |
| 87 | + | |
| 88 | + case "gif": | |
| 89 | + imagegif($createImage, $image); | |
| 90 | + break; | |
| 91 | + | |
| 92 | + default: | |
| 93 | +			throw new \Exception("A watermark can only be applied to: jpeg, jpg, gif, png images ");
 | |
| 94 | + break; | |
| 95 | + } | |
| 96 | 96 | } | 
| 97 | 97 | \ No newline at end of file | 
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | */ | 
| 10 | 10 | namespace Bulletproof; | 
| 11 | 11 | |
| 12 | - function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center"){
 | |
| 12 | + function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center") {
 | |
| 13 | 13 | |
| 14 | 14 | // Calculate the watermark position | 
| 15 | 15 |      switch ($position) {
 | 
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | */ | 
| 10 | 10 | namespace Bulletproof; | 
| 11 | 11 | |
| 12 | - function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center"){
 | |
| 12 | + function watermark($image, $mimeType, $imgWidth, $imgHeight, $watermark, $watermarkHeight, $watermarkWidth, $position = "center") { | |
| 13 | 13 | |
| 14 | 14 | // Calculate the watermark position | 
| 15 | 15 |      switch ($position) {
 | 
| @@ -110,8 +110,7 @@ discard block | ||
| 110 | 110 | /** | 
| 111 | 111 | * @param array $_files represents the $_FILES array passed as dependancy | 
| 112 | 112 | */ | 
| 113 | - public function __construct(array $_files = []) | |
| 114 | -    {
 | |
| 113 | +    public function __construct(array $_files = []) { | |
| 115 | 114 | $this->_files = $_files; | 
| 116 | 115 | } | 
| 117 | 116 | |
| @@ -122,8 +121,7 @@ discard block | ||
| 122 | 121 | * | 
| 123 | 122 | * @return bool|string | 
| 124 | 123 | */ | 
| 125 | - protected function getImageMime($tmp_name) | |
| 126 | -    {
 | |
| 124 | +    protected function getImageMime($tmp_name) { | |
| 127 | 125 |          if (isset($this->imageMimes[exif_imagetype($tmp_name)])) {
 | 
| 128 | 126 | return $this->imageMimes [exif_imagetype($tmp_name)]; | 
| 129 | 127 | } | 
| @@ -145,8 +143,7 @@ discard block | ||
| 145 | 143 | * | 
| 146 | 144 | * @return bool|mixed | 
| 147 | 145 | */ | 
| 148 | - public function offsetGet($offset) | |
| 149 | -    {
 | |
| 146 | +    public function offsetGet($offset) { | |
| 150 | 147 |          if ($offset == "error") {
 | 
| 151 | 148 | return $this->error; | 
| 152 | 149 | } | 
| @@ -166,8 +163,7 @@ discard block | ||
| 166 | 163 | * | 
| 167 | 164 | * @return $this | 
| 168 | 165 | */ | 
| 169 | - public function setName($isNameProvided = null) | |
| 170 | -    {
 | |
| 166 | +    public function setName($isNameProvided = null) { | |
| 171 | 167 |          if ($isNameProvided) {
 | 
| 172 | 168 | $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); | 
| 173 | 169 | } | 
| @@ -182,8 +178,7 @@ discard block | ||
| 182 | 178 | * | 
| 183 | 179 | * @return $this | 
| 184 | 180 | */ | 
| 185 | - public function setMime(array $fileTypes) | |
| 186 | -    {
 | |
| 181 | +    public function setMime(array $fileTypes) { | |
| 187 | 182 | $this->mimeTypes = $fileTypes; | 
| 188 | 183 | return $this; | 
| 189 | 184 | } | 
| @@ -196,8 +191,7 @@ discard block | ||
| 196 | 191 | * | 
| 197 | 192 | * @return $this | 
| 198 | 193 | */ | 
| 199 | - public function setSize($min, $max) | |
| 200 | -    {
 | |
| 194 | +    public function setSize($min, $max) { | |
| 201 | 195 | $this->size = array($min, $max); | 
| 202 | 196 | return $this; | 
| 203 | 197 | } | 
| @@ -210,8 +204,7 @@ discard block | ||
| 210 | 204 | * | 
| 211 | 205 | * @return $this | 
| 212 | 206 | */ | 
| 213 | - public function setLocation($dir = "bulletproof", $permission = 0666) | |
| 214 | -    {
 | |
| 207 | +    public function setLocation($dir = "bulletproof", $permission = 0666) { | |
| 215 | 208 |          if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
 | 
| 216 | 209 |              $createFolder = @mkdir("" . $dir, (int) $permission, true);
 | 
| 217 | 210 |              if (!$createFolder) {
 | 
| @@ -232,8 +225,7 @@ discard block | ||
| 232 | 225 | * | 
| 233 | 226 | * @return $this | 
| 234 | 227 | */ | 
| 235 | - public function setDimension($maxWidth, $maxHeight) | |
| 236 | -    {
 | |
| 228 | +    public function setDimension($maxWidth, $maxHeight) { | |
| 237 | 229 | $this->dimensions = array($maxWidth, $maxHeight); | 
| 238 | 230 | return $this; | 
| 239 | 231 | } | 
| @@ -245,8 +237,7 @@ discard block | ||
| 245 | 237 | * | 
| 246 | 238 | * @return $this | 
| 247 | 239 | */ | 
| 248 | - public function setErrorMessages($new_error_messages) | |
| 249 | -	{
 | |
| 240 | +	public function setErrorMessages($new_error_messages) { | |
| 250 | 241 |  		if($new_array = array_replace_recursive($this->error_messages, $new_error_messages)) {
 | 
| 251 | 242 | $this->error_messages = $new_array; | 
| 252 | 243 | }; | 
| @@ -258,8 +249,7 @@ discard block | ||
| 258 | 249 | * | 
| 259 | 250 | * @return string | 
| 260 | 251 | */ | 
| 261 | - public function getName() | |
| 262 | -    {
 | |
| 252 | +    public function getName() { | |
| 263 | 253 |          if (!$this->name) {
 | 
| 264 | 254 |             return  uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
 | 
| 265 | 255 | } | 
| @@ -272,8 +262,7 @@ discard block | ||
| 272 | 262 | * | 
| 273 | 263 | * @return string | 
| 274 | 264 | */ | 
| 275 | - public function getFullPath() | |
| 276 | -    {
 | |
| 265 | +    public function getFullPath() { | |
| 277 | 266 | $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime; | 
| 278 | 267 | return $this->fullPath; | 
| 279 | 268 | } | 
| @@ -283,8 +272,7 @@ discard block | ||
| 283 | 272 | * | 
| 284 | 273 | * @return int | 
| 285 | 274 | */ | 
| 286 | - public function getSize() | |
| 287 | -    {
 | |
| 275 | +    public function getSize() { | |
| 288 | 276 | return (int) $this->_files["size"]; | 
| 289 | 277 | } | 
| 290 | 278 | |
| @@ -293,8 +281,7 @@ discard block | ||
| 293 | 281 | * | 
| 294 | 282 | * @return int | 
| 295 | 283 | */ | 
| 296 | - public function getHeight() | |
| 297 | -    {
 | |
| 284 | +    public function getHeight() { | |
| 298 | 285 |          if ($this->height != null) {
 | 
| 299 | 286 | return $this->height; | 
| 300 | 287 | } | 
| @@ -308,8 +295,7 @@ discard block | ||
| 308 | 295 | * | 
| 309 | 296 | * @return int | 
| 310 | 297 | */ | 
| 311 | - public function getWidth() | |
| 312 | -    {
 | |
| 298 | +    public function getWidth() { | |
| 313 | 299 |          if ($this->width != null) {
 | 
| 314 | 300 | return $this->width; | 
| 315 | 301 | } | 
| @@ -323,8 +309,7 @@ discard block | ||
| 323 | 309 | * | 
| 324 | 310 | * @return string | 
| 325 | 311 | */ | 
| 326 | - public function getLocation() | |
| 327 | -    {
 | |
| 312 | +    public function getLocation() { | |
| 328 | 313 |          if(!$this->location){
 | 
| 329 | 314 | $this->setLocation(); | 
| 330 | 315 | } | 
| @@ -337,8 +322,7 @@ discard block | ||
| 337 | 322 | * | 
| 338 | 323 | * @return string | 
| 339 | 324 | */ | 
| 340 | - public function getJson() | |
| 341 | -    {
 | |
| 325 | +    public function getJson() { | |
| 342 | 326 | return json_encode($this->serialize); | 
| 343 | 327 | } | 
| 344 | 328 | |
| @@ -347,8 +331,7 @@ discard block | ||
| 347 | 331 | * | 
| 348 | 332 | * @return string | 
| 349 | 333 | */ | 
| 350 | - public function getMime() | |
| 351 | -    {
 | |
| 334 | +    public function getMime() { | |
| 352 | 335 | return $this->mime; | 
| 353 | 336 | } | 
| 354 | 337 | |
| @@ -357,7 +340,7 @@ discard block | ||
| 357 | 340 | * | 
| 358 | 341 | * @return string|bool | 
| 359 | 342 | */ | 
| 360 | -    public function getError(){
 | |
| 343 | +    public function getError() { | |
| 361 | 344 | return $this->error != "" ? $this->error : false; | 
| 362 | 345 | } | 
| 363 | 346 | |
| @@ -366,8 +349,7 @@ discard block | ||
| 366 | 349 | * | 
| 367 | 350 | * @param $e int error constant | 
| 368 | 351 | */ | 
| 369 | - protected function uploadErrors($e) | |
| 370 | -    {
 | |
| 352 | +    protected function uploadErrors($e) { | |
| 371 | 353 | $errors = $this->error_messages['upload']; | 
| 372 | 354 | return $errors[$e]; | 
| 373 | 355 | } | 
| @@ -378,8 +360,7 @@ discard block | ||
| 378 | 360 | * | 
| 379 | 361 | * @return $this|bool | 
| 380 | 362 | */ | 
| 381 | - public function upload() | |
| 382 | -    {
 | |
| 363 | +    public function upload() { | |
| 383 | 364 | /* modify variable names for convenience */ | 
| 384 | 365 | $image = $this; | 
| 385 | 366 | $files = $this->_files; | 
| @@ -462,8 +443,7 @@ discard block | ||
| 462 | 443 | * | 
| 463 | 444 | * @return bool | 
| 464 | 445 | */ | 
| 465 | - public function moveUploadedFile($tmp_name, $destination) | |
| 466 | -    {
 | |
| 446 | +    public function moveUploadedFile($tmp_name, $destination) { | |
| 467 | 447 | return move_uploaded_file($tmp_name, $destination); | 
| 468 | 448 | } | 
| 469 | 449 | } | 
| @@ -152,7 +152,7 @@ discard block | ||
| 152 | 152 | * | 
| 153 | 153 | * @param mixed $offset | 
| 154 | 154 | * | 
| 155 | - * @return bool|mixed | |
| 155 | + * @return string|boolean | |
| 156 | 156 | */ | 
| 157 | 157 | public function offsetGet($offset) | 
| 158 | 158 |      {
 | 
| @@ -364,7 +364,7 @@ discard block | ||
| 364 | 364 | /** | 
| 365 | 365 | * Returns error string or false if no errors occurred | 
| 366 | 366 | * | 
| 367 | - * @return string|bool | |
| 367 | + * @return string|false | |
| 368 | 368 | */ | 
| 369 | 369 |      public function getError(){
 | 
| 370 | 370 | return $this->error != "" ? $this->error : false; | 
| @@ -473,7 +473,7 @@ discard block | ||
| 473 | 473 | * Final upload method to be called, isolated for testing purposes | 
| 474 | 474 | * | 
| 475 | 475 | * @param $tmp_name int the temporary location of the image file | 
| 476 | - * @param $destination int upload destination | |
| 476 | + * @param string $destination int upload destination | |
| 477 | 477 | * | 
| 478 | 478 | * @return bool | 
| 479 | 479 | */ | 
| @@ -16,89 +16,89 @@ discard block | ||
| 16 | 16 | |
| 17 | 17 | class Image implements \ArrayAccess | 
| 18 | 18 |  {
 | 
| 19 | - /** | |
| 20 | - * @var string The new image name, to be provided or will be generated. | |
| 21 | - */ | |
| 22 | - protected $name; | |
| 23 | - | |
| 24 | - /** | |
| 25 | - * @var int The image width in pixels | |
| 26 | - */ | |
| 27 | - protected $width; | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * @var int The image height in pixels | |
| 31 | - */ | |
| 32 | - protected $height; | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * @var string The image mime type (extension) | |
| 36 | - */ | |
| 37 | - protected $mime; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * @var string The full image path (dir + image + mime) | |
| 41 | - */ | |
| 42 | - protected $fullPath; | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * @var string The folder or image storage location | |
| 46 | - */ | |
| 47 | - protected $location; | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * @var array A json format of all information about an image | |
| 51 | - */ | |
| 52 | - protected $serialize = array(); | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * @var array The min and max image size allowed for upload (in bytes) | |
| 56 | - */ | |
| 57 | - protected $size = array(100, 50000); | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * @var array The max height and width image allowed | |
| 61 | - */ | |
| 62 | - protected $dimensions = array(500, 5000); | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * @var array The mime types allowed for upload | |
| 66 | - */ | |
| 67 | -    protected $mimeTypes = array("jpeg", "png", "gif");
 | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * @var array list of known image types | |
| 71 | - */ | |
| 72 | - protected $imageMimes = array( | |
| 73 | - 1 => "gif", "jpeg", "png", "swf", "psd", | |
| 74 | - "bmp", "tiff", "tiff", "jpc", "jp2", "jpx", | |
| 75 | - "jb2", "swc", "iff", "wbmp", "xbm", "ico" | |
| 76 | - ); | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * @var array storage for the $_FILES global array | |
| 80 | - */ | |
| 81 | - private $_files = array(); | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * @var string storage for any errors | |
| 85 | - */ | |
| 86 | - private $error = ""; | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * @var array error messages strings | |
| 90 | - */ | |
| 91 | - private $error_messages = array( | |
| 19 | + /** | |
| 20 | + * @var string The new image name, to be provided or will be generated. | |
| 21 | + */ | |
| 22 | + protected $name; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * @var int The image width in pixels | |
| 26 | + */ | |
| 27 | + protected $width; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * @var int The image height in pixels | |
| 31 | + */ | |
| 32 | + protected $height; | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * @var string The image mime type (extension) | |
| 36 | + */ | |
| 37 | + protected $mime; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * @var string The full image path (dir + image + mime) | |
| 41 | + */ | |
| 42 | + protected $fullPath; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * @var string The folder or image storage location | |
| 46 | + */ | |
| 47 | + protected $location; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * @var array A json format of all information about an image | |
| 51 | + */ | |
| 52 | + protected $serialize = array(); | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @var array The min and max image size allowed for upload (in bytes) | |
| 56 | + */ | |
| 57 | + protected $size = array(100, 50000); | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * @var array The max height and width image allowed | |
| 61 | + */ | |
| 62 | + protected $dimensions = array(500, 5000); | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * @var array The mime types allowed for upload | |
| 66 | + */ | |
| 67 | +	protected $mimeTypes = array("jpeg", "png", "gif");
 | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * @var array list of known image types | |
| 71 | + */ | |
| 72 | + protected $imageMimes = array( | |
| 73 | + 1 => "gif", "jpeg", "png", "swf", "psd", | |
| 74 | + "bmp", "tiff", "tiff", "jpc", "jp2", "jpx", | |
| 75 | + "jb2", "swc", "iff", "wbmp", "xbm", "ico" | |
| 76 | + ); | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * @var array storage for the $_FILES global array | |
| 80 | + */ | |
| 81 | + private $_files = array(); | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * @var string storage for any errors | |
| 85 | + */ | |
| 86 | + private $error = ""; | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * @var array error messages strings | |
| 90 | + */ | |
| 91 | + private $error_messages = array( | |
| 92 | 92 | 'upload' => array( | 
| 93 | - UPLOAD_ERR_OK => "", | |
| 94 | - UPLOAD_ERR_INI_SIZE => "Image is larger than the specified amount set by the server", | |
| 95 | - UPLOAD_ERR_FORM_SIZE => "Image is larger than the specified amount specified by browser", | |
| 96 | - UPLOAD_ERR_PARTIAL => "Image could not be fully uploaded. Please try again later", | |
| 97 | - UPLOAD_ERR_NO_FILE => "Image is not found", | |
| 98 | - UPLOAD_ERR_NO_TMP_DIR => "Can't write to disk, due to server configuration ( No tmp dir found )", | |
| 99 | - UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk. Please check you file permissions", | |
| 100 | - UPLOAD_ERR_EXTENSION => "A PHP extension has halted this file upload process" | |
| 101 | - ), | |
| 93 | + UPLOAD_ERR_OK => "", | |
| 94 | + UPLOAD_ERR_INI_SIZE => "Image is larger than the specified amount set by the server", | |
| 95 | + UPLOAD_ERR_FORM_SIZE => "Image is larger than the specified amount specified by browser", | |
| 96 | + UPLOAD_ERR_PARTIAL => "Image could not be fully uploaded. Please try again later", | |
| 97 | + UPLOAD_ERR_NO_FILE => "Image is not found", | |
| 98 | + UPLOAD_ERR_NO_TMP_DIR => "Can't write to disk, due to server configuration ( No tmp dir found )", | |
| 99 | + UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk. Please check you file permissions", | |
| 100 | + UPLOAD_ERR_EXTENSION => "A PHP extension has halted this file upload process" | |
| 101 | + ), | |
| 102 | 102 | 'location' => "Folder %s could not be created", | 
| 103 | 103 | 'mime_type' => "Invalid File! Only (%s) image types are allowed", | 
| 104 | 104 | 'file_size' => "Image size should be atleast more than min: %s and less than max: %s kb", | 
| @@ -107,145 +107,145 @@ discard block | ||
| 107 | 107 | 'unknown' => "Upload failed, Unknown error occured" | 
| 108 | 108 | ); | 
| 109 | 109 | |
| 110 | - /** | |
| 111 | - * @param array $_files represents the $_FILES array passed as dependency | |
| 112 | - */ | |
| 113 | - public function __construct(array $_files = []) | |
| 114 | -    {
 | |
| 115 | - $this->_files = $_files; | |
| 116 | - } | |
| 117 | - | |
| 118 | - /** | |
| 119 | - * Gets the real image mime type | |
| 120 | - * | |
| 121 | - * @param $tmp_name string The upload tmp directory | |
| 122 | - * | |
| 123 | - * @return bool|string | |
| 124 | - */ | |
| 125 | - protected function getImageMime($tmp_name) | |
| 126 | -    {
 | |
| 127 | -        if (isset($this->imageMimes[exif_imagetype($tmp_name)])) {
 | |
| 128 | - return $this->imageMimes [exif_imagetype($tmp_name)]; | |
| 129 | - } | |
| 130 | - return false; | |
| 131 | - } | |
| 132 | - | |
| 133 | - /** | |
| 134 | - * @param mixed $offset | |
| 135 | - * @param mixed $value | |
| 136 | - */ | |
| 137 | -    public function offsetSet($offset, $value){}
 | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * @param mixed $offset | |
| 141 | - * @return null | |
| 142 | - */ | |
| 143 | -    public function offsetExists($offset){}
 | |
| 144 | - | |
| 145 | - /** | |
| 146 | - * @param mixed $offset | |
| 147 | - */ | |
| 148 | -    public function offsetUnset($offset){}
 | |
| 149 | - | |
| 150 | - /** | |
| 151 | - * Gets array value \ArrayAccess | |
| 152 | - * | |
| 153 | - * @param mixed $offset | |
| 154 | - * | |
| 155 | - * @return bool|mixed | |
| 156 | - */ | |
| 157 | - public function offsetGet($offset) | |
| 158 | -    {
 | |
| 159 | -        if ($offset == "error") {
 | |
| 160 | - return $this->error; | |
| 161 | - } | |
| 162 | - | |
| 163 | -        if (isset($this->_files[$offset]) && file_exists($this->_files[$offset]["tmp_name"])) {
 | |
| 164 | - $this->_files = $this->_files[$offset]; | |
| 165 | - return true; | |
| 166 | - } | |
| 110 | + /** | |
| 111 | + * @param array $_files represents the $_FILES array passed as dependency | |
| 112 | + */ | |
| 113 | + public function __construct(array $_files = []) | |
| 114 | +	{
 | |
| 115 | + $this->_files = $_files; | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Gets the real image mime type | |
| 120 | + * | |
| 121 | + * @param $tmp_name string The upload tmp directory | |
| 122 | + * | |
| 123 | + * @return bool|string | |
| 124 | + */ | |
| 125 | + protected function getImageMime($tmp_name) | |
| 126 | +	{
 | |
| 127 | +		if (isset($this->imageMimes[exif_imagetype($tmp_name)])) {
 | |
| 128 | + return $this->imageMimes [exif_imagetype($tmp_name)]; | |
| 129 | + } | |
| 130 | + return false; | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * @param mixed $offset | |
| 135 | + * @param mixed $value | |
| 136 | + */ | |
| 137 | +	public function offsetSet($offset, $value){}
 | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * @param mixed $offset | |
| 141 | + * @return null | |
| 142 | + */ | |
| 143 | +	public function offsetExists($offset){}
 | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * @param mixed $offset | |
| 147 | + */ | |
| 148 | +	public function offsetUnset($offset){}
 | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * Gets array value \ArrayAccess | |
| 152 | + * | |
| 153 | + * @param mixed $offset | |
| 154 | + * | |
| 155 | + * @return bool|mixed | |
| 156 | + */ | |
| 157 | + public function offsetGet($offset) | |
| 158 | +	{
 | |
| 159 | +		if ($offset == "error") {
 | |
| 160 | + return $this->error; | |
| 161 | + } | |
| 162 | + | |
| 163 | +		if (isset($this->_files[$offset]) && file_exists($this->_files[$offset]["tmp_name"])) {
 | |
| 164 | + $this->_files = $this->_files[$offset]; | |
| 165 | + return true; | |
| 166 | + } | |
| 167 | 167 | |
| 168 | - return false; | |
| 169 | - } | |
| 170 | - | |
| 171 | - | |
| 172 | - /** | |
| 173 | - * Provide image name if not provided | |
| 174 | - * | |
| 175 | - * @param null $isNameProvided | |
| 176 | - * @return $this | |
| 177 | - */ | |
| 178 | - public function setName($isNameProvided = null) | |
| 179 | -    {
 | |
| 180 | -        if ($isNameProvided) {
 | |
| 181 | - $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); | |
| 182 | - } | |
| 168 | + return false; | |
| 169 | + } | |
| 170 | + | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * Provide image name if not provided | |
| 174 | + * | |
| 175 | + * @param null $isNameProvided | |
| 176 | + * @return $this | |
| 177 | + */ | |
| 178 | + public function setName($isNameProvided = null) | |
| 179 | +	{
 | |
| 180 | +		if ($isNameProvided) {
 | |
| 181 | + $this->name = filter_var($isNameProvided, FILTER_SANITIZE_STRING); | |
| 182 | + } | |
| 183 | 183 | |
| 184 | - return $this; | |
| 185 | - } | |
| 186 | - | |
| 187 | - /** | |
| 188 | - * Define a mime type for uploading | |
| 189 | - * | |
| 190 | - * @param array $fileTypes | |
| 191 | - * | |
| 192 | - * @return $this | |
| 193 | - */ | |
| 194 | - public function setMime(array $fileTypes) | |
| 195 | -    {
 | |
| 196 | - $this->mimeTypes = $fileTypes; | |
| 197 | - return $this; | |
| 198 | - } | |
| 199 | - | |
| 200 | - /** | |
| 201 | - * Define a min and max image size for uploading | |
| 202 | - * | |
| 203 | - * @param $min int minimum value in bytes | |
| 204 | - * @param $max int maximum value in bytes | |
| 205 | - * | |
| 206 | - * @return $this | |
| 207 | - */ | |
| 208 | - public function setSize($min, $max) | |
| 209 | -    {
 | |
| 210 | - $this->size = array($min, $max); | |
| 211 | - return $this; | |
| 212 | - } | |
| 213 | - | |
| 214 | - /** | |
| 215 | - * Creates a location for upload storage | |
| 216 | - * | |
| 217 | - * @param $dir string the folder name to create | |
| 218 | - * @param int $permission chmod permission | |
| 219 | - * | |
| 220 | - * @return $this | |
| 221 | - */ | |
| 222 | - public function setLocation($dir = "bulletproof", $permission = 0666) | |
| 223 | -    {
 | |
| 224 | -        if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
 | |
| 225 | -            $createFolder = @mkdir("" . $dir, (int) $permission, true);
 | |
| 226 | -            if (!$createFolder) {
 | |
| 227 | - $this->error = sprintf($this->error_messages['location'], $dir); | |
| 228 | - return; | |
| 229 | - } | |
| 230 | - } | |
| 231 | - | |
| 232 | - $this->location = $dir; | |
| 233 | - return $this; | |
| 234 | - } | |
| 235 | - | |
| 236 | - /** | |
| 237 | - * Sets acceptable max image height and width | |
| 238 | - * | |
| 239 | - * @param $maxWidth int max width value | |
| 240 | - * @param $maxHeight int max height value | |
| 241 | - * | |
| 242 | - * @return $this | |
| 243 | - */ | |
| 244 | - public function setDimension($maxWidth, $maxHeight) | |
| 245 | -    {
 | |
| 246 | - $this->dimensions = array($maxWidth, $maxHeight); | |
| 247 | - return $this; | |
| 248 | - } | |
| 184 | + return $this; | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** | |
| 188 | + * Define a mime type for uploading | |
| 189 | + * | |
| 190 | + * @param array $fileTypes | |
| 191 | + * | |
| 192 | + * @return $this | |
| 193 | + */ | |
| 194 | + public function setMime(array $fileTypes) | |
| 195 | +	{
 | |
| 196 | + $this->mimeTypes = $fileTypes; | |
| 197 | + return $this; | |
| 198 | + } | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * Define a min and max image size for uploading | |
| 202 | + * | |
| 203 | + * @param $min int minimum value in bytes | |
| 204 | + * @param $max int maximum value in bytes | |
| 205 | + * | |
| 206 | + * @return $this | |
| 207 | + */ | |
| 208 | + public function setSize($min, $max) | |
| 209 | +	{
 | |
| 210 | + $this->size = array($min, $max); | |
| 211 | + return $this; | |
| 212 | + } | |
| 213 | + | |
| 214 | + /** | |
| 215 | + * Creates a location for upload storage | |
| 216 | + * | |
| 217 | + * @param $dir string the folder name to create | |
| 218 | + * @param int $permission chmod permission | |
| 219 | + * | |
| 220 | + * @return $this | |
| 221 | + */ | |
| 222 | + public function setLocation($dir = "bulletproof", $permission = 0666) | |
| 223 | +	{
 | |
| 224 | +		if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
 | |
| 225 | +			$createFolder = @mkdir("" . $dir, (int) $permission, true);
 | |
| 226 | +			if (!$createFolder) {
 | |
| 227 | + $this->error = sprintf($this->error_messages['location'], $dir); | |
| 228 | + return; | |
| 229 | + } | |
| 230 | + } | |
| 231 | + | |
| 232 | + $this->location = $dir; | |
| 233 | + return $this; | |
| 234 | + } | |
| 235 | + | |
| 236 | + /** | |
| 237 | + * Sets acceptable max image height and width | |
| 238 | + * | |
| 239 | + * @param $maxWidth int max width value | |
| 240 | + * @param $maxHeight int max height value | |
| 241 | + * | |
| 242 | + * @return $this | |
| 243 | + */ | |
| 244 | + public function setDimension($maxWidth, $maxHeight) | |
| 245 | +	{
 | |
| 246 | + $this->dimensions = array($maxWidth, $maxHeight); | |
| 247 | + return $this; | |
| 248 | + } | |
| 249 | 249 | |
| 250 | 250 | /** | 
| 251 | 251 | * Replace error_messages array values with values of given array | 
| @@ -262,223 +262,223 @@ discard block | ||
| 262 | 262 | return $this; | 
| 263 | 263 | } | 
| 264 | 264 | |
| 265 | - /** | |
| 266 | - * Returns the image name | |
| 267 | - * | |
| 268 | - * @return string | |
| 269 | - */ | |
| 270 | - public function getName() | |
| 271 | -    {
 | |
| 272 | -        if (!$this->name) {
 | |
| 273 | -           return  uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
 | |
| 274 | - } | |
| 275 | - | |
| 276 | - return $this->name; | |
| 277 | - } | |
| 278 | - | |
| 279 | - /** | |
| 280 | - * Returns the full path of the image ex "location/image.mime" | |
| 281 | - * | |
| 282 | - * @return string | |
| 283 | - */ | |
| 284 | - public function getFullPath() | |
| 285 | -    {
 | |
| 286 | - $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime; | |
| 287 | - return $this->fullPath; | |
| 288 | - } | |
| 289 | - | |
| 290 | - /** | |
| 291 | - * Returns the image size in bytes | |
| 292 | - * | |
| 293 | - * @return int | |
| 294 | - */ | |
| 295 | - public function getSize() | |
| 296 | -    {
 | |
| 297 | - return (int) $this->_files["size"]; | |
| 298 | - } | |
| 299 | - | |
| 300 | - /** | |
| 301 | - * Returns the image height in pixels | |
| 302 | - * | |
| 303 | - * @return int | |
| 304 | - */ | |
| 305 | - public function getHeight() | |
| 306 | -    {
 | |
| 307 | -        if ($this->height != null) {
 | |
| 308 | - return $this->height; | |
| 309 | - } | |
| 310 | - | |
| 311 | - list(, $height) = getImageSize($this->_files["tmp_name"]); | |
| 312 | - return $height; | |
| 313 | - } | |
| 314 | - | |
| 315 | - /** | |
| 316 | - * Returns the image width | |
| 317 | - * | |
| 318 | - * @return int | |
| 319 | - */ | |
| 320 | - public function getWidth() | |
| 321 | -    {
 | |
| 322 | -        if ($this->width != null) {
 | |
| 323 | - return $this->width; | |
| 324 | - } | |
| 325 | - | |
| 326 | - list($width) = getImageSize($this->_files["tmp_name"]); | |
| 327 | - return $width; | |
| 328 | - } | |
| 329 | - | |
| 330 | - /** | |
| 331 | - * Returns the storage / folder name | |
| 332 | - * | |
| 333 | - * @return string | |
| 334 | - */ | |
| 335 | - public function getLocation() | |
| 336 | -    {
 | |
| 337 | -        if(!$this->location){
 | |
| 338 | - $this->setLocation(); | |
| 339 | - } | |
| 340 | - | |
| 341 | - return $this->location; | |
| 342 | - } | |
| 343 | - | |
| 344 | - /** | |
| 345 | - * Returns a JSON format of the image width, height, name, mime ... | |
| 346 | - * | |
| 347 | - * @return string | |
| 348 | - */ | |
| 349 | - public function getJson() | |
| 350 | -    {
 | |
| 351 | - return json_encode($this->serialize); | |
| 352 | - } | |
| 353 | - | |
| 354 | - /** | |
| 355 | - * Returns the image mime type | |
| 356 | - * | |
| 357 | - * @return string | |
| 358 | - */ | |
| 359 | - public function getMime() | |
| 360 | -    {
 | |
| 361 | - return $this->mime; | |
| 362 | - } | |
| 363 | - | |
| 364 | - /** | |
| 365 | - * Returns error string or false if no errors occurred | |
| 366 | - * | |
| 367 | - * @return string|bool | |
| 368 | - */ | |
| 369 | -    public function getError(){
 | |
| 370 | - return $this->error != "" ? $this->error : false; | |
| 371 | - } | |
| 372 | - | |
| 373 | - /** | |
| 374 | - * Checks for the common upload errors | |
| 375 | - * | |
| 376 | - * @param $e int error constant | |
| 377 | - */ | |
| 378 | - protected function uploadErrors($e) | |
| 379 | -    {
 | |
| 380 | - $errors = $this->error_messages['upload']; | |
| 381 | - return $errors[$e]; | |
| 382 | - } | |
| 383 | - | |
| 384 | - | |
| 385 | - /** | |
| 386 | - * This methods validates and uploads the image | |
| 387 | - * @return bool|Image|null | |
| 388 | - * @throws ImageUploaderException | |
| 389 | - */ | |
| 390 | - public function upload() | |
| 391 | -    {
 | |
| 392 | - /* modify variable names for convenience */ | |
| 393 | - $image = $this; | |
| 394 | - $files = $this->_files; | |
| 395 | - | |
| 396 | - /* check if php_exif is enabled */ | |
| 397 | -        if(!function_exists('exif_imagetype')){
 | |
| 398 | - $image->error = "Function 'exif_imagetype' Not found. Please enable \"php_exif\" in your PHP.ini"; | |
| 399 | - return null; | |
| 400 | - } | |
| 401 | - | |
| 402 | - /* initialize image properties */ | |
| 403 | - $image->name = $image->getName(); | |
| 404 | - $image->width = $image->getWidth(); | |
| 405 | - $image->height = $image->getHeight(); | |
| 406 | - $image->location = $image->getLocation(); | |
| 407 | - | |
| 408 | - /* get image sizes */ | |
| 409 | - list($minSize, $maxSize) = $image->size; | |
| 410 | - | |
| 411 | - /* check for common upload errors */ | |
| 412 | -        if($image->error = $image->uploadErrors($files["error"])){
 | |
| 413 | - return null; | |
| 414 | - } | |
| 415 | - | |
| 416 | - /* check image for valid mime types and return mime */ | |
| 417 | - $image->mime = $image->getImageMime($files["tmp_name"]); | |
| 418 | - | |
| 419 | - /* validate image mime type */ | |
| 420 | -        if (!in_array($image->mime, $image->mimeTypes)) {
 | |
| 421 | -            $ext = implode(", ", $image->mimeTypes);
 | |
| 422 | - $image->error = sprintf($this->error_messages['mime_type'], $ext); | |
| 423 | - return null; | |
| 424 | - } | |
| 425 | - | |
| 426 | - /* check image size based on the settings */ | |
| 427 | -        if ($files["size"] < $minSize || $files["size"] > $maxSize) {
 | |
| 428 | - $min = intval($minSize / 1000) ?: 1; $max = intval($maxSize / 1000); | |
| 429 | - | |
| 430 | - $image->error = sprintf($this->error_messages['file_size'], $min, $max); | |
| 431 | - return null; | |
| 432 | - } | |
| 433 | - | |
| 434 | - /* check image dimension */ | |
| 435 | - list($allowedWidth, $allowedHeight) = $image->dimensions; | |
| 436 | - | |
| 437 | -        if ($image->height > $allowedHeight || $image->width > $allowedWidth) {
 | |
| 438 | - $image->error = sprintf($this->error_messages['dimensions'], $allowedHeight, $allowedWidth); | |
| 439 | - return null; | |
| 440 | - } | |
| 441 | - | |
| 442 | -        if($image->height < 4 || $image->width < 4){
 | |
| 443 | - $image->error = $this->error_messages['too_small']; | |
| 444 | - return null; | |
| 445 | - } | |
| 265 | + /** | |
| 266 | + * Returns the image name | |
| 267 | + * | |
| 268 | + * @return string | |
| 269 | + */ | |
| 270 | + public function getName() | |
| 271 | +	{
 | |
| 272 | +		if (!$this->name) {
 | |
| 273 | +		   return  uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
 | |
| 274 | + } | |
| 275 | + | |
| 276 | + return $this->name; | |
| 277 | + } | |
| 278 | + | |
| 279 | + /** | |
| 280 | + * Returns the full path of the image ex "location/image.mime" | |
| 281 | + * | |
| 282 | + * @return string | |
| 283 | + */ | |
| 284 | + public function getFullPath() | |
| 285 | +	{
 | |
| 286 | + $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime; | |
| 287 | + return $this->fullPath; | |
| 288 | + } | |
| 289 | + | |
| 290 | + /** | |
| 291 | + * Returns the image size in bytes | |
| 292 | + * | |
| 293 | + * @return int | |
| 294 | + */ | |
| 295 | + public function getSize() | |
| 296 | +	{
 | |
| 297 | + return (int) $this->_files["size"]; | |
| 298 | + } | |
| 299 | + | |
| 300 | + /** | |
| 301 | + * Returns the image height in pixels | |
| 302 | + * | |
| 303 | + * @return int | |
| 304 | + */ | |
| 305 | + public function getHeight() | |
| 306 | +	{
 | |
| 307 | +		if ($this->height != null) {
 | |
| 308 | + return $this->height; | |
| 309 | + } | |
| 310 | + | |
| 311 | + list(, $height) = getImageSize($this->_files["tmp_name"]); | |
| 312 | + return $height; | |
| 313 | + } | |
| 314 | + | |
| 315 | + /** | |
| 316 | + * Returns the image width | |
| 317 | + * | |
| 318 | + * @return int | |
| 319 | + */ | |
| 320 | + public function getWidth() | |
| 321 | +	{
 | |
| 322 | +		if ($this->width != null) {
 | |
| 323 | + return $this->width; | |
| 324 | + } | |
| 325 | + | |
| 326 | + list($width) = getImageSize($this->_files["tmp_name"]); | |
| 327 | + return $width; | |
| 328 | + } | |
| 329 | + | |
| 330 | + /** | |
| 331 | + * Returns the storage / folder name | |
| 332 | + * | |
| 333 | + * @return string | |
| 334 | + */ | |
| 335 | + public function getLocation() | |
| 336 | +	{
 | |
| 337 | +		if(!$this->location){
 | |
| 338 | + $this->setLocation(); | |
| 339 | + } | |
| 340 | + | |
| 341 | + return $this->location; | |
| 342 | + } | |
| 343 | + | |
| 344 | + /** | |
| 345 | + * Returns a JSON format of the image width, height, name, mime ... | |
| 346 | + * | |
| 347 | + * @return string | |
| 348 | + */ | |
| 349 | + public function getJson() | |
| 350 | +	{
 | |
| 351 | + return json_encode($this->serialize); | |
| 352 | + } | |
| 353 | + | |
| 354 | + /** | |
| 355 | + * Returns the image mime type | |
| 356 | + * | |
| 357 | + * @return string | |
| 358 | + */ | |
| 359 | + public function getMime() | |
| 360 | +	{
 | |
| 361 | + return $this->mime; | |
| 362 | + } | |
| 363 | + | |
| 364 | + /** | |
| 365 | + * Returns error string or false if no errors occurred | |
| 366 | + * | |
| 367 | + * @return string|bool | |
| 368 | + */ | |
| 369 | +	public function getError(){
 | |
| 370 | + return $this->error != "" ? $this->error : false; | |
| 371 | + } | |
| 372 | + | |
| 373 | + /** | |
| 374 | + * Checks for the common upload errors | |
| 375 | + * | |
| 376 | + * @param $e int error constant | |
| 377 | + */ | |
| 378 | + protected function uploadErrors($e) | |
| 379 | +	{
 | |
| 380 | + $errors = $this->error_messages['upload']; | |
| 381 | + return $errors[$e]; | |
| 382 | + } | |
| 383 | + | |
| 384 | + | |
| 385 | + /** | |
| 386 | + * This methods validates and uploads the image | |
| 387 | + * @return bool|Image|null | |
| 388 | + * @throws ImageUploaderException | |
| 389 | + */ | |
| 390 | + public function upload() | |
| 391 | +	{
 | |
| 392 | + /* modify variable names for convenience */ | |
| 393 | + $image = $this; | |
| 394 | + $files = $this->_files; | |
| 395 | + | |
| 396 | + /* check if php_exif is enabled */ | |
| 397 | +		if(!function_exists('exif_imagetype')){
 | |
| 398 | + $image->error = "Function 'exif_imagetype' Not found. Please enable \"php_exif\" in your PHP.ini"; | |
| 399 | + return null; | |
| 400 | + } | |
| 401 | + | |
| 402 | + /* initialize image properties */ | |
| 403 | + $image->name = $image->getName(); | |
| 404 | + $image->width = $image->getWidth(); | |
| 405 | + $image->height = $image->getHeight(); | |
| 406 | + $image->location = $image->getLocation(); | |
| 407 | + | |
| 408 | + /* get image sizes */ | |
| 409 | + list($minSize, $maxSize) = $image->size; | |
| 410 | + | |
| 411 | + /* check for common upload errors */ | |
| 412 | +		if($image->error = $image->uploadErrors($files["error"])){
 | |
| 413 | + return null; | |
| 414 | + } | |
| 415 | + | |
| 416 | + /* check image for valid mime types and return mime */ | |
| 417 | + $image->mime = $image->getImageMime($files["tmp_name"]); | |
| 418 | + | |
| 419 | + /* validate image mime type */ | |
| 420 | +		if (!in_array($image->mime, $image->mimeTypes)) {
 | |
| 421 | +			$ext = implode(", ", $image->mimeTypes);
 | |
| 422 | + $image->error = sprintf($this->error_messages['mime_type'], $ext); | |
| 423 | + return null; | |
| 424 | + } | |
| 425 | + | |
| 426 | + /* check image size based on the settings */ | |
| 427 | +		if ($files["size"] < $minSize || $files["size"] > $maxSize) {
 | |
| 428 | + $min = intval($minSize / 1000) ?: 1; $max = intval($maxSize / 1000); | |
| 429 | + | |
| 430 | + $image->error = sprintf($this->error_messages['file_size'], $min, $max); | |
| 431 | + return null; | |
| 432 | + } | |
| 433 | + | |
| 434 | + /* check image dimension */ | |
| 435 | + list($allowedWidth, $allowedHeight) = $image->dimensions; | |
| 436 | + | |
| 437 | +		if ($image->height > $allowedHeight || $image->width > $allowedWidth) {
 | |
| 438 | + $image->error = sprintf($this->error_messages['dimensions'], $allowedHeight, $allowedWidth); | |
| 439 | + return null; | |
| 440 | + } | |
| 441 | + | |
| 442 | +		if($image->height < 4 || $image->width < 4){
 | |
| 443 | + $image->error = $this->error_messages['too_small']; | |
| 444 | + return null; | |
| 445 | + } | |
| 446 | 446 | |
| 447 | - /* set and get folder name */ | |
| 448 | - $image->fullPath = $image->location. "/" . $image->name . "." . $image->mime; | |
| 449 | - | |
| 450 | - /* gather image info for json storage */ | |
| 451 | - $image->serialize = array( | |
| 452 | - "name" => $image->name, | |
| 453 | - "mime" => $image->mime, | |
| 454 | - "height" => $image->height, | |
| 455 | - "width" => $image->width, | |
| 456 | - "size" => $files["size"], | |
| 457 | - "location" => $image->location, | |
| 458 | - "fullpath" => $image->fullPath | |
| 459 | - ); | |
| 460 | - | |
| 461 | -        if ($image->error === "") {
 | |
| 462 | - $moveUpload = $image->moveUploadedFile($files["tmp_name"], $image->fullPath); | |
| 463 | -            if (false !== $moveUpload) {
 | |
| 464 | - return $image; | |
| 465 | - } | |
| 466 | - } | |
| 467 | - | |
| 468 | - $image->error = $this->error_messages['unknown']; | |
| 469 | - return false; | |
| 470 | - } | |
| 471 | - | |
| 472 | - /** | |
| 473 | - * Final upload method to be called, isolated for testing purposes | |
| 474 | - * | |
| 475 | - * @param $tmp_name int the temporary location of the image file | |
| 476 | - * @param $destination int upload destination | |
| 477 | - * | |
| 478 | - * @return bool | |
| 479 | - */ | |
| 480 | - public function moveUploadedFile($tmp_name, $destination) | |
| 481 | -    {
 | |
| 482 | - return move_uploaded_file($tmp_name, $destination); | |
| 483 | - } | |
| 447 | + /* set and get folder name */ | |
| 448 | + $image->fullPath = $image->location. "/" . $image->name . "." . $image->mime; | |
| 449 | + | |
| 450 | + /* gather image info for json storage */ | |
| 451 | + $image->serialize = array( | |
| 452 | + "name" => $image->name, | |
| 453 | + "mime" => $image->mime, | |
| 454 | + "height" => $image->height, | |
| 455 | + "width" => $image->width, | |
| 456 | + "size" => $files["size"], | |
| 457 | + "location" => $image->location, | |
| 458 | + "fullpath" => $image->fullPath | |
| 459 | + ); | |
| 460 | + | |
| 461 | +		if ($image->error === "") {
 | |
| 462 | + $moveUpload = $image->moveUploadedFile($files["tmp_name"], $image->fullPath); | |
| 463 | +			if (false !== $moveUpload) {
 | |
| 464 | + return $image; | |
| 465 | + } | |
| 466 | + } | |
| 467 | + | |
| 468 | + $image->error = $this->error_messages['unknown']; | |
| 469 | + return false; | |
| 470 | + } | |
| 471 | + | |
| 472 | + /** | |
| 473 | + * Final upload method to be called, isolated for testing purposes | |
| 474 | + * | |
| 475 | + * @param $tmp_name int the temporary location of the image file | |
| 476 | + * @param $destination int upload destination | |
| 477 | + * | |
| 478 | + * @return bool | |
| 479 | + */ | |
| 480 | + public function moveUploadedFile($tmp_name, $destination) | |
| 481 | +	{
 | |
| 482 | + return move_uploaded_file($tmp_name, $destination); | |
| 483 | + } | |
| 484 | 484 | } | 
| @@ -134,18 +134,18 @@ discard block | ||
| 134 | 134 | * @param mixed $offset | 
| 135 | 135 | * @param mixed $value | 
| 136 | 136 | */ | 
| 137 | -    public function offsetSet($offset, $value){}
 | |
| 137 | +    public function offsetSet($offset, $value) {}
 | |
| 138 | 138 | |
| 139 | 139 | /** | 
| 140 | 140 | * @param mixed $offset | 
| 141 | 141 | * @return null | 
| 142 | 142 | */ | 
| 143 | -    public function offsetExists($offset){}
 | |
| 143 | +    public function offsetExists($offset) {}
 | |
| 144 | 144 | |
| 145 | 145 | /** | 
| 146 | 146 | * @param mixed $offset | 
| 147 | 147 | */ | 
| 148 | -    public function offsetUnset($offset){}
 | |
| 148 | +    public function offsetUnset($offset) {}
 | |
| 149 | 149 | |
| 150 | 150 | /** | 
| 151 | 151 | * Gets array value \ArrayAccess | 
| @@ -222,7 +222,7 @@ discard block | ||
| 222 | 222 | public function setLocation($dir = "bulletproof", $permission = 0666) | 
| 223 | 223 |      {
 | 
| 224 | 224 |          if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
 | 
| 225 | -            $createFolder = @mkdir("" . $dir, (int) $permission, true);
 | |
| 225 | +            $createFolder = @mkdir("".$dir, (int) $permission, true);
 | |
| 226 | 226 |              if (!$createFolder) {
 | 
| 227 | 227 | $this->error = sprintf($this->error_messages['location'], $dir); | 
| 228 | 228 | return; | 
| @@ -256,7 +256,7 @@ discard block | ||
| 256 | 256 | */ | 
| 257 | 257 | public function setErrorMessages($new_error_messages) | 
| 258 | 258 |  	{
 | 
| 259 | -		if($new_array = array_replace_recursive($this->error_messages, $new_error_messages)) {
 | |
| 259 | +		if ($new_array = array_replace_recursive($this->error_messages, $new_error_messages)) {
 | |
| 260 | 260 | $this->error_messages = $new_array; | 
| 261 | 261 | }; | 
| 262 | 262 | return $this; | 
| @@ -270,7 +270,7 @@ discard block | ||
| 270 | 270 | public function getName() | 
| 271 | 271 |      {
 | 
| 272 | 272 |          if (!$this->name) {
 | 
| 273 | -           return  uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
 | |
| 273 | +           return  uniqid(true)."_".str_shuffle(implode(range("e", "q")));
 | |
| 274 | 274 | } | 
| 275 | 275 | |
| 276 | 276 | return $this->name; | 
| @@ -283,7 +283,7 @@ discard block | ||
| 283 | 283 | */ | 
| 284 | 284 | public function getFullPath() | 
| 285 | 285 |      {
 | 
| 286 | - $this->fullPath = $this->location . "/" . $this->name . "." . $this->mime; | |
| 286 | + $this->fullPath = $this->location."/".$this->name.".".$this->mime; | |
| 287 | 287 | return $this->fullPath; | 
| 288 | 288 | } | 
| 289 | 289 | |
| @@ -334,7 +334,7 @@ discard block | ||
| 334 | 334 | */ | 
| 335 | 335 | public function getLocation() | 
| 336 | 336 |      {
 | 
| 337 | -        if(!$this->location){
 | |
| 337 | +        if (!$this->location) {
 | |
| 338 | 338 | $this->setLocation(); | 
| 339 | 339 | } | 
| 340 | 340 | |
| @@ -366,7 +366,7 @@ discard block | ||
| 366 | 366 | * | 
| 367 | 367 | * @return string|bool | 
| 368 | 368 | */ | 
| 369 | -    public function getError(){
 | |
| 369 | +    public function getError() {
 | |
| 370 | 370 | return $this->error != "" ? $this->error : false; | 
| 371 | 371 | } | 
| 372 | 372 | |
| @@ -394,7 +394,7 @@ discard block | ||
| 394 | 394 | $files = $this->_files; | 
| 395 | 395 | |
| 396 | 396 | /* check if php_exif is enabled */ | 
| 397 | -        if(!function_exists('exif_imagetype')){
 | |
| 397 | +        if (!function_exists('exif_imagetype')) {
 | |
| 398 | 398 | $image->error = "Function 'exif_imagetype' Not found. Please enable \"php_exif\" in your PHP.ini"; | 
| 399 | 399 | return null; | 
| 400 | 400 | } | 
| @@ -409,7 +409,7 @@ discard block | ||
| 409 | 409 | list($minSize, $maxSize) = $image->size; | 
| 410 | 410 | |
| 411 | 411 | /* check for common upload errors */ | 
| 412 | -        if($image->error = $image->uploadErrors($files["error"])){
 | |
| 412 | +        if ($image->error = $image->uploadErrors($files["error"])) {
 | |
| 413 | 413 | return null; | 
| 414 | 414 | } | 
| 415 | 415 | |
| @@ -439,13 +439,13 @@ discard block | ||
| 439 | 439 | return null; | 
| 440 | 440 | } | 
| 441 | 441 | |
| 442 | -        if($image->height < 4 || $image->width < 4){
 | |
| 442 | +        if ($image->height < 4 || $image->width < 4) {
 | |
| 443 | 443 | $image->error = $this->error_messages['too_small']; | 
| 444 | 444 | return null; | 
| 445 | 445 | } | 
| 446 | 446 | |
| 447 | 447 | /* set and get folder name */ | 
| 448 | - $image->fullPath = $image->location. "/" . $image->name . "." . $image->mime; | |
| 448 | + $image->fullPath = $image->location."/".$image->name.".".$image->mime; | |
| 449 | 449 | |
| 450 | 450 | /* gather image info for json storage */ | 
| 451 | 451 | $image->serialize = array( | 
| @@ -465,7 +465,7 @@ discard block | ||
| 465 | 465 | } | 
| 466 | 466 | } | 
| 467 | 467 | |
| 468 | - $image->error = $this->error_messages['unknown']; | |
| 468 | + $image->error = $this->error_messages['unknown']; | |
| 469 | 469 | return false; | 
| 470 | 470 | } | 
| 471 | 471 | |