PHP - Rotate 360 - Not Return (?)
How to do that when you turn 360 degrees no longer come back? Only in this way was?
Similar TutorialsHey guy's i have a script i did a few months ago and now noticed that it is doing its job but keeps the old file ..so i got the image a few times but on a different angle...
how can i optimize this code to delete the old image when doing the rotation?
<?php session_start(); include_once 'dbconnect.php'; if (!isset($_SESSION['userSession'])) { header("Location: index.php"); } $degrees = -270; $path = $_GET['Folder']; $file =$_GET['Pic']; $fileid =$_GET['id']; $image = $path.'/'.$file; $imageN = $path.'/New_'.$file; //load the image $source = imagecreatefromjpeg($image); //rotate the image $rotate = imagerotate($source, $degrees, 0); $NewImg='New_'.$file ; //set the Content type //header('Content-type: image/jpeg'); //display the rotated image on the browser //imagejpeg($rotate); imagejpeg($rotate,$imageN,100); //free the memory imagedestroy($source); imagedestroy($rotate); $sql = "UPDATE Coupon_list SET product_image_thumb = '$NewImg' WHERE id = '$fileid'"; if (mysqli_query($DBcon, $sql)) { echo "Rotation ok"; echo('<script language="Javascript">opener.window.location.reload(false); window.close();</script>'); } else { echo "Error Rotating: " . mysqli_error($DBcon); } mysqli_close($DBcon); ?> <img src="gears.gif" alt="" />
Hi, There are 10 images in a folder called "Images". All images are named like 1.jpg, 2.jpg, 3.gif, 4.png, and so on... I am using these images on my website with this link: MyDomain.com/Images/1.jpg Now what i want to do is change the image every minute. from 1... to ...10 all images one by one, every minute... Link should remain same, but it should give different image every time. and if someone copies my link of image, it still gets changed every minute. i hope to get some help, better with some example code... Thanks! Maybe somebody knows a good way to do this... I have a simple query that seasonal categories - plus one special events header. then for each header I pull all the classes in that category. Right now it just pulls and orders by id. So, regardless of year, they come out in the same order: spring, winter, fall, special events. I'm trying to see if there's a way to make them show in order of relevance to the current time. right now, the "cat" table just has two fields: cat_id, cat_name. In other words, in autumn, I want them to order: Autumn, winter, summer, spring - then special events. In summer, I want them to order: Summer, spring, autumn, winter - then special events. any thoughts on how to do this? step one, order by relevence to current date. step two, special events is always last. Code: [Select] $query1 = "select * from tbl_cat ORDER by cat_id"; $result_cats = mysql_query($query1) or die(mysql_error()); while ($row = mysql_fetch_array($result_cats)) { $query_selectall = "select *,workshop_date AS tester from tbl_workshops WHERE category={$row['cat_id']} and active_inactive = '1' ORDER by workshop_date"; $result_all = mysql_query($query_selectall) or die(mysql_error()); $catid = $row['cat_id']; $catname = $row['cat_name']; echo "<font face='georgia' size=5><b>".$catname." </b></font><br><div style='color:#fff;'>"; while ($c_row = mysql_fetch_array($result_all)){ // rest of code pulls items that match that specific category id. } I have the following code, works rotates the image. But it seems to lose its transparency and add color when rotated to say 45. How can I avoid this? // File and rotation $filename = 'placeholder.png'; $degrees = 45; // Content type header('Content-type: image/png'); // Load $source = imagecreatefrompng($filename); // Rotate $rotate = imagerotate($source, $degrees, 0); // Output imagepng($rotate); ?> So whether I am uploading an image through my iphone or sending that image to my computer and uploading it from the computer, it has the same effect. If I upload that image, it'll orient the image in landscape mode. Having said that, I found a function that can fix the orient issue. The problem is I don't know the proper way to integrate it into the image upload script. I have tried several different ways but they all give me errors. Can you show me where exactly I should use this function? // IMAGE ORIENTATION function getOrientedImage($imagePath) { $image = imagecreatefromstring(file_get_contents($imagePath)); $exif = exif_read_data($imagePath); if(!empty($exif['Orientation'])) { switch($exif['Orientation']) { case 8: $image = imagerotate($image,90,0); swapHW(); break; case 3: $image = imagerotate($image,180,0); break; case 6: $image = imagerotate($image,-90,0); swapHW(); break; } } return $image; } // IMAGE UPLOAD SCRIPT if(isset($_FILES['fileToUpload']) AND !empty($_FILES['fileToUpload']["name"])) { if(is_uploaded_file($_FILES['fileToUpload']["tmp_name"])) { $target_dir = '../members/images/'.$global_user_id.'/projects/'.$url_project_id.'/'; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); $source_file = $_FILES["fileToUpload"]["tmp_name"]; $random_name = generateRandomString(10); $new_image = $random_name . '.' . $imageFileType; $resized_image = compressImage($source_file, $new_image, 50); $new_file_path = $target_dir . $resized_image; if(!is_dir($target_dir)){ mkdir($target_dir, 0775, true); } $uploadOk = 1; // Check if image file is a actual image or fake image $check = getimagesize($source_file); if($check !== false) { // echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { $errors[] = 'File is not an image!'; $uploadOk = 0; } // Check if file already exists if (file_exists($target_file)) { $errors[] = 'Sorry, file already exists!'; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 5000000) { $errors[] = 'Sorry, your file size is bigger than 5mb!'; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG" && $imageFileType != "GIF") { $errors[] = 'Sorry, only JPG, JPEG, PNG & GIF files are allowed!'; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if($uploadOk == 0) { $errors[] = 'Sorry, your file was not uploaded!'; // if everything is ok, try to upload file } else { if(rename($new_image, $new_file_path)) { echo 'success'; } else { $errors[] = 'Sorry, there was an error uploading your file!'; } } } else { $errors[] = 'You must upload an image!'; } } Edited December 23, 2019 by imgrooot Hi, I want to create a function that reads the exif orientation data of an image and rotates it as required - needs to run before before the resize function here, I'm using GD library if that is relevant: function resize_gd($sourceFileName, $folder, $destinationFileName, $newWidth, $newHeight, $keepProportion) { $newWidth = (int)$newWidth; $newHeight = (int)$newHeight; if (!$this->gdInfo >= 1 || !$this->checkGdFileType($sourceFileName)) { return false; } $img = &$this->getImg($sourceFileName); if ($this->hasError()) { return false; } $srcWidth = ImageSX($img); $srcHeight = ImageSY($img); if ( $keepProportion && ($newWidth != 0 && $srcWidth<$newWidth) && ($newHeight!=0 && $srcHeight<$newHeight) ) { if ($sourceFileName != $folder . $destinationFileName) { @copy($sourceFileName, $folder . $destinationFileName); } return true; } if ($keepProportion == true) { if ($newWidth != 0 && $newHeight != 0) { $ratioWidth = $srcWidth/$newWidth; $ratioHeight = $srcHeight/$newHeight; if ($ratioWidth < $ratioHeight) { $destWidth = $srcWidth/$ratioHeight; $destHeight = $newHeight; } else { $destWidth = $newWidth; $destHeight = $srcHeight/$ratioWidth; } } else { if ($newWidth != 0) { $ratioWidth = $srcWidth/$newWidth; $destWidth = $newWidth; $destHeight = $srcHeight/$ratioWidth; } else if ($newHeight != 0) { $ratioHeight = $srcHeight/$newHeight; $destHeight = $newHeight; $destWidth = $srcWidth/$ratioHeight; } else { $destWidth = $srcWidth; $destHeight = $srcHeight; } } } else { $destWidth = $newWidth; $destHeight = $newHeight; } $destWidth = round($destWidth); $destHeight = round($destHeight); if ($destWidth < 1) $destWidth = 1; if ($destHeight < 1) $destHeight = 1; $destImage = &$this->getImageCreate($destWidth, $destHeight);Edited June 7, 2019 by mcfc4heatons Is there a way to use php to incorporate a folder of pictures as a clickable slideshow. For instance.... using a pic as a button... to go to the next pic.... except in quantities of 100... without having to manually write the code for each page...? In HTML: Code: [Select] <a href="index3.html"><img src="2.jpg" /></a> <a href="index4.html"><img src="3.jpg" /></a> <a href="index5.html"><img src="4.jpg" /></a> <a href="index6.html"><img src="5.jpg" /></a> <a href="index7.html"><img src="6.jpg" /></a> <a href="index8.html"><img src="7.jpg" /></a> <a href="index9.html"><img src="8.jpg" /></a> Something like using a basic rotating script activated on mouse click? How do i convert this into a button without making 100 pages? Code: [Select] <img src="/path/to/images/ rotate.php?img=my_static_image.jpg" /> I have come up with the rotate.php file as following: Code: [Select] <?php $folder = '/oprah/is/sofuckingfat.com/images/'; $extList = array(); $extList['gif'] = 'image/gif'; $extList['jpg'] = 'image/jpeg'; $extList['jpeg'] = 'image/jpeg'; $extList['png'] = 'image/png'; /* I believe that most of the following can be omitted once it hits the timer / countdown script */ $img = null; if (substr($folder,-1) != '/') { $folder = $folder.'/'; } if (isset($_GET['img'])) { $imageInfo = pathinfo($_GET['img']); if ( isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) && file_exists( $folder.$imageInfo['basename'] ) ) { $img = $folder.$imageInfo['basename']; } } else { $fileList = array(); $handle = opendir($folder); while ( false !== ( $file = readdir($handle) ) ) { $file_info = pathinfo($file); if ( isset( $extList[ strtolower( $file_info['extension'] ) ] ) ) { $fileList[] = $file; } } closedir($handle); if (count($fileList) > 0) { $imageNumber = time() % count($fileList); $img = $folder.$fileList[$imageNumber]; } } if ($img!=null) { $imageInfo = pathinfo($img); $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ]; header ($contentType); readfile($img); } else { if ( function_exists('imagecreate') ) { header ("Content-type: image/png"); $im = @imagecreate (100, 100) or die ("Cannot initialize new GD image stream"); $background_color = imagecolorallocate ($im, 255, 255, 255); $text_color = imagecolorallocate ($im, 0,0,0); imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color); imagepng ($im); imagedestroy($im); } } ?> Would be more or less converting the rotate.php script into the base for the link structure. I assume the timing element in this script would be omitted with a replacement or nothing. I can't figure out what will be the quickest way to go about making the href follow the folder contents. I just want a basic click on the pic to go to the next one until it ends. Thoughts anyone? Hi Everyone,
My name is Raoul Grosser, live in The Netherlands.
I'm a front/backend developer working with AngularJS and Bootstrap and Symphone2.
I've been writing PHP code for over 4 years now my focus is on opensource projects.
If you have any question, please let me know!
Hey all. My site has a config database table that has a column showlogin to set whether or not login functionality is enabled. I'm playing around with MySQLi, Classes, and Returns. My return is always 1. Where am I going wrong? test.php <?php // Start Session session_start(); // Production Settings ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ALL); include 'db.php'; $mysqli = new mysqli($host, $user, $pass, $db); class styles { function showlogin($show) { global $mysqli; $select = $mysqli->query("SELECT showlogin FROM config LIMIT 1"); $value = $select->fetch_object(); if ($value->showlogin = 1) { return 1; } return 0; } } $login = new styles(); echo $login->showlogin($show); ?> If a user is on Page X, but not logged in, when they log in to my website, I want them to return back to Page X (in this example). To handle this, I am adding this code to the top of each webpage... Code: [Select] // Set current Script Name. $_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME']; And then as part of my Log In script I have... Code: [Select] // Redirect User. if (isset($_SESSION['returnToPage'])){ header("Location: " . BASE_URL . $_SESSION['returnToPage']); }else{ // Take user to Home Page. header("Location: " . BASE_URL . "index.php"); } What do you think about this approach? Thanks, Debbie return (int) $value VS return $value
What is the purpose of using int in a bracket? return (int) $value
Which is the best and safest method?
Thank you
Hello First of all i am very weak about OOP and classes in php. I am learning now but i stuck with very silly problem. My codes are below. <?php class myTestClass { function __construct() { $this->OldName("This is Old Name"); } function OldName($VeryOld) { if($VeryOld == "This is Old Name") $this->NewName(); else $VeryOld = "Something Wrong"; return $VeryOld; } function NewName() { echo "This is Brand New Name"; } } $i = new myTestClass(); ?> if i send value to OldName "This is Old Name" then codes works fine. But if i send "This is Old Nameeee" then does not appear anything. what i want to do is print "Something Wrong" text if i enter different value. I have no idea what return do and how it do? How to retrieve/print "Something Wrong"? i can do that with echo but i want to transfer result of return to another function. Really appreciate for any help/idea. Hi all, I am kinda stuck on the return() statement in the php.net manual about control structures. (http://au.php.net/manual/en/function.return.php) All I see is notes on when not to use it and some scary examples with loads of foo and bar but, it's hard to find out when it would be nice to use it. At the moment i am thinking its another way of echo, but I bet that's wrong. If someone could enlighten me a bit on when return() is useful I would be very happy since i see it more often everyday. CHeers! Hi all, can you give me suggestion how to return value from function like this Code: [Select] function returnArray(){ for($i=1; $i<=3; $i++){ return $i; //how to return this as array?? } } when I code "echo" inside the function then call the function it give me output => 123 but when I code "return" inside the function, it will give output => 1 Can you suggest me how to output it as array? I am trying make my code display different things depending on how many rows are returned This is my code Code: [Select] <?PHP include 'db_con.php'; $month = date("n"); $day = date("j"); $sql = mysql_query("SELECT * FROM table WHERE month = $month AND day = $day ")or die(mysql_error()); while($row = mysql_fetch_array($sql) ) if (mysql_fetch_array($row = 1 ) ) ///THIS IS AN ERROR BUT IF ONE ROW RETURNED THEN THIS { echo "ONE THING"; } elseif (mysql_fetch_array($row >1 ) )////IF > 1 ROW RETURNED THAN THIS { echo"TWO THINGS"; } else { echo "SOMETHING ELSE "; } ?> I have tried several variations of the above code but cannot get it to work. Thanks for any help anyone can give me. Hi, I have setup my paypal payment method for a shopping cart on my site, all is well but in order for my server to flag an invoice as paid, the user must return to my website after paying and the query string in the url give the script the go ahead to mark it as paid which in turn alerts the appropriate department that its ok to source the order. ~The problem is, if the user for whatever reason skip the redirect back to my site, the invoice is remain 'unpaid' and has to be changed manually when the payment has been checked in the account. As you might imagine this is a bit of a problem because not only can it cause quite a delay, it also requires manually changing values which can lead to other problems. So if there is a better way i would appreciate the info, thanks a lot. Hello again. I use echo "Rating:".$json['Rating]."/10"; and get in return: 7.5/10 - it's ok. But I want to replace 7.5 with 75.png (image), 6.3 with 63.png, 9.4 with 94.png... hope u understand. Know someone how I can do this? Thanks. I have a form page (referred to as form.php) which is then processed via a submit button, the script then processes the data from the form.php and if it discovers an error it then sets a variable containing the error message my process page contains Code: [Select] if (empty($b_addr)) { $b_addr_error = "Address is required"; $check_failed = TRUE;} header("Location: form.php"); then my form.php contains Code: [Select] $b_addr_error = safe($_GET['b_addr_error']); if (isset($_POST['$b_addr_error'])) { echo "<div class='errorfont' align='center'>'".$b_addr_error."';</div>"; } but the variables do not get passed back to form.php from the process page, any ideas? Thank you. Script:
<?php class Article{ public function fetch_all(){ global $pdo; $query = $pdo->prepare("SELECT * FROM `articles` ORDER BY `article_timestamp` DESC"); $query->execute(); return $query->fetchAll(); } public function fetch_data($article_id){ global $pdo; $query = $pdo->prepare("SELECT * FROM `articles` WHERE `article_id` = ?"); $query->bindValue(1, $article_id); $query->execute(); return $query->fetch(); } /* * These have gotten added later on. */ public function delete($id){ global $pdo; $query = $pdo->prepare("DELETE FROM `articles` WHERE `article_id` = ?"); $query->bindValue(1, $id); $query->execute(); // The "return" here. } public function edit_page($title, $content, $aticle_id){ global $pdo; $query = $pdo->prepare("UPDATE `articles` SET `article_title` = ?, `article_content` = ? WHERE `article_id` = ?"); $query->bindValue(1, $title); $query->bindValue(2, $content); $query->bindValue(3, $article_id); $query->execute(); // The "return" here. } } ?>I have this from a tutorial. In the function "fetch_all()" it uses "fetchAll()" at the spot where the "return" is, and in the function "fetch_data()" it uses "fetch()" at the spot where the "return" is. My Question: What may have to use for the function "delete()" and the function "edit_page()" at the spot where "return" would be? Edited by glassfish, 29 October 2014 - 12:32 PM. |