I've created a codeigniter website with a image resize function. This website worked great on my old webspace, now I transfered the website successfully to my new webspace, but unfortunately only small file size images are resized.
Big size images are not resized, and there are no errors displayed.
I've already checked the following stuff:
memory_limit=64M, GD2 image library installed on server, upload_max_filesize=25M, post_max_size=25M, max_input_time=300, max_execution_time=300
Here's the resize code I use:
$query = $this->db->query('SELECT * FROM table1');
foreach ($query->result_array() as $key => $row)
{
//$key value on error is '0'
$config_1['image_library'] = 'imagemagick';
$config_1['source_image'] = $filePath . $fileName;
$config_1['new_image'] = $filePath . 'resized1' . $fileExtension;
$config_1['maintain_ratio'] = TRUE;
$config_1['width'] = 420;
$config_1['height'] = 680;
$config_1['quality'] = 100;
//+ 2 other times the same for $config_2 and $config_3
$this->load->library('image_lib');
$this->image_lib->initialize($config_1);
$this->image_lib->resize();
$this->image_lib->clear();
$this->image_lib->initialize($config_2);
$this->image_lib->resize();
$this->image_lib->clear();
//function quits here with big files (tested with 11 MB files)
$this->image_lib->initialize($config_3);
$this->image_lib->resize();
$this->image_lib->clear();
}
//Update: I've now tried to change image library to ImageMagick to see if it works. Now I get the following error (and images are not resized):
A PHP Error was encountered
Severity: Warning
Message: filesize(): stat failed for test-uploads/files/2016/02/01/resized-file.jpg
Filename: controllers/xyz.php
Line Number: xyz
The error occurs here:
$photo_size1 = filesize($filePath . $fileRename_1) / 1024;
Related
I have integrated Intervention Image library (v-2.5) into my laravel application (v-5.1) to resize images. It is working fine in local server, but when i deploy it to live server i'm getting this error: Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files.
. My image size is 18kb and its mime type is jpg. So there is nothing wrong with my image. Here is my code that i'm using for convertion and saving to server:
foreach ($request->images as $file) {
// getting file name with extension
$imageName = getFileName($file);
$homeworkImage = new HomeworkImage();
$homeworkImage->tbl_homework_id = $homework->homework_id;
$homeworkImage->image_name = $imageName;
if ($homeworkImage->save()) {
// $file->move('uploads/homework', $imageName);
$image_resize = Image::make($file->getRealPath());
$image_resize->resize(300, 300);
$image_resize->save('uploads/homework/' . $imageName);
}
}
If i try to upload the image normally, that it is working fine. Can anyone point me out if i'm missing something!
Hello im uploading from input form a data:image, its works well with png and jpg
but i cant get work it with GIF.
<input value="data:image/gif;base64,...................................." type="hidden" />
What i need:
Create a file from a string with out losing animation. (the other problem)
Copy to a folder
The problem
Whatever gif im trying to upload i get a error from if (!$image) that image is not valid. Why ?
If i remove $image = #imagecreatefromgif($image); All works but image copied is only first frame from the gif, so its not animated (i heard GD have problems with it, maybe i can just copy full image from datestring, but how to save it right ? )
Im tried to use Gifencoder and Gifdecoder and imagemagick but the problem its doesn't recognize a image from datastring , i need to blob it ?
Here is my code
function ImageUploadString($data_string)
{
$data_string = str_replace('data:image/gif;base64,', '', $data_string);
$data_string = base64_decode($data_string); // decode image from base64
$image = imagecreatefromstring($data_string);
if ($image !== false) {
$random_imagename = str_shuffle(MD5(microtime()));
$extention = "gif";
$ufname = 'folder/'.$random_imagename.'.'.$extention;
$image = #imagecreatefromgif($image); /* Attempt to open */
if (!$image) {
imagedestroy($image);
die('gif error');
}
imagegif($image, $ufname);
}
}
$imagebase = "data:image/gif;base64,..........................................";
ImageUploadString($imagebase);
I have a successful upload script and it returns the path (later inserted to DB table). Now I realize that since my site should allow large photo (not in size but dimensions), I should try and resize the photos (in MBs). I came across image manipulation in CI. How can I resize picture with given path and delete original picture (not sure if it is done automatically)? Code below shows the last bit of my upload function:
/*Image Manipulation Class*/
$config['image_library'] = 'gd2';
$config['source_image'] = $fullImagePath;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
return $fullImagePath;
I have a project that I wanna use codeigniter to resize the uploaded image and save to a remote server
I can successfully do the following(all on my local machine):
get the uploaded images
save to a tmp folder
resize the image in the tmp folder
save to the final destination folder.
However, I wanna make one more step further. I wanna get the image from tmp, resize it and save to a remote server. here is the sample code I assume it wont work.
$config['image_library'] = 'gd2';
$config['source_image'] = '/tmp/sample.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 80;
$config['height'] = 60;
$config['new_image'] = 'ftp://xx.xx.xxx.xxx/tmp/sample.jpg'; // can i do this?
$config['thumb_marker'] = '';
$ftpconfig['hostname'] = 'xx.xx.xxx.xxx';
$ftpconfig['username'] = 'name';
$ftpconfig['password'] = 'password';
$ftpconfig['debug'] = TRUE;
$this->ftp->connect($ftpconfig);
// and can I call CI to resize it and save to a ftp server after connent ftp?
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$this->ftp->close();
you need to upload file, right now you are not using upload method of FTP library file after saving on your server you have to upload
$this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775);
please check user guide for ftp class
I've been trying to find a way to add Photo to a customer profile in Magento.
They have everything but this, and I can't find anywhere how to do it.
Any help is appreciated.
I'm using Community edition.
To upload profile photo for customer in magento we need to follow few steps as below.
Add a new field for profile photo(How to create new fields for customer - Check this link it will helps you).
The above link helps you to add a new filed in DB and you need to upload that photo manually the below code will helps you to upload photos in magento.
if(isset($_FILES['logo']['name']) and (file_exists($_FILES['logo']['tmp_name'])))
{
try {
$uploader = new Varien_File_Uploader('logo');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS .'catalog/customer/logo/';
$newName = time() . $_FILES['logo']['name'];
$uploader->save($path, $newName);
$customer->setLogo($newName);
// actual path of image
$imageUrl = $path . $newName;
// path of the resized image to be saved
// here, the resized image is saved in media/resized folder
$imageResized = $path . $newName;
// resize image only if the image file exists and the resized image file doesn't exist
// the image is resized proportionally with the width/height 135px
if (!file_exists($imageResized)&&file_exists($imageUrl)) :
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->resize(150, 150);
$imageObj->save($imageResized);
endif;
}catch(Exception $e) {
}
}
After upload we need to save file name in DB.
$customer->setLogo($newName);