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
https://forums.phpfreaks.com/topic/85417-solved-rotate-multiple-images/
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");

?>


Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.