php - Pictures taken from front camera becomes black when uploaded -


i'm using gd library resize images , exif fix orientation. works fine, on specific devices samsung galaxies, pic taken front camera gets uploaded becomes black. how fix it?

image resizing method:

public function process($task, $savepath, $taskwidth=0, $taskheight=0, $quality=80) {     $quality = (int) $quality;     $quality = ($quality < 0 or $quality > 100) ? 80 : $quality;      if (file_exists ($this->path))     {         if (in_array($this->extension, $this->photoextensions))         {             if ($this->extension == "gif")             {                 copy($this->path, $savepath);                 return true;             }              switch ($this->extension)             {                 case 'png':                     $im = imagecreatefrompng($this->path);                     break;                  default:                     $im = imagecreatefromjpeg($this->path);                     break;             }              if ($task == "crop")             {                 if ($taskwidth > 0 && $taskheight > 0)                 {                     $cropwidth = $this->imagewidth;                     $cropheight = $this->imageheight;                     $ratiowidth = 1;                     $ratioheight = 1;                     $destinationx = 0;                     $destinationy = 0;                     $sourcex = 0;                     $sourcey = 0;                      $cropwidth = ($taskwidth == 0 || $taskwidth > $this->imagewidth) ? $this->imagewidth : $taskwidth;                     $cropheight = ($taskheight == 0 || $taskheight > $this->imageheight) ? $this->imageheight : $taskheight;                      if ($cropwidth > $this->imagewidth)                     {                         $destinationx = ($cropwidth - $this->imagewidth) / 2;                     }                      if ($cropheight > $this->imageheight)                     {                         $destinationy = ($cropheight - $this->imageheight) / 2;                     }                      if ($cropwidth < $this->imagewidth || $cropheight < $this->imageheight)                     {                         $ratiowidth = $cropwidth / $this->imagewidth;                         $ratioheight = $cropheight / $this->imageheight;                          if ($cropheight > $this->imageheight)                         {                             $sourcex  = ($this->imagewidth - $cropwidth) / 2;                         }                         elseif ($cropwidth > $this->imagewidth)                         {                             $sourcey  = ($this->imageheight - $cropheight) / 2;                         }                         else                         {                             if ($ratioheight > $ratiowidth)                             {                                 $sourcex = round(($this->imagewidth - ($cropwidth / $ratioheight)) / 2);                             }                             else                             {                                 $sourcey = round(($this->imageheight - ($cropheight / $ratiowidth)) / 2);                             }                         }                     }                      $cropimage = @imagecreatetruecolor($cropwidth, $cropheight);                      if ($this->extension == "png")                     {                         @imagesavealpha($cropimage, true);                         @imagefill($cropimage, 0, 0, @imagecolorallocatealpha($cropimage, 0, 0, 0, 127));                     }                      @imagecopyresampled($cropimage, $im ,$destinationx, $destinationy, $sourcex, $sourcey, $cropwidth - 2 * $destinationx, $cropheight - 2 * $destinationy, $this->imagewidth - 2 * $sourcex, $this->imageheight - 2 * $sourcey);                      @imageinterlace($cropimage, true);                      switch ($this->extension)                     {                         case 'png':                             @imagepng($cropimage, $savepath);                             break;                          default:                             @imagejpeg($cropimage, $savepath, $quality);                             break;                     }                      @imagedestroy($cropimage);                 }             }             elseif ($task == "resize")             {                 if ($taskwidth == 0 && $taskheight == 0)                 {                     return false;                 }                  if ($taskwidth > 0 && $taskheight == 0)                 {                     $resizewidth = $taskwidth;                     $resizeratio = $resizewidth / $this->imagewidth;                     $resizeheight = floor($this->imageheight * $resizeratio);                 }                 elseif ($taskheight > 0 && $taskwidth == 0)                 {                     $resizeheight = $taskheight;                     $resizeratio = $resizeheight / $this->imageheight;                     $resizewidth = floor($this->imagewidth * $resizeratio);                 }                 elseif ($taskwidth > 0 && $taskheight > 0)                 {                     $resizewidth = $taskwidth;                     $resizeheight = $taskheight;                 }                  $resizeimage = @imagecreatetruecolor($resizewidth, $resizeheight);                  if ($this->extension == "png")                 {                     @imagesavealpha($resizeimage, true);                     @imagefill($resizeimage, 0, 0, @imagecolorallocatealpha($resizeimage, 0, 0, 0, 127));                 }                  @imagecopyresampled($resizeimage, $im, 0, 0, 0, 0, $resizewidth, $resizeheight, $this->imagewidth, $this->imageheight);                 @imageinterlace($resizeimage, true);                  switch ($this->extension)                 {                     case 'png':                         @imagepng($resizeimage, $savepath);                         break;                      default:                         @imagejpeg($resizeimage, $savepath, $quality);                         break;                 }                  @imagedestroy($resizeimage);             }             elseif ($task == "scale")             {                 if ($taskwidth == 0)                 {                     $taskwidth = 100;                 }                  if ($taskheight == 0)                 {                     $taskheight = 100;                 }                  $scalewidth = $this->imagewidth * ($taskwidth / 100);                 $scaleheight = $this->imageheight * ($taskheight / 100);                 $scaleimage = @imagecreatetruecolor($scalewidth, $scaleheight);                  if ($this->extension == "png")                 {                     @imagesavealpha($scaleimage, true);                     @imagefill($scaleimage, 0, 0, imagecolorallocatealpha($scaleimage, 0, 0, 0, 127));                 }                  @imagecopyresampled($scaleimage, $im, 0, 0, 0, 0, $scalewidth, $scaleheight, $this->imagewidth, $this->imageheight);                 @imageinterlace($scaleimage, true);                  switch ($this->extension)                 {                     case 'png':                         @imagepng($scaleimage, $savepath);                         break;                      default:                         @imagejpeg($scaleimage, $savepath, $quality);                         break;                 }                  @imagedestroy($scaleimage);             }         }     } } 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -