Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imagecreatefromjpeg not working

Tags:

php

image

jpeg

Hello i have little problem with image showing after making it object. I'm still learning to use object images. So here is my code:

    $what = getimagesize($file);
switch(strtolower($what['mime'])){
    case 'image/png' : $src_id = imagecreatefrompng($file); imagesavealpha($src_id,true) ; break;
    case 'image/jpeg': $src_id = imagecreatefromjpeg($file); break;
    case 'image/gif' : $old_id = imagecreatefromgif($file); $src_id = imagecreatetruecolor($what[0],$what[1]); imagecopy($src_id,$old_id,0,0,0,0,$what[0],$what[1]); break; 
    default: die();
}
header('Content-Type: image/jpeg');
imagejpeg($scr_id);
imagedestroy($scr_id);
die();

The browser outputs blank image with text "Image". On $file i give the file URL. Any ideas ?

like image 762
Andrey Avatar asked Dec 22 '12 13:12

Andrey


1 Answers

This tested out correctly for me.

<?php // RAY_temp_andrey.php
error_reporting(E_ALL);

$file = 'http://laprbass.com/RAY_EE_images/headshot.png';
$file = 'http://laprbass.com/RAY_EE_images/headshot.jpg';
$file = 'http://laprbass.com/RAY_EE_images/headshot.gif';

$what = getimagesize($file);

switch(strtolower($what['mime']))
{
    case 'image/png':
        $img = imagecreatefrompng($file);
        break;
    case 'image/jpeg':
        $img = imagecreatefromjpeg($file);
        break;
    case 'image/gif':
        $img = imagecreatefromgif($file);
        break;
    default: die();
}
$new = imagecreatetruecolor($what[0],$what[1]);
imagecopy($new,$img,0,0,0,0,$what[0],$what[1]);

header('Content-Type: image/jpeg');
imagejpeg($new);
imagedestroy($new);
like image 78
Ray Paseur Avatar answered Oct 01 '22 12:10

Ray Paseur