Codeigniter resize image and save to a remote server - codeigniter

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

Related

image resize and add watermark in codeigniter at same time

<?php
$config["image_library"] = 'gd2';
$config['source_image'] = $image_org;
$config['new_image'] = $image_thumb;
$config['maintain_ratio'] = TRUE;
$config["width"] = $width;
$config["height"] = $height;
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = './images/logo.png';
$config['wm_opacity'] = 50;
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'right';
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->watermark();
?>
i need to perform image resize and add watermark in same function, but either of resize or watermark only works ?
From https://www.codeigniter.com/userguide3/libraries/image_lib.html
Watermarking is only available using the GD/GD2 library.
In addition, even though other libraries are supported, GD is required in order for the script to calculate the image properties. The image processing, however, will be performed with the library you specify.
Try using GD, ImageMagick, NetPBM in $config["image_library"]="GD"; //
You will have to install PHP GD2 Library on your machine.
For ubuntu
sudo apt-get install php5-gd && sudo service apache2 restart
For windows
you'll include the GD2 DLL php_gd2.dll as an extension in php.ini.

CanĀ“t export canvas ti image if i add image from external url fabric js

Hello i create a function to add image from an external URL:
HTML:
<input type="text" id="IMGbyURL" placeholder="http://"/>Agregar
Javascript to add image:
function ImgPorURL(srcImg){
fabric.Image.fromURL(srcImg, function(oImg) {
canvas.add(oImg);
})
}
HTML to export:
Export
Javascript to export canvas:
function convertToImagen() {
canvas.deactivateAll().renderAll();
window.open(canvas.toDataURL('jpg'));
}
But does not work, the funny thing is that if i upload the image, save to any folder in the server and add the image to the canvas, it works perfectly and the canvas is exported as an image, but not work if i add the image from external site... Thanks!!
The funny thing, as you call it is called CORS.
Cross origin resource sharing.
Fabricjs support some CORS functionality
fabric.Image.fromURL(srcImg, function(oImg) {
canvas.add(oImg);
}, {crossOrigin: 'Anonymous'});
If this does not work, well the server of the external link does not support sharing images all around. There is little than you can do other than sharing on another server, including your.
In addition to #AndreaBogazzi's answer - if the FabricJS config {crossOrigin: 'Anonymous'} won't work you can utilise PHP proxying script (on backend) that will download images from 3rd party to your domain and serve fabric with them. Here's the sample script:
<?php
// define absolute path to image folder
$image_folder = '/home/mydomain/upload_folder/';
// get the image name from the query string
// and make sure it's not trying to probe your file system
if (isset($_GET['pic']) && basename($_GET['pic']) == $_GET['pic']) {
$pic = $image_folder.$_GET['pic'];
if (file_exists($pic) && is_readable($pic)) {
// get the filename extension
$ext = substr($pic, -3);
// set the MIME type
switch ($ext) {
case 'jpg':
$mime = 'image/jpeg';
break;
case 'gif':
$mime = 'image/gif';
break;
case 'png':
$mime = 'image/png';
break;
default:
$mime = false;
}
// if a valid MIME type exists, display the image
// by sending appropriate headers and streaming the file
if ($mime) {
header('Content-type: '.$mime);
header('Content-length: '.filesize($pic));
$file = # fopen($pic, 'rb');
if ($file) {
fpassthru($file);
exit;
}
}
}
}
?>

Codeigniter Image Resize with Big Images Not Working

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;

manipulate image in codeigniter after upload

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;

Magento - Customer Profile Photo upload

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);

Resources