Jump to content

Error generated with imagecreatefromjpeg() function


madhukar_garg

Recommended Posts

Hi Billy,

 

Thanks for your reply, here is my code for resize.php

 

<?php

//stop direct access

defined( '_VALID_MOS' ) or die( 'Restricted access.' );

//IMAGE RESIZE FUNCTION FOLLOW ABOVE DIRECTIONS

function makeimage($filelocation,$filename,$newfilename,$path,$newwidth,$newheight) {

 

//SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER . )

$image_type = strstr($filename, '.');

 

//SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION

switch($image_type) {

case '.jpg':

$source = imagecreatefromjpeg($filelocation);

break;

case '.jpeg':

$source = imagecreatefromjpeg($filelocation);

break;

case '.JPG':

$source = imagecreatefromjpeg($filelocation);

break;

case '.JPEG':

$source = imagecreatefromjpeg($filelocation);

break;

case '.png':

$source = imagecreatefrompng($filelocation);

break;

case '.PNG':

$source = imagecreatefrompng($filelocation);

break;

case '.gif':

$source = imagecreatefromgif($filelocation);

break;

case '.GIF':

$source = imagecreatefromgif($filelocation);

break;

default:

echo("Error: Invalid Image Type");

die;

break;

}

 

//CREATES THE NAME OF THE SAVED FILE

$file = $newfilename . strtolower($filename);

 

//CREATES THE PATH TO THE SAVED FILE

$fullpath = $path . $file;

 

//FINDS SIZE OF THE OLD FILE

list($width, $height) = getimagesize($filelocation);

 

//CREATES IMAGE WITH NEW SIZES

$thumb = imagecreatetruecolor($newwidth, $newheight);

 

//RESIZES OLD IMAGE TO NEW SIZES

imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

 

//SAVES IMAGE AND SETS QUALITY || NUMERICAL VALUE = QUALITY ON SCALE OF 1-100

imagejpeg($thumb, $fullpath, 85);

 

//CREATING FILENAME TO WRITE TO DATABSE

$filepath = $fullpath;

 

//RETURNS FULL FILEPATH OF IMAGE ENDS FUNCTION

return $filepath;

 

}

 

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.