Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

littlejubs

[Resolvido] Problema com Upload(crop) GD

Recommended Posts

Olá,

 

Estou tendo problemas com um crop de imagem no servidor em que eu subi a minha aplicação. Local tudo está funcionando normalmente, já ví o phpinfo() dos dois e estão praticamente iguais, porém quando subi ao fazer o upload da imagem recebo o seguinte erro:

 

 

error : No JPEG create support.

e
Dentro da Classe que estou usando encontei :

 

$this->translation['file_create'] = 'No %s create support.';


case 'jpg':
if (!$return_mode) {
$result = @imagejpeg($image_dst, $this->file_dst_pathname, $this->jpeg_quality);
} else {
ob_start();
$result = @imagejpeg($image_dst, null, $this->jpeg_quality);
$return_content = ob_get_contents();
ob_end_clean();
}
if (!$result) {
$this->processed = false;
$this->error = $this->translate('file_create', array('JPEG'));
} else {
$this->log .= '    JPEG image created<br />';
}
break;

 

 

Estou usando esta classe de upload:

 

http://www.phpclasses.org/browse/file/8831.html

e esta função para o crop:

 protected function resizeImagejCrop( array $fileArray, $prefix = null, array $coords, $widthInBrowser, array $finalSize, array $oldSize, $outputFile = "file", $delete_original = true )
      {
         # Setting defaults and meta
         list( $path, $filename ) = $fileArray;
         list( $x, $y ) = $coords;
         list( $width_old, $height_old ) = $oldSize;
         list( $final_width, $final_height ) = $finalSize;

         $file = implode( "", $fileArray );
         $info = getimagesize( $file );
         $image = "";
         $output = $path . $prefix . $filename;

         require_once "class.upload.php";

         $handle = new upload( $path . $filename );
         $handle->image_resize = true;
         $handle->image_x = $widthInBrowser[ 1 ];
         $handle->image_y = $widthInBrowser[ 3 ];
         $handle->file_overwrite = true;
         $handle->Process( $path );

         if( !is_null( $output ) && is_file( $output ) )
         {
            // unlink( $output );
         }

         # Loading image to memory according to type
         switch( $info[ 2 ] )
         {
            case IMAGETYPE_GIF: $image = imagecreatefromgif( $file );
               break;
            case IMAGETYPE_JPEG: $image = imagecreatefromjpeg( $file );
               break;
            case IMAGETYPE_PNG: $image = imagecreatefrompng( $file );
               break;
            default: return false;
         }

         $trnprt_indx = imagecolortransparent( $image );
         $trnprt_color = array( "red" => 255, "green" => 255, "blue" => 255 );

         # This is the resizing/resampling/transparency-preserving magic
         $image_resized = imagecreatetruecolor( $final_width, $final_height );

         if( ( $info[ 2 ] == IMAGETYPE_GIF ) || ( $info[ 2 ] == IMAGETYPE_PNG ) )
         {
            $transparency = imagecolortransparent( $image );

            if( $transparency >= 0 )
            {
               $transparent_color = imagecolorsforindex( $image, $trnprt_indx );
               $transparency = imagecolorallocate( $image_resized, $trnprt_color[ "red" ], $trnprt_color[ "green" ], $trnprt_color[ "blue" ] );
               imagefill( $image_resized, 0, 0, $transparency );
               imagecolortransparent( $image_resized, $transparency );
            }
            elseif( $info[ 2 ] == IMAGETYPE_PNG )
            {
               imagealphablending( $image_resized, false );
               $color = imagecolorallocatealpha( $image_resized, 0, 0, 0, 127 );
               imagefill( $image_resized, 0, 0, $color );
               imagesavealpha( $image_resized, true );
            }
         }

         imagecopyresampled( $image_resized, $image, 0, 0, $x, $y, $final_width, $final_height, $width_old, $height_old );

         # Preparing a method of providing result
         switch( strtolower( $outputFile ) )
         {
            case "browser":
               $mime = image_type_to_mime_type( $info[ 2 ] );
               header( "Content-type: $mime" );
               $output = NULL;
               break;
            case "file":
               break;
            case "return":
               return $image_resized;
               break;
            default:
               break;
         }

         # Writing image according to type to the output destination
         switch( $info[ 2 ] )
         {
            case IMAGETYPE_GIF: imagegif( $image_resized, $output, 95 );
               break;
            case IMAGETYPE_JPEG: imagejpeg( $image_resized, $output, 95 );
               break;
            case IMAGETYPE_PNG: imagepng( $image_resized, $output, 95 );
               break;
            default: return false;
         }

         # Taking care of original, if needed
         if( $delete_original )
         {
            // unlink( $file );
         }

         return true;
      }

Compartilhar este post


Link para o post
Compartilhar em outros sites

Então...

 

Você pode usar o wideImage: http://wideimage.sourceforge.net/

 

Minha vida melhorou consideravelmente, depois que comecei usar esta library para upload de imagens.

 

E como nosso amigo já citou, pode ser permissionamento de pasta; verifique também o caminho de destino das imagens, pois comigo já deu problema desenvolvendo em ambiente windows e não funcionar após subir para o servidor "Linux".

 

Abraço!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Por hora, obrigada pela ajuda à todos, vou tentar com esse wideImage.
Sobre permissões de pasta eu já tinha tentado isso e não deu certo, a classe de upload tá sendo usada em outro módulo do zend no mesmo projeto e funcionando corretamente no servidor, talvez seja um erro ~bobo~ que meus olhos não consigam detectar :(

Ainda aceito idéias sobre o que fazer..se eu conseguir resolver eu coloco qual era o problema e marco como resolvido.

bjs

Compartilhar este post


Link para o post
Compartilhar em outros sites

Seu script ta meio tenso te lê =X

 

Seu servidor e linux?

 

Parece que a extensão não está instalada.

@imagejpeg //Isto e problemático muita supressão de erro

 

 

tente rodar um simples teste no server. Veja oq rola

 

$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($im);
// Free up memory
imagedestroy($im);

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ja faz um tempo que eu não preciso lidar mais com estes tipos de problemas. O que eu faço é: Eu envio a imagem para um bucket qualquer tipo Amazon S3 e depois uso o ImageBoss (https://imageboss.me/) com estas URLs publicas. Espero ter ajudado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.