how do rename an image file and then upload with resize image see below my php code
move_uploaded_file($_FILES["img"]["tmp_name"], "bannerimg/" . $image);
$image = new SimpleImage();
$image->load("bannerimg/" . $_FILES["img"]["name"]);
$image->resize(520,310);
$image->save("bannerimg/thumbs/" . $_FILES["img"]["name"]);
I think it's simple? This one does exactly what you want: PHP rename()
rename($_FILES["img"]["name"], "new_name.jpg");
And here you go, then you may do whatever you want. :)
Related
I'm trying to convert a user-uploaded PDF file to .jpg, to create some sort of thumbnail. I want the thumbnail to be displayed on the same page once they upload their PDF.
I'm using Imagick.
Here's some of my code:
$filePath = $_FILES['file']['tmp_name'];
$fileName = $_FILES['file']['name'];
$pdfThumb = new Imagick();
$pdfThumb->setResolution(300,300);
$pdfThumb->readImage($filePath . '[0]');
$pdfThumb->setImageFormat('jpeg');
$fp = $fileName . '.jpg';
$pdfThumb->writeImage($fp);
I don't feel like anything is really happening, and I want to make sure it saves the thumbnail to my server (possibly temporarily) and show it on a div. Any tips would be much appreciated!
I want to save an image in particular folder. here i am using image bytes string to upload. i am using "imagecreatefromstring($bytesarray)" for this. and "imagejpeg()" which is given me a jpeg image which i passed in imagecreatefromstring() function.
here i am using file_put_contents() for uploading an image. but the image still not save in folder.
Here below is my code.
$imgdata = base64_decode($fl_data[$i]['Archivo']);
$im = imagecreatefromstring($imgdata);
header('Content-Type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
$filemainpath = base_url().'uploads/apifiles/'.$filename.".".$extension;
file_put_contents($filemainpath, $im);
give the folder permission to 777 and use absolute path instead of base_url()
$filemainpath = __dir__.'../uploads/apifiles/'.$filename.".".$extension;
You can also use DOCUMENT_ROOT:
$filemainpath = $_SERVER['DOCUMENT_ROOT'] . "/YourAppName/uploads/apifiles/".$filename.".".$extension;
I have an EPS file from Photoshop with a clipping path on it:
EPS File
I need to get a thumbnail from this file, so I have the following code:
$img = new imagick();
$img->readimage($uploadfile);
$img->trimimage();
$img->setImageFormat("jpeg");
$img->scaleImage(200,200);
$img->writeimage($uploaddir . $thumb . ".jpg");
I get the following:
Thumb bad
Instead of what I need:
Thumb ok
If I open the file on Photoshop and remove the path by hand I can see it ok, but I have around 3000 images like this, so I need to do this automatically.
I'm letting users upload image files from their desktop and then using the PHP image routines to create thumbnails and resize images for the user's directory. But this doesn't seem to work at all for an animated gif. imagecreatefromgif(), for example, seems to peel off the first image of the animation and only work with it. Do I need to completely bypass these functions to get the complete uploaded animated gif to the user's directory?
Thanks
You cannot resize an animated gif image in the way you easily do with jpeg, bmp or other image formats. The function imagecreatefromgif() is not going to help you by any means, so take a look at the below link.
http://phpimageworkshop.com/tutorial/5/manage-animated-gif-with-imageworkshop.html
It should help you solve your problem.
To upload animated gif images I use this script:
$fileinfo = PATHINFO($_FILES["image"]["name"]);
$newFilename=$fileinfo['filename'] ."_". time() . "." . $fileinfo['extension'];
move_uploaded_file($_FILES["image"]["tmp_name"],"../avatar/" . $newFilename);
$location="avatar/" . $newFilename;
It is simple and may not be a very functional one, but with animated gifs I have no problems.
I'm using the PHP copy function to copy an image after upload to a directory. Is there a way to resize the image before I copy it? I need to resize it to 80x80 for use in my forum.
Here is how I'm calling my copy:
//lets move a copy to the img dir for the forum
$avatar_tmp_file = 'forum/img/avatars/'.$_SESSION['forum_uid']. '.jpg';
copy($_FILES['file']['tmp_name'], $avatar_tmp_file);
Any suggestions?
Yes there is a way to do so. using imagick for instance.
$image=new Imagick();
$image->readImage($_FILES['file']['tmp_name']);
$image->thumbnailImage(80,80);
$image->writeImage($avatar_tmp_file);