The Little Guy Posted December 21, 2006 Share Posted December 21, 2006 This code works correctly when it is all put together, except for the image size, it should resize to 50%, but when I add in my function, it doesn't resize it, but rotating it works. If I remove the function, then resizing does work, so where and how would I insert it?OK... I have this code:[code]<?php// The filesession_start();$img_id = $_GET['image_id'];include"db.php";$img = mysql_query("SELECT * FROM files where file_id='$img_id'")or die(mysql_query());$imgs = mysql_fetch_array($img);$filename = "users/".$_SESSION['user']."/$imgs[file_name]";#$filename = "users/ryan/screen2.jpg";//$filename = 'images/user_images/geoff.jpg';$percent = .5;function getext($file) { $pos = strrpos($file,'.'); $str = substr($file, $pos); return strtolower($str);}// Content typeif(getext($filename)=='.jpg'){ header('Content-type: image/jpeg');}elseif(getext($filename)=='.gif'){ header('Content-type: image/gif');}elseif(getext($filename)=='.png'){ header('Content-type: image/png');}// Get new sizeslist($width, $height) = getimagesize($filename);$newwidth = $width * $percent;$newheight = $height * $percent;// Load$thumb = imagecreatetruecolor($newwidth, $newheight);if(getext($filename)=='.jpg'){ $source = imagecreatefromjpeg($filename); #$source = rotate($filename,$_GET['degrees']); //$thumb = rotate($source,$_GET['degrees']);}elseif(getext($filename)=='.gif'){ $source = imagecreatefromgif($filename);}elseif(getext($filename)=='.png'){ $source = imagecreatefrompng($filename); imageAlphaBlending($source, true); imageSaveAlpha($source, true);}// Resizeimagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);// Outputif(getext($filename)=='.jpg'){ imagejpeg($thumb);}elseif(getext($filename)=='.gif'){ imagegif($thumb);}elseif(getext($filename)=='.png'){ imagepng($thumb);}?>[/code]I want to add this function, so I add it to the top.[code]function rotate($filerotate,$rotationamount){ // File and rotation $filename = $filerotate; $degrees = $rotationamount; // Content type header('Content-type: image/jpeg'); // Load $source = imagecreatefromjpeg($filename); // Rotate $rotate = imagerotate($source, $degrees, 0); // Output return imagejpeg($rotate);}[/code]My question is... Where do I add this:[b]$thumb = rotate($source,$_GET['degrees']);[/b]I don't know if [b]$source[/b] or [b]$thumb[/b] is the correct variable to use, but [b]$_GET['degrees'][/b] is required Link to comment https://forums.phpfreaks.com/topic/31451-inserting-my-funtion-to-rotate-an-image/ Share on other sites More sharing options...
The Little Guy Posted December 21, 2006 Author Share Posted December 21, 2006 anyone? Link to comment https://forums.phpfreaks.com/topic/31451-inserting-my-funtion-to-rotate-an-image/#findComment-146077 Share on other sites More sharing options...
The Little Guy Posted December 22, 2006 Author Share Posted December 22, 2006 Maybe this will help...I would like to combine these two scripts:[code]<?php// File and rotation$filename = 'test.jpg';$degrees = 180;// Content typeheader('Content-type: image/jpeg');// Load$source = imagecreatefromjpeg($filename);// Rotate$rotate = imagerotate($source, $degrees, 0);// Outputimagejpeg($rotate);?>[/code]And this one: [code]<?php// File and new size$filename = 'test.jpg';$percent = 0.5;// Content typeheader('Content-type: image/jpeg');// Get new sizeslist($width, $height) = getimagesize($filename);$newwidth = $width * $percent;$newheight = $height * $percent;// Load$thumb = imagecreatetruecolor($newwidth, $newheight);$source = imagecreatefromjpeg($filename);// Resizeimagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);// Outputimagejpeg($thumb);?>[/code] Link to comment https://forums.phpfreaks.com/topic/31451-inserting-my-funtion-to-rotate-an-image/#findComment-146211 Share on other sites More sharing options...
trq Posted December 22, 2006 Share Posted December 22, 2006 Honestly, I don't understand the question. Do you mean to say you wrote all that code but now don't know weather or not to use $source or $thumb when calling rotate()? Link to comment https://forums.phpfreaks.com/topic/31451-inserting-my-funtion-to-rotate-an-image/#findComment-146212 Share on other sites More sharing options...
The Little Guy Posted December 22, 2006 Author Share Posted December 22, 2006 No... I got them from PHP.net, and I cannot figure out how to combine the two pieces of code above in the previous post. Link to comment https://forums.phpfreaks.com/topic/31451-inserting-my-funtion-to-rotate-an-image/#findComment-146214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.