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.
Related
i want to make my image size as my given size when it upload.
my php code
$picture_name =time().'-' .$_FILES["picture"]["name"];
if($c->Insert())
{
move_uploaded_file($_FILES["picture"]["tmp_name"], "Portfolio_Image/" . $picture_name);
}
But how can i re-size image at upload time
Take a look at the PHP GD library. In particular the imagecopyresized function. The example on there is a pretty good one.
First I want to tell you guys I'm a beginner to this. I'm developing a website, I want to allow users to upload any size of images in a variety of formats (GIF,JPEG,PNG).
And I want to re size the image and convert the image format into PNG. Im not inserting the image into database as BLOBs.
this is my code, But I'm uploading the image directly here, How to re size and convert to PNG:
$myImage = $_FILES['imgCover']['name'];
$response = mysql_query("INSERT INTO gallery (imagename) VALUE ('$myImage')");
if($response === true)
{
move_uploaded_file($_FILES['imgCover']['tmp_name'],"images/gallery/".$_FILES['imgCover']['name'])
}
Please help me.
Something like http://salman-w.blogspot.com/2008/10/resize-images-using-phpgd-library.html?
Just use png where its says jpeg, like
imagejpeg
etc.
I am looking to accomplish this in CodeIgniter specifically.
The PHP App I am coding allows a user to upload either a jpg or an animated gif image. On the next step I want to allow the user to use jCrop to crop a few different size thumbnails. This would require me to convert a new copy of the animated gif to a jpg. My code works fine with uploaded jpg images, but creates a broken image for gif files. Is what I am trying to do possible?
My Code:
// Create image to crop
$config['image_library'] = 'ImageMagick';
$config['library_path'] = '/usr/bin';
$config['source_image'] = $this->config->item('upload_dir_path') . $file_path . 'original.' . $file_ext;
chmod($config['source_image'], 0777);
$config['new_image'] = $this->config->item('upload_dir_path') . $file_path . 'crop-me.jpg';
$this->image_lib->initialize($config);
$this->image_lib->resize();
For those interested in my solution, I simply used the built in GD PHP functions. I have little experience dealing with gif files so I was expecting this to be difficult. The fact of the matter is the CodeIgniter Image_lib and extended library (Which I never got to work properly) is overkill for this.
Here is what I used:
$image = imagecreatefromgif($path_to_gif_image);
imagejpeg($image, $output_path_with_jpg_extension);
Very easy and worked perfectly for what I needed.
How much difference does it make if I want to save all uploaded images to my site as gif if I just do...
$target = 'images/avatars/' . md5($user['id']) . '.gif';
Rather than creating a gif in php copying the temp image and then saving? Will the browser still load the file? Will it still recognise the old file type? Does it really matter from a point of view where these images will never be downloaded purposelly through my site?
Thanks
Yes, you can rename images to .gif and browsers will still display them as jpg even if you load them with a .gif extension.
It will still have a jpg filetype, just with a .gif extension. (Just tested this)
In my web app users are allowed to upload images as their photos. How can I convert different image extensions to JPG? Input files are JPG, PNG or GIF.
Personally, I prefer Image Magick over GD. It's a lot better if you're dealing with large images too; you can run into memory allocation issues with GD.
With php, you can convert any image to an other using imagepng, imagejpeg, imagegif :
imagepng(imagecreatefromstring(file_get_contents($input)), 'output.png');
In this example, it will save the uploaded image in png with the path 'output.png'
You can use PHP GD.
For anybody who would want to get the binary out of a temporary file, here is my solution:
<?php
$temp = tmpfile();
imagepng(imagecreatefromstring($imgBinary), $temp);
$pathFile = stream_get_meta_data($temp)['uri']; // eg: /tmp/phpFx0513a
$pngBin = file_get_contents($pathFile)
?>