Jump to content

Search the Community

Showing results for tags 'resize'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 11 results

  1. Good Morning, Freaks, I hope you're all well. I've a question - I've been researching coding image resize functionality. While looking into the functions I'd need to do this I came across very similar code used in examples from 3 different sources so decided this was good code to learn from. So I tweeked it a bit and put it into a class method -> public function imageResize($target, $newcopy, $w, $h, $ext) { list($orig_w, $orig_h) = getimagesize($target); $scale_ratio = $orig_w/$orig_h; if(($w / $h) > $scale_ratio) { $w = $h * $scale_ratio; } else { $h = $w / $scale_ratio; } $img = ""; if($ext == "gif" || $ext == "GIF") { $img = imagecreatefromgif($target); } else if($ext == "png" || $ext == "PNG") { $img = imagecreatefrompng($target); } else if($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG") { $img = imagecreatefromjpeg($target); } $create_tci = imagecreatetruecolor($w, $h); imagecopyresampled($create_tci, $img, 0, 0, 0, 0, $w, $h, $orig_w, $orig_h); imagejpeg($create_tci, $newcopy, 80); } and then connected it to a button -> <?php require("assets/initializations.php"); if(isset($_POST['upload_image'])) { $image_obj = new Image($conn, $user); $image_obj->imageUpload(); } else if(isset($_POST['resize_image'])) { mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $image_obj = new Image($conn, $user); $kaboom = explode(".", $image_name); //object params $image_ext = $kaboom[-1]; $target_image = "/opt/lampp/htdocs/site/admin/img/$image_name"; $resized_image = "/opt/lampp/htdocs/site/admin/img/resized_$image_name"; $max_w = 150; $max_h = 150; $image_obj->imageResize($target_image, $resized_image, $max_w, $max_h, $image_ext); //header("Location: add_photo.php"); } ?> Setup: A preview button chooses the image, a preview which is displayed underneath it (using js). There's also an upload button to bring it into the sites file system. This functionality works fine. I've just added the resize button beside the preview button and connected the object method to it. Intended Result: The resize button resizes the previewed image and the resized image is now previewed instead of the original image. Result: Nothing. The button stays in the active state, but nothing happens. I get no warning nor error messages and absolutely nothing in dev tools to work from. Not sure what my next step would be outside asking more experienced coders Any advise or guidance on getting this resolved would be met with appreciation. TIA
  2. I am trying out a new script that lets me resize an image before uploading. It is based on this script. http://www.w3bees.com/2013/03/resize-image-while-upload-using-php.html Basically what happens is, it resizes and makes 3 thumbnails and puts them in their relative folder. That works. The part that's giving me the problem is when inserting it into the database. Error says the "image_path" cannot be null. Since it's creating an array of 3 different thumbnails, should I create 2 more fields in the database tabel to account for that? If so, how would I insert the 3 different thumbnail paths into the query? What would it look like? Below is my code. <?php $db_userid = intval($row['user_id']); $get_item_id = intval($row['item_id']); // settings $max_file_size = 5242880; // 5mb $valid_exts = array('jpeg', 'jpg', 'png', 'gif'); // thumbnail sizes $sizes = array(100 => 100, 150 => 150, 250 => 250); // dir paths $target_dir = 'images/'.$db_userid.'/items/'.$get_item_id.'/'; if ($_SERVER['REQUEST_METHOD'] == 'POST' AND isset($_FILES['image'])) { if(!empty($_FILES['image']['name'])) { if($_FILES['image']['size'] < $max_file_size ){ // get file extension $ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)); if(in_array($ext, $valid_exts)) { function resize($width, $height){ global $db_userid; global $get_item_id; /* Get original image x y*/ list($w, $h) = getimagesize($_FILES['image']['tmp_name']); /* calculate new image size with ratio */ $ratio = max($width/$w, $height/$h); $h = ceil($height / $ratio); $x = ($w - $width / $ratio) / 2; $w = ceil($width / $ratio); /* new file name */ $path = 'images/'.$db_userid.'/items/'.$get_item_id.'/'.$width.'x'.$height.'_'.$_FILES['image']['name']; /* read binary data from image file */ $imgString = file_get_contents($_FILES['image']['tmp_name']); /* create image from string */ $image = imagecreatefromstring($imgString); $tmp = imagecreatetruecolor($width, $height); imagecopyresampled($tmp, $image, 0, 0, $x, 0, $width, $height, $w, $h); /* Save image */ switch ($_FILES['image']['type']) { case 'image/jpeg': imagejpeg($tmp, $path, 100); break; case 'image/png': imagepng($tmp, $path, 0); break; case 'image/gif': imagegif($tmp, $path); break; default: exit; break; } return $path; /* cleanup memory */ imagedestroy($image); imagedestroy($tmp); } /* resize image */ foreach($sizes as $w => $h) { if(!is_dir($target_dir)){ mkdir($target_dir, 0775, true); } $files[] = resize($w, $h); } $insert_image = $db->prepare("INSERT INTO images(user_id, item_id, image_path, date_added) VALUES(:user_id, :item_id, :image_path, :date_added)"); $insert_image->bindParam(':user_id', $db_userid); $insert_image->bindParam(':item_id', $get_item_id); $insert_image->bindParam(':image_path', $path); $insert_image->bindParam(':date_added', $item_date_added); if(!$insert_image->execute()) { $errors[] = 'There was a problem uploading the image!'; } else { if(empty($errors)) { $db->commit(); $success = 'Your item has been saved.'; } else { $db->rollBack(); } } } else { $errors[] = 'Unsupported file'; } } else{ $errors[] = 'Please upload image smaller than 5mb'; } } else { $errors[] = 'An image is required!'; } }
  3. Hey everyone! I have a question about handling video files. Are there classes available for handling videos? I've found classes to handle images and I was wondering if there is something similar for videos. I'm asking because I want to allow users to upload videos, but I want to reduce their resolution (take up less space). The video is intended to play in a small section on the page, so it doesn't require high resolution. I'll appreciate any help. Thanks!
  4. Hi everyone, here is a thing that I need help with. Firstly I am not good in php programming - have some understanding of it. First: why? I am starting up a site that sells editorial content (images) to different newspapers, magazines and so on. The website will show the images and let the customer choose licens and size of image (large, medium, small) since there are big difference between prices, depending on the size of the image, I need the function to on-demand resize the image after customers choice. So far so good - the site I have works and if I fiddle around with pricegroup and size it does the job of resizing - but and this is a big but, when it resizes the image it also deletes all information in exif, metadata colorprofile and resolution. So the customer gets a image that he cannot print or use at all. The developer of the shoppingcart will not alter the file to solve this issue (atleast not yet) but I am free to do this myself as I see fit. So to clarify: I need to modify the code below to preserve all information (exif, colorprofile, copyright, metadata). Either by using wordpress GD library (it does use that now) or switch it for better usage with imagick. But the original file must be left unaltered so a new copy with the new size is created upon checkout and then made available for download after purchase. Code that does the resizing: public function create_download_size( $size, $location=null ){ $image_p = imagecreatetruecolor( $size['width'], $size['height'] ); $image = imagecreatefromjpeg( $location ); list( $current_image['width'], $current_image['height'] ) = getimagesize( $location ); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $size['width'], $size['height'], $current_image['width'], $current_image['height']); $destination_file = $this->tmp_dir . basename( $location ); if ( ! file_exists( $destination_file ) ){ wp_mkdir_p( dirname( $destination_file ) ); } From what I have been told the function "imagecopyresampled" make a copy of the original and it is then all information is deleted. Can I extract the exif and then rewrite it back to the new resized copy of the image? or rewrite this code to use imagick instead, imagick should preserve exif (do not know but been told so) So do anyone want to give it a try and solve this? I have according to my webhost imagick installed at "exec('/usr/bin/convert') I hope that this is something that can be solved. Regards, mxfarsa..
  5. i want to store youtube thumbnnail in my folder with resize option. http://img.youtube.com/vi/BoVBdxftEF8/0.jpg this is the image thumbnail file_put_contents ("video_thumbnails/thumb.jpg",file_get_contents("http://img.youtube.com/vi/BoVBdxftEF8/0.jpg")); but it shows errors!!!
  6. i have this code which will resize the uploaded image to its max level. all i want is to transfer my images into a folder if i will use this format move_uploaded_file($_FILES['image']['tmp_name'],'uploads/'. $_FILES['image']['name']); only one image will be place on the folder and its the original image. move_uploaded_file($_FILES['image']['tmp_name'],$_FILES['image']['name']); if i will used this code all resize images will be displayed but not in the folder which i want the image to be place upload_image.php
  7. So i have a website, here i have a backoffice. In the backoffice i can add new "places" and when i add a new place i want to be able to upload 1 picture of it. All good till now. So i have a from, and i want the image i upload do be resized to 800x600, and to create a thumbnail of 200px x 200px. So can someone help me? What is the best way to do this? Just store the path of the 800x600 image on the db and save the thumbnail with the same name of the 800x600 image but with thum in the front? Or save both paths in the db? Because the main goal is to show the place in the frontpage, like this: The thumb with the name of the place, and when i click on the thumb, i will get the 800x600 image with a lightbox. Can someone help me please?
  8. I found a script that resizes all images in a given directory to a new size. I need some guidance to modify this script to my needs. The script resizes images to a specified image width and height. I would like to change that to make it scale the image to half the original size if it is above a certain size. I would also like for it to create a new image of a given size of 150px * 150px [icons]. How can I achieve this? <?php //Maximize script execution time ini_set('max_execution_time', 0); //Initial settings, Just specify Source and Destination Image folder. $ImagesDirectory = 'images/gallery/'; //Source Image Directory End with Slash $DestImagesDirectory = 'images/main/'; //Destination Image Directory End with Slash $NewImageWidth = 500; //New Width of Image $NewImageHeight = 500; // New Height of Image $Quality = 80; //Image Quality //Open Source Image directory, loop through each Image and resize it. if($dir = opendir($ImagesDirectory)){ while(($file = readdir($dir))!== false){ $imagePath = $ImagesDirectory.$file; $destPath = $DestImagesDirectory.$file; $checkValidImage = @getimagesize($imagePath); if(file_exists($imagePath) && $checkValidImage) //Continue only if 2 given parameters are true { //Image looks valid, resize. if(resizeImage($imagePath,$destPath,$NewImageWidth,$NewImageHeight,$Quality)) { echo $file.' resize Success!<br />'; /* Now Image is resized, may be save information in database? */ }else{ echo $file.' resize Failed!<br />'; } } } closedir($dir); } //Function that resizes image. function resizeImage($SrcImage,$DestImage, $MaxWidth,$MaxHeight,$Quality) { list($iWidth,$iHeight,$type) = getimagesize($SrcImage); $ImageScale = min($MaxWidth/$iWidth, $MaxHeight/$iHeight); $NewWidth = ceil($ImageScale*$iWidth); $NewHeight = ceil($ImageScale*$iHeight); $NewCanves = imagecreatetruecolor($NewWidth, $NewHeight); switch(strtolower(image_type_to_mime_type($type))) { case 'image/jpeg': case 'image/png': case 'image/gif': $NewImage = imagecreatefromjpeg($SrcImage); break; default: return false; } // Resize Image if(imagecopyresampled($NewCanves, $NewImage,0, 0, 0, 0, $NewWidth, $NewHeight, $iWidth, $iHeight)) { // copy file if(imagejpeg($NewCanves,$DestImage,$Quality)) { imagedestroy($NewCanves); return true; } } } ?>
  9. Hi could you please help me with the functions used to resize a image when users upload profile picture and allows them to resize it by using a transformation scale
  10. Hey all, hoping to get this code solved. I am building an image gallery for a client's website and wanted a way for the client to upload their own images from the back end and shows up on the website page for the pictures. I am using color box as the lightbox feature for the photos and on the webpage thumbnails are displayed in rows. In the backend, I have the upload page and here is my form: <form name="form" action="../uploader.php" method="POST" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="uploaded_file" id="uploaded_file"> <input type="hidden" name="MAX_FILE_SIZE" value="10485760" /><br /> <input type="hidden" name="image_type" value="" /><br /> <input type="submit" name="submit" value="Submit"> <input type="hidden" name="MM_insert" value="form" /> </form> From the admin upload page, the client can upload their image and it will save it into the "image/uploads/" folder. Here is the uploader.php script: <?php //Сheck that we have a file if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { //Check if the file is JPEG image and it's size is less than 1.4MB $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && ($_FILES["uploaded_file"]["size"] < 10485760)) { //Determine the path to which we want to save this file $newname = dirname(__FILE__).'/images/uploads/'.$filename; //Check if the file with the same name is already exists on the server if (!file_exists($newname)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) { echo "Upload Complete! "; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists"; } } else { echo "Error: File too big to upload"; } } else { echo "Error: No file uploaded"; } ?> Now the website page will display all the images in the "images/uploads" folder and will update itself when new photos are uploaded. Here is the gallery code from the website: <div class="gallery"> <?php /* function: returns files from dir */ function get_files($images_dir,$exts = array('jpg')) { $files = array(); if($handle = opendir($images_dir)) { while(false !== ($file = readdir($handle))) { $extension = strtolower(get_file_extension($file)); if($extension && in_array($extension,$exts)) { $files[] = $file; } } closedir($handle); } return $files; } /* function: returns a file's extension */ function get_file_extension($file_name) { return substr(strrchr($file_name,'.'),1); } /** settings **/ $images_dir = 'images/uploads/'; $images_per_row = 5; /** generate photo gallery **/ $image_files = get_files($images_dir); if(count($image_files)) { $index = 0; foreach($image_files as $index=>$file) { $index++; echo '<a href="',$images_dir.$file,'" class="photo-link group1" rel="uploads"><img src="timthumb.php?src=',$images_dir.$file,'&h=150&w=150" /></a>'; if($index % $images_per_row == 0) { echo '<div class="clear"></div>'; } } echo '<div class="clear"></div>'; } else { echo '<p>There are no images in this gallery.</p>'; } ?> </div> With the help from timthumb.php and timthumb-config.php I am able to produce the thumbnails for the website. Once clicked, brings up the colorbox feature for the image slideshow. For some reason, this code only can use image sizes under 1500px. How can I upload a bigger image and resize it to save itself into the "images/uploads/" folder to be under 1500px? Please look at my codes and let me know where and what code I need to produce the resized image. Thanks!
  11. Dear fellow php programmers. Ik have 4 frames in an page and one contains pictures. I managed to get the pictures fullscreen, yet it does not resize when the index page is shown. It looks like this: And the goal is to make the picture fit perfect, so not half the picture, and adjust to its resolution. How can i fix this? Thanks in advance Dave
×
×
  • 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.