<?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.
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!
I am currently working on a solution, where I crop an image to a rectangle using jcrop so I can use it as a texture for a 3D cube (in three.js)
AND I can save the cropped area as an image on the server.
The Problem here is, that the cropped image looks not good, it has low quality.
At first I thought it has something to do with the DPI, because it saves in 96 DPI, but some images that I upload do also have 96 dpi and have good quality.
I think it has something to do with jcrop. Do someone know or had any experience with jcrop regarding this issue? Or should I use a different plugin?
Original Image
Cropped Image
why don't you use php resize image system.
i am using it on my website.
Check demo resize wallpaper (check screen shoot) : Happy diwali wallpaper
and original wallpaper (download button as well as below resize option at the page) diwali wallpaper
you ca use
function resize($newWidth, $targetFile, $originalFile) {
$info = getimagesize($originalFile);
$mime = $info['mime'];
switch ($mime) {
case 'image/jpeg':
$image_create_func = 'imagecreatefromjpeg';
$image_save_func = 'imagejpeg';
$new_image_ext = 'jpg';
break;
case 'image/png':
$image_create_func = 'imagecreatefrompng';
$image_save_func = 'imagepng';
$new_image_ext = 'png';
break;
case 'image/gif':
$image_create_func = 'imagecreatefromgif';
$image_save_func = 'imagegif';
$new_image_ext = 'gif';
break;
default:
throw new Exception('Unknown image type.');
}
$img = $image_create_func($originalFile);
list($width, $height) = getimagesize($originalFile);
$newHeight = ($height / $width) * $newWidth;
$tmp = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($tmp, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if (file_exists($targetFile)) {
unlink($targetFile);
}
$image_save_func($tmp, "$targetFile.$new_image_ext");
}
Source: Resize images with PHP, support PNG, JPG
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;
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