jordz Posted May 26, 2010 Share Posted May 26, 2010 Hey all, I've been having an issue with using two scripts, one is an image manipulation class that does some watermarking for me and has a variety of different functions. Once I've processed the image from that class It comes out in a raw format (requiring a header()). I built another script to add 25 pixels to the bottom off the image but for the life of me can't seem to take the image from the raw format and manipulate it. Does anyone know how I could take the raw image and do something like imagecreatefromjpeg() to it? here's my code: include('class.upload.php'); //get the uploader class header('Content-Type: image/jpeg'); //image header $filename = 'test.jpg'; //source image file $handle = new upload($filename); if ($handle->uploaded) { // process the image $handle->file_new_name_body = 'image_resized'; $handle->image_watermark = 'wm2.png'; $handle->image_watermark_position = 'RM'; //outputs the image as raw format. $handle->process(); } // I can't do $image = $handle->process() then feed it through... // My script starts here and $image should be what comes out of the $handle... //*********** This is where I'm stuck, any help?********** $source = imagecreatefromjpeg($image); list($width, $height) = getimagesize($image); $thumb = imagecreatetruecolor($width, $height+25); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $width, $height); Any help would be much appreciated thanks. Jordan Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/ Share on other sites More sharing options...
The Eagle Posted May 26, 2010 Share Posted May 26, 2010 This is just some of what I remember, $img_number = imagecreate(275,25); And then where I see, imagefill($img_number,0,0,$backcolor); Then displayed, imagejpeg($img_number); Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/#findComment-1063747 Share on other sites More sharing options...
jordz Posted May 26, 2010 Author Share Posted May 26, 2010 I'm sorry I don't understand what you're getting at? I need to take the $handle->process() (this is now raw code) and some how put it into my script below.... Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/#findComment-1063749 Share on other sites More sharing options...
The Eagle Posted May 26, 2010 Share Posted May 26, 2010 You asked how can you take a raw image and do imagecreatefromjpeg() to it? Well, what I posted are bits of virtually what imagecreatefromjpeg() can do. If you'd like a better imagecreatefromjpeg() example then read below, <?php function LoadJpeg($imgname) { /* Attempt to open */ $im = @imagecreatefromjpeg($imgname); /* See if it failed */ if(!$im) { /* Create a black image */ $im = imagecreatetruecolor(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an error message */ imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } header('Content-Type: image/jpeg'); $img = LoadJpeg('bogus.image'); imagejpeg($img); imagedestroy($img); ?> Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/#findComment-1063753 Share on other sites More sharing options...
jordz Posted May 26, 2010 Author Share Posted May 26, 2010 I'm still failing to see how this works... Sorry If Im a little thick. $handle->process() outputs the image in raw code, how exactly would I go about taking that raw code and manipulating the image again? Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/#findComment-1063769 Share on other sites More sharing options...
mattal999 Posted May 26, 2010 Share Posted May 26, 2010 Basically, you will have to do what I coded yesterday You need to write the data to a temporary file and then use that temporary file on imagecreatefromjpeg. Then, when all is done, delete the temporary file. I use @ to compress errors just because I am using this in a cron script and I output JSON (No idea why, I just do ). Example: <?php $fileName = "button.jpg"; $rawData = "xxx"; // This is where you put $handle->process(); $tempDir = "temp/"; // CHMOD this to 0777. $realDir = "images/"; // CHMOD this to 0777 as well. $fp = @fopen($tempDir.$fileName.".tmp", "wb"); // 'b' is to use binary (Without the 'b' tag, I had loads of corruption issues and I finally figured this out). if($fp) { fwrite($fp, $rawData); fclose($fp); } else { die("Could not open a temporary file (Check directory has CHMOD 0777)"); } if(!$src = @imagecreatefromjpeg($tempDir.$fileName.".tmp")) { die("Could not open the temporary file and create a new jpeg object from it."); } // Carry out operations... imagejpeg($src, $realDir.$fileName, 100); // Save the file to a directory. imagedestroy($src); @unlink($tempDir.$fileName.".tmp"); // Delete the temporary file. ?> Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/#findComment-1063775 Share on other sites More sharing options...
jordz Posted May 26, 2010 Author Share Posted May 26, 2010 Ahhh okay, so is there no way at all to do it without saving to temporary file? edit: Does this delete the temporary file then? Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/#findComment-1063776 Share on other sites More sharing options...
mattal999 Posted May 26, 2010 Share Posted May 26, 2010 Does this delete the temporary file then? Yes; after the processing has been completed the unlink(); command at the end of the script deletes the temporary file. Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/#findComment-1063780 Share on other sites More sharing options...
jordz Posted May 26, 2010 Author Share Posted May 26, 2010 Fixed Solved! Thank you Very Very Much! That's been a problem I've been pondering over for agggeeesss. Jordan Quote Link to comment https://forums.phpfreaks.com/topic/202997-php-image-manipulation-problems/#findComment-1063792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.