i have two type of image upload :
first high resolution :
$specialImages = count($_FILES['specialImg']['name']);
$specialMinwidth = 3000;
$specialMinheight = 2500;
$urlSpecialImages = array();
if ($specialImages) {
for ($i=1; $i<=$specialImages; $i++) {
if ($_FILES['specialImg']['name'][$i] != "") {
if ((($_FILES['specialImg']['type'][$i] == "image/pjpeg") ||
($_FILES['specialImg']['type'][$i] == "image/jpeg") ||
($_FILES['specialImg']['type'][$i] == "image/png")) &&
($_FILES['specialImg']['size'][$i] < $this->return_bytes(ini_get('post_max_size')))) {
list($width, $height, $type, $attr) = getimagesize($_FILES['specialImg']['tmp_name'][$i]);
if ($width >= $specialMinwidth && $height >= $specialMinheight) {
$urlSpecialImages[$i] = $_FILES['specialImg']['tmp_name'][$i];
}
else {
$this->errors[] = $this->module->l("L'image doit ĂȘtre au format minimum de 3000px x 2500px", 'addproduct');
}
second low resolution :
$images = count($_FILES['images']['name']);
$minwidth = 1500;
$minheight = 1500;
if ($images <= Configuration::get('JMARKETPLACE_MAX_IMAGES')) {
for ($i=1; $i<=Configuration::get('JMARKETPLACE_MAX_IMAGES'); $i++) {
if ($_FILES['images']['name'][$i] != "") {
if ((($_FILES['images']['type'][$i] == "image/pjpeg") ||
($_FILES['images']['type'][$i] == "image/jpeg") ||
($_FILES['images']['type'][$i] == "image/png")) &&
($_FILES['images']['size'][$i] < $this->return_bytes(ini_get('post_max_size')))) {
list($width, $height, $type, $attr) = getimagesize($_FILES['images']['tmp_name'][$i]);
if ($width == $minwidth && $height == $minheight) {
$url_images[$i] = $_FILES['images']['tmp_name'][$i];
}
else {
$this->errors[] = $this->module->l('The image format need to be 1500 x 1500 pixels', 'addproduct');
}
i want to use the special $specialImages uploaded and resize them to . 1500x1500 on images low resolution !
because i want to get both resolution by one upload ! how can i do that ?
Image resize function example:
function resizeImage($file = 'image.png', $maxwidth = 1366){
error_reporting(0);
$image_info = getimagesize($file);
$image_width = $image_info[0];
$image_height = $image_info[1];
$ratio = $image_width / $maxwidth;
$info = getimagesize($file);
if ($image_width > $maxwidth) {
// GoGoGo
$newwidth = $maxwidth;
$newheight = (int)($image_height / $ratio);
if ($info['mime'] == 'image/jpeg') {
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($file);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $image_width, $image_height);
echo imagejpeg($thumb,$file,90);
}
if ($info['mime'] == 'image/jpg') {
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($file);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $image_width, $image_height);
echo imagejpeg($thumb,$file,90);
}
if ($info['mime'] == 'image/png') {
$im = imagecreatefrompng($file);
$im_dest = imagecreatetruecolor($newwidth, $newheight);
imagealphablending($im_dest, false);
imagecopyresampled($im_dest, $im, 0, 0, 0, 0, $newwidth, $newheight, $image_width, $image_height);
imagesavealpha($im_dest, true);
imagepng($im_dest, $file, 9);
}
if ($info['mime'] == 'image/gif') {
$im = imagecreatefromgif($file);
$im_dest = imagecreatetruecolor($newwidth, $newheight);
imagealphablending($im_dest, false);
imagecopyresampled($im_dest, $im, 0, 0, 0, 0, $newwidth, $newheight, $image_width, $image_height);
imagesavealpha($im_dest, true);
imagegif($im_dest, $file);
}
}}
Use:
resizeImage('D:\tmp\11.png', 1366);
Related
I use img uploader on my ftp.
If image large to 1024x768 i use script for resize.
But after resize lose quality.
Code from uploader.php:
if(#move_uploaded_file($_FILES['myfile']['tmp_name'], "$upload_folder/" . $newname))
if($width>1024 || $height>768) {
require './image_resize.php';
echo (image_resize("$upload_folder/" . $newname, "$upload_folder/" . $newname, 1024, 768));
}
Code prom image_resize.php:
<?php ini_set('memory_limit','500M');
function image_resize($src, $dst, $width, $height, $crop=0){
if(!($pic = #getimagesize($src)))
return false;
$w = $pic[0];
$h = $pic[1];
$type = substr($pic['mime'], 6);
$func = 'imagecreatefrom' . $type;
if(!function_exists($func))
return false;
$img = $func($src);
if($crop){
if($w < $width && $h < $height)
return false;
$ratio = max($width/$w, $height/$h);
$h = $height / $ratio;
$x = ($w - $width / $ratio) / 2;
$w = $width / $ratio;
}
else{
if($w < $width && $h < $height)
return false;
$ratio = min($width/$w, $height/$h);
$width = $w * $ratio;
$height = $h * $ratio;
$x = 0;
}
$new = imagecreatetruecolor($width, $height);
if($type == "gif" || $type == "png"){
imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
imagealphablending($new, false);
imagesavealpha($new, true);
}
imagecopyresampled($new, $img, 0, 0, $x, 0, $width, $height, $w, $h);
$save = 'image' . $type;
$save($new, $dst);
return true;
}
It is impossible to reduce the size without losing quality :(
I found script for resize, working fine. I think this is a what I need :)
http://sanchiz.net/blog/resizing-images-with-php
But, one problem and please correct for me: If need resize PNG with transparent background this script remove transparent and add black background.
In comments posted modified script, but with this code not working compress function
I need modify this code for resize PNG without remove transparent background:
class SimpleImage {
public $image;
public $image_type;
public function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if ($this->image_type == IMAGETYPE_JPEG) {
$this->image = imagecreatefromjpeg($filename);
} elseif ($this->image_type == IMAGETYPE_GIF) {
$this->image = imagecreatefromgif($filename);
} elseif ($this->image_type == IMAGETYPE_PNG) {
$this->image = imagecreatefrompng($filename);
}
}
public function save($filename, $image_type = IMAGETYPE_JPEG, $compression = 100, $permissions = NULL) {
if ($image_type == IMAGETYPE_JPEG) {
imagejpeg($this->image, $filename, $compression);
} elseif ($image_type == IMAGETYPE_GIF) {
imagegif($this->image, $filename);
} elseif ($image_type == IMAGETYPE_PNG) {
imagepng($this->image, $filename);
}
if ($permissions != NULL) {
chmod($filename, $permissions);
}
}
public function output($image_type = IMAGETYPE_JPEG) {
if ($image_type == IMAGETYPE_JPEG) {
imagejpeg($this->image);
} elseif ($image_type == IMAGETYPE_GIF) {
imagegif($this->image);
} elseif ($image_type == IMAGETYPE_PNG) {
imagepng($this->image);
}
}
public function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width, $height);
}
public function getHeight() {
return imagesy($this->image);
}
public function getWidth() {
return imagesx($this->image);
}
public function resize($width, $height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
public function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width, $height);
}
public function scale($scale) {
$width = $this->getWidth() * $scale / 100;
$height = $this->getheight() * $scale / 100;
$this->resize($width, $height);
}
Thank you
Since the default API may not be really effective when it comes to image handling, i suggest you use a library. Take a look at grafika
You can also use an external service for images resizing such as this repo
Flyimg.
I'm using the following image resizing script for a mobile application. It works on the fly so the image is automatically resized when a user uploads one. However, some images from smartphones are rotated after the script runs. I researched this and found the cause was the image's EXIF data. I found a piece of script to insert into my own to correct this, but it doesn't seem to be working. I'd appreciate if someone could take a look and let me know what's wrong with it. I'm not an expert in php at all. Here's the code:
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
$ext = strtolower($ext);
if ($ext == "gif"){
$img = imagecreatefromgif($target);
} else if($ext =="png"){
$img = imagecreatefrompng($target);
} else {
$img = imagecreatefromjpeg($target);
$exif = exif_read_data($target);
if ($img && $exif && isset($exif['Orientation']))
{
$ort = $exif['Orientation'];
if ($ort == 6 || $ort == 5)
$img = imagerotate($img, 270, null);
if ($ort == 3 || $ort == 4)
$img = imagerotate($img, 180, null);
if ($ort == 8 || $ort == 7)
$img = imagerotate($img, 90, null);
if ($ort == 5 || $ort == 4 || $ort == 7)
imageflip($img, IMG_FLIP_HORIZONTAL);
}
}
$tci = imagecreatetruecolor($w, $h);
// imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
imagejpeg($tci, $newcopy, 80);
I have this code, I want to resize the picture, it manage to do the first one which 100x100 but not the others. I don't see why it doesn't work, it doesn't have any error. I'm a php newbie, doesn't really know what went wrong, but as you can see as the code does works for the 1st one but why doesn't work for the others?
<?php
function thumbnail($image, $width, $height) {
$image_properties = getimagesize($image);
$image_width = $image_properties[0];
$image_height = $image_properties[1];
$image_ratio = $image_width / $image_height;
$type = $image_properties["mime"];
if(!$width && !$height) {
$width = $image_width;
$height = $image_height;
}
if(!$width) {
$width = round($height * $image_ratio);
}
if(!$height) {
$height = round($width / $image_ratio);
}
if($type == "image/jpeg") {
header('Content-type: image/jpeg');
$thumb = imagecreatefromjpeg($image);
} elseif($type == "image/png") {
header('Content-type: image/png');
$thumb = imagecreatefrompng($image);
} elseif($type == "image/gif") {
header('Content-type: image/gif');
$thumb = imagecreatefromgif($image);
}
else {
return false;
}
$temp_image = imagecreatetruecolor($width, $height);
imagecopyresampled($temp_image, $thumb, 0, 0, 0, 0, $width, $height, $image_width, $image_height);
$thumbnail = imagecreatetruecolor($width, $height);
imagecopyresampled($thumbnail, $temp_image, 0, 0, 0, 0, $width, $height, $width, $height);
if($type == "image/jpeg") {
imagejpeg($thumbnail);
}
elseif($type == "image/jpeg") {
imagepng($thumbnail);
}
elseif($type == "image/gif") {
imagegif($thumbnail);
}
imagedestroy($temp_image);
imagedestroy($thumbnail);
}
$pic_size = array();
// Adjust size
$pic_size['height'][0] = 100;
$pic_size['width'][0] = 100;
$pic_size['height'][1] = 200;
$pic_size['width'][1] = 200;
$pic_size['height'][2] = 300;
$pic_size['width'][2] = 300;
$pic_size['height'][3] = 400;
$pic_size['width'][3] = 400;
$pic_size['height'][4] = 500;
$pic_size['width'][4] = 500;
$total_pic_size= count($pic_size['height']);
$x = 0;
foreach(array_keys($pic_size['height']) as $x) {
thumbnail($_GET["img"], $pic_size['width'][$x], $pic_size['height'][$x]);
echo '<img src="index.php?w='.$pic_size['width'][$x].'&h='.$pic_size['height'][$x].'&img='.$_GET["img"].'" />';
$x++;
}
?>
You iterate only two times, because
$total_pic_size= count($pic_size);// is 2
Change that to:
$total_pic_size= count($pic_size['height']);
Or use foreach:
foreach(array_keys($pic_size['height']) as $x)
And don't use COUNT_RECURSIVE here, it will return wrong number again, counting in the width and height keys.
Also thumbnail function has header call in it, which cannot be called after echo, which in your case, is called after echo, in your loop. You should see the warning saying "Headers already sent".
You can save the image to file and echo image with file path as a source. Remove the header calls and let your thumbnail function save it and return the file name, for example:
imagejpeg($thumbnail, $filename);
return $filename;
and use the output as src of the echoed image.
Your $total_pic_size is always 2.
$total_pic_size = count( $pic_size['width'] );
This will give you the correct number of items and the loop should run not only once.
You should also change the loop-condition:
while ($x <= $total_pic_size) {
#Update 1
You can try something like this:
// ...
$pic_sizes[0]['height'] = 100;
$pic_sizes[0]['width'] = 100;
$pic_sizes[1]['height'] = 200;
$pic_sizes[1]['width'] = 200;
$pic_sizes[2]['height'] = 300;
$pic_sizes[2]['width'] = 300;
$pic_sizes[3]['height'] = 400;
$pic_sizes[3]['width'] = 400;
$pic_sizes[4]['height'] = 500;
$pic_sizes[4]['width'] = 500;
$img = $_GET["img"];
foreach ($pic_sizes as $pic_size) {
thumbnail($img, $pic_size['width'], $pic_size['height']);
echo '<img src="index.php?w='.$pic_size['width'].'&h='.$pic_size['height'].'&img='.$img.'" />';
}
#Update 2:
You already accepted another answere, but maybe this is also helpful for you. i found some more errors and logic-problems in your code... the code below works (without saving the thumbs).
<?php
function thumbnail($image, $width, $height) {
$image_properties = getimagesize($image);
$image_width = $image_properties[0];
$image_height = $image_properties[1];
$image_ratio = $image_width / $image_height;
$type = $image_properties["mime"];
if(!$width && !$height) {
$width = $image_width;
$height = $image_height;
}
if(!$width) {
$width = round($height * $image_ratio);
}
if(!$height) {
$height = round($width / $image_ratio);
}
if($type == "image/jpeg") {
header('Content-type: image/jpeg');
$thumb = imagecreatefromjpeg($image);
} elseif($type == "image/png") {
header('Content-type: image/png');
$thumb = imagecreatefrompng($image);
} elseif($type == "image/gif") {
header('Content-type: image/gif');
$thumb = imagecreatefromgif($image);
}
else {
return false;
}
$temp_image = imagecreatetruecolor($width, $height);
imagecopyresampled($temp_image, $thumb, 0, 0, 0, 0, $width, $height, $image_width, $image_height);
$thumbnail = imagecreatetruecolor($width, $height);
imagecopyresampled($thumbnail, $temp_image, 0, 0, 0, 0, $width, $height, $width, $height);
if($type == "image/jpeg") {
imagejpeg($thumbnail);
}
elseif($type == "image/png") {
imagepng($thumbnail);
}
elseif($type == "image/gif") {
imagegif($thumbnail);
}
imagedestroy($temp_image);
imagedestroy($thumbnail);
}
$img = $_GET["img"];
$gen = #$_GET["gen"];
$w = #$_GET["w"];
$h = #$_GET["h"];
if ( !$gen ) {
$pic_sizes = array();
// Adjust size
$pic_sizes[0]['height'] = 100;
$pic_sizes[0]['width'] = 100;
$pic_sizes[1]['height'] = 200;
$pic_sizes[1]['width'] = 200;
$pic_sizes[2]['height'] = 300;
$pic_sizes[2]['width'] = 300;
$pic_sizes[3]['height'] = 400;
$pic_sizes[3]['width'] = 400;
$pic_sizes[4]['height'] = 500;
$pic_sizes[4]['width'] = 500;
foreach ($pic_sizes as $pic_size) {
echo '<img src="'.$_SERVER['PHP_SELF'].'?w='.$pic_size['width'].'&h='.$pic_size['height'].'&img='.$img.'&gen=1" />';
}
} else {
thumbnail($img, $w, $h);
}
I have a PHP function that I use regularly for working with images (resizing, watermarking, converting to grayscale, etc). I am happy with it and it works well. However, it is designed to work with the $_FILES superglobal, and accepts it as a parameter.
I've run into a situation where I have an existing directory of files on my server that I need to process in the same way as I do for files uploaded from a form into the $_FILES array.
Figuring it would be easiest to work with my existing function, I have been looking for a way to duplicate the $_FILES superglobal, so I can pass it to my script, but I am not finding the functions/properties I need to accomplish this. (Although, at a glance, the getimagesize and filesize functions looks like they may help).
Can anyone advise on what functions/properties I would need to duplicate the $_FILES array? (Or an alternate way to accomplish what I am trying to do?)
For reference's sake, the image function I use is here:
function resize_upload ($file, $dest, $maxw = 50, $maxh = 50, $grey = false, $wm = false, $mark = "a/i/watermark.png", $opa = 40) {
$allowext = array("gif", "jpg", "png", "jpeg", "bmp");
$fileext = strtolower(getExtension($file['name']));
if (!in_array($fileext,$allowext)) {
echo "Wrong file extension.";
exit();
}
list($width, $height, $imgcon) = getimagesize($file['tmp_name']);
if ($file['size'] && ($width > $maxw || $height > $maxh)) {
if($file['type'] == "image/pjpeg" || $file['type'] == "image/jpeg"){$newimg = imagecreatefromjpeg($file['tmp_name']);}
elseif($file['type'] == "image/x-png" || $file['type'] == "image/png"){$newimg = imagecreatefrompng($file['tmp_name']);}
elseif($file['type'] == "image/gif"){$newimg = imagecreatefromgif($file['tmp_name']);}
$ratio = $width/$height;
if ($ratio < 1) { // Width < Height
$newheight = $maxh;
$newwidth = $width * ($maxh/$height);
if ($newwidth > $maxw) {
$newheight = $newheight * ($maxw/$newwidth);
$newwidth = $maxw;
}
} elseif ($ratio == 1) { // Width = Height
if ($maxw < $maxh) {
$newheight = $maxw;
$newwidth = $maxw;
} elseif ($maxw == $maxh) {
$newheight = $maxh;
$newwidth = $maxw;
} elseif ($maxw > $maxh) {
$newheight = $maxh;
$newwidth = $maxh;
}
} elseif ($ratio > 1) { // Width > Height
$newwidth = $maxw;
$newheight = $height * ($maxw/$width);
if ($newheight > $maxh) {
$newwidth = $newwidth * ($maxh/$newheight);
$newheight = $maxh;
}
}
if (function_exists(imagecreatetruecolor)) {$resize = imagecreatetruecolor($newwidth, $newheight);}
if (($imgcon == IMAGETYPE_GIF)) {
$trnprt_indx = imagecolortransparent($newimg);
if ($trnprt_indx >= 0) {
$trnprt_color = imagecolorsforindex($newimg, $trnprt_indx);
$trnprt_indx = imagecolorallocate($resize, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
imagefill($resize, 0, 0, $trnprt_indx);
imagecolortransparent($resize, $trnprt_indx);
}
} elseif ($imgcon == IMAGETYPE_PNG) {
imagealphablending($resize, false);
$color = imagecolorallocatealpha($resize, 0, 0, 0, 127);
imagefill($resize, 0, 0, $color);
imagesavealpha($resize, true);
}
imagecopyresampled($resize, $newimg, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
if ($wm) {
$watermark = imagecreatefrompng($mark);
$wm_width = imagesx($watermark);
$wm_height = imagesy($watermark);
$destx = $newwidth - $wm_width - 5;
$desty = $newheight - $wm_height - 5;
imagecopymerge($resize, $watermark, $destx, $desty, 0, 0, $wm_width, $wm_height, $opa);
imagedestroy($watermark);
}
$filename = random_name().".".$fileext;
if ($grey) {imagefilter($resize, IMG_FILTER_GRAYSCALE);}
if($file['type'] == "image/pjpeg" || $file['type'] == "image/jpeg"){$new = imagejpeg($resize, $dest."/".$filename, 100);}
elseif($file['type'] == "image/x-png" || $file['type'] == "image/png"){$new = imagepng($resize, $dest."/".$filename, 0);}
elseif($file['type'] == "image/gif"){$new = imagegif($resize, $dest."/".$filename);}
imagedestroy($resize);
imagedestroy($newimg);
return $filename;
} elseif ($file['size']) {
$filename = random_name().".".getExtension($file['name']);
if ($grey) {
if($file['type'] == "image/pjpeg" || $file['type'] == "image/jpeg"){$newimg = imagecreatefromjpeg($file['tmp_name']);}
elseif($file['type'] == "image/x-png" || $file['type'] == "image/png"){$newimg = imagecreatefrompng($file['tmp_name']);}
elseif($file['type'] == "image/gif"){$newimg = imagecreatefromgif($file['tmp_name']);}
imagefilter($newimg, IMG_FILTER_GRAYSCALE);
if($file['type'] == "image/pjpeg" || $file['type'] == "image/jpeg"){imagejpeg($newimg, $dest."/".$filename);}
elseif($file['type'] == "image/x-png" || $file['type'] == "image/png"){imagepng($newimg, $dest."/".$filename);}
elseif($file['type'] == "image/gif"){imagegif($newimg, $dest."/".$filename);}
imagedestroy($newimg);
return $filename;
} else {
$upload = file_upload($file, $dest);
return $upload;
}
}
}
The $_FILES array contains a nested array for an uploaded file. This nested array has 5 keys. For each key I explain what it should contain, and what function to use:
name: the name of the file, use the basename() function for this entry
type: the mime type of the file, for images set to 'image/png', 'image/jpeg', etc
tmp_name: the path to the actual file, here you should set the path to your images
error: this indicates that an error occured with the upload, in your case you can set it to 0 for no error
size: the size of the file in bytes, so you can use the filesize() function for your image
An example:
$_FILES = array('image' => array(
'name' => basename('/path/to/image.png'),
'type' => 'image/png',
'tmp_name' => '/path/to/image.png',
'error' => 0,
'size' => filesize('/path/to/image.png')
));
If you want to process multiple files at once, you should be aware that the structure of the $_FILES array is different than what you would expect in this case, see this comment in the PHP docs.
I'm trying to resize an image of more than 3000px in width, it uploads fine if i do not resize it, but as soon as I resize the image it does not want to upload and resize, this is funny and I can't seem to understnd, since if the width of the image is alot smaller everthing works just fine. Are there limitations to this?
Try this... Not Using GD but i think it will work for u.
<?php
function Image($image, $crop = null, $size = null) {
$image = ImageCreateFromString(file_get_contents($image));
if (is_resource($image) === true) {
$x = 0;
$y = 0;
$width = imagesx($image);
$height = imagesy($image);
/*
CROP (Aspect Ratio) Section
*/
if (is_null($crop) === true) {
$crop = array($width, $height);
} else {
$crop = array_filter(explode(':', $crop));
if (empty($crop) === true) {
$crop = array($width, $height);
} else {
if ((empty($crop[0]) === true) || (is_numeric($crop[0]) === false)) {
$crop[0] = $crop[1];
} else if ((empty($crop[1]) === true) || (is_numeric($crop[1]) === false)) {
$crop[1] = $crop[0];
}
}
$ratio = array(0 => $width / $height, 1 => $crop[0] / $crop[1]);
if ($ratio[0] > $ratio[1]) {
$width = $height * $ratio[1];
$x = (imagesx($image) - $width) / 2;
}
else if ($ratio[0] < $ratio[1]) {
$height = $width / $ratio[1];
$y = (imagesy($image) - $height) / 2;
}
}
/*
Resize Section
*/
if (is_null($size) === true) {
$size = array($width, $height);
}
else {
$size = array_filter(explode('x', $size));
if (empty($size) === true) {
$size = array(imagesx($image), imagesy($image));
} else {
if ((empty($size[0]) === true) || (is_numeric($size[0]) === false)) {
$size[0] = round($size[1] * $width / $height);
} else if ((empty($size[1]) === true) || (is_numeric($size[1]) === false)) {
$size[1] = round($size[0] * $height / $width);
}
}
}
$result = ImageCreateTrueColor($size[0], $size[1]);
if (is_resource($result) === true) {
ImageSaveAlpha($result, true);
ImageAlphaBlending($result, true);
ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255));
ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height);
ImageInterlace($result, true);
ImageJPEG($result, null, 90);
}
}
return false;
}
header('Content-Type: image/jpeg');
Image('image.jpg', '2:1', '1200x');
?>