Jump to content

[SOLVED] Rotate Multiple Images


bluebyyou

Recommended Posts

I am trying to rotate multiple images at a time using this in my script. One image will be rotated fine, but then I will get the error messages below.

 

		if ($picturerotate > 0)
	{
	//270 = Rotate Right
	//90 = Rotate Left
		if ($picturerotate == 1){ $degrees = 90; }
		else if ($picturerotate == 2){ $degrees = 270; }

		$img_quality = 300;
		$thumb_quality = 75;


		$image = imagecreatefromjpeg("uploads/$picturefile");
		$bg_color = imagecolorallocate($image, 255,255,255);
		$rotated_image = imagerotate($image, $degrees, $bg_color);
		imagejpeg($rotated_image, "uploads/$picturefile", $img_quality);
		imagedestroy($image);
		imagedestroy($rotated_image);\		
	}

Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /home/content/w/i/u/wiuartinny/html/photo_info_action.php on line 57

Warning: imagecreatefromjpeg(): 'uploads/' is not a valid JPEG file in /home/content/w/i/u/wiuartinny/html/photo_info_action.php on line 57

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/content/w/i/u/wiuartinny/html/photo_info_action.php on line 58

Warning: imagerotate(): supplied argument is not a valid Image resource in /home/content/w/i/u/wiuartinny/html/photo_info_action.php on line 59

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/content/w/i/u/wiuartinny/html/photo_info_action.php on line 60

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/content/w/i/u/wiuartinny/html/photo_info_action.php on line 61

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/content/w/i/u/wiuartinny/html/photo_info_action.php on line 62

Warning: Cannot modify header information - headers already sent by (output started at /home/content/w/i/u/wiuartinny/html/photo_info_action.php:57) in /home/content/w/i/u/wiuartinny/html/photo_info_action.php on line 68

 

Is this some sort of memory issue? I cant figure out why it dies after rotating only one.

 

Link to comment
Share on other sites

I don't really know, but two things I saw...

 

Are you sure $picturefile is not empty or invalid?

 

And $img_quality = 300;??? I think that's a little too much... 100 is perfect ... 300 means, you want a picture quality of 300%? Put it lower ;)

Link to comment
Share on other sites

$picturefile is set in an earlier part of the script, I can post the whole thing If that would help it make more sense. About the quality I thought it was resolution not percentage, so i will try it at 100.

 

Here is the whole thing(sorry no comments on it yet):

<?php
session_start();
include("db_connect.php");

if (isset($_SESSION['photo_array']))
{
foreach($_SESSION['photo_array'] as $id) 
{
	$pictureid = $_POST[$id]['pictureid'];
	$pictureyear = $_POST[$id]['year'];
	$picturetitle = $_POST[$id]['title'];
	$picturefile = $_POST[$id]['picturefile'];
	$picturethumb = $_POST[$id]['picturethumb'];
	$picturerotate = $_POST[$id]['rotate'];
	$event = explode(",",$_POST[$id]['event']); //Separate Day and Event

	$picturelocation = $event[0];
	$pictureday = $event[1];	

	//Get Event Date
	$query = "SELECT trip_days FROM `trip` WHERE trip_year = 2007";
	query_db($query);
	$row = mysql_fetch_array($result);
	extract($row);

	$trip_day = explode(",",$trip_days); //Separate trip_days

	$picturedate = $trip_day['$pictureday'];

	if (isset($_POST[$id]['tag']))
	{
		$picturetag = implode(",",$_POST[$id]['tag']);
	}

	$query = "UPDATE pic SET `pictureyear` = '$pictureyear',
							 `pictureday` = '$pictureday',
							 `picturedate` = '$picturedate',
							 `picturelocation` = '$picturelocation',
							 `picturetitle` = '$picturetitle',
							 `picturetag` = '$picturetag'
			  WHERE pictureid = '$pictureid'";
	query_db($query); 



	if ($picturerotate > 0)
	{
	//270 = Rotate Right
	//90 = Rotate Left
		if ($picturerotate == 1){ $degrees = 90; }
		else if ($picturerotate == 2){ $degrees = 270; }

		$img_quality = 300;
		$thumb_quality = 75;


		$image = imagecreatefromjpeg("uploads/$picturefile");
		$bg_color = imagecolorallocate($image, 255,255,255);
		$rotated_image = imagerotate($image, $degrees, $bg_color);
		imagejpeg($rotated_image, "uploads/$picturefile", $img_quality);
		imagedestroy($image);
		imagedestroy($rotated_image);\		
	}
}
} 
unset($_SESSION['photo_array']);
header("location:account.php");

?>


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.