i am working on php function that would put watermark on image. I´ve got it working but i need to scale this watermark so the height of the watermark will be 1/3 of the original image. I can do that, but when i put it into my code it just doesnt work, because the parameter of imagecopymerge must be resource, which i dont know what means.
define('WATERMARK_OVERLAY_IMAGE', 'watermark.png');
define('WATERMARK_OVERLAY_OPACITY', 100);
define('WATERMARK_OUTPUT_QUALITY', 100);
function create_watermark($source_file_path, $output_file_path)
{
list($source_width, $source_height, $source_type) = getimagesize($source_file_path);
if ($source_type === NULL) {
return false;
}
switch ($source_type) {
case IMAGETYPE_GIF:
$source_gd_image = imagecreatefromgif($source_file_path);
break;
case IMAGETYPE_JPEG:
$source_gd_image = imagecreatefromjpeg($source_file_path);
break;
case IMAGETYPE_PNG:
$source_gd_image = imagecreatefrompng($source_file_path);
break;
default:
return false;
}
$overlay_gd_image = imagecreatefrompng(WATERMARK_OVERLAY_IMAGE);
$overlay_width = imagesx($overlay_gd_image);
$overlay_height = imagesy($overlay_gd_image);
//THIS PART IS WHAT SHOULD RESIZE THE WATERMARK
$source_width = imagesx($source_gd_image);
$source_height = imagesy($source_gd_image);
$percent = $source_height/3/$overlay_height;
// Get new sizes
$new_overlay_width = $overlay_width * $percent;
$new_overlay_height = $overlay_height * $percent;
// Load
$overlay_gd_image_resized = imagecreatetruecolor($new_overlay_width, $new_overlay_height);
// Resize
$overlay_gd_image_complet = imagecopyresized($overlay_gd_image_resized, $overlay_gd_image, 0, 0, 0, 0, $new_overlay_width, $new_overlay_height, $overlay_width, $overlay_height);
//ALIGN BOTTOM, RIGHT
if (isset($_POST['kde']) && $_POST['kde'] == 'pravo') {
imagecopymerge(
$source_gd_image,
$overlay_gd_image_complet,
$source_width - $new_overlay_width,
$source_height - $new_overlay_height,
0,
0,
$new_overlay_width,
$new_overlay_height,
WATERMARK_OVERLAY_OPACITY
);
}
if (isset($_POST['kde']) && $_POST['kde'] == 'levo') {
//ALIGN BOTTOM, LEFT
imagecopymerge(
$source_gd_image,
$overlay_gd_image,
0,
$source_height - $overlay_height,
0,
0,
$overlay_width,
$overlay_height,
WATERMARK_OVERLAY_OPACITY
);
}
imagejpeg($source_gd_image, $output_file_path, WATERMARK_OUTPUT_QUALITY);
imagedestroy($source_gd_image);
imagedestroy($overlay_gd_image);
imagedestroy($overlay_gd_image_resized);
}
/*
* Uploaded file processing function
*/
define('UPLOADED_IMAGE_DESTINATION', 'originals/');
define('PROCESSED_IMAGE_DESTINATION', 'images/');
function process_image_upload($Field)
{
$temp_file_path = $_FILES[$Field]['tmp_name'];
/*$temp_file_name = $_FILES[$Field]['name'];*/
$temp_file_name = md5(uniqid(rand(), true)) . '.jpg';
list(, , $temp_type) = getimagesize($temp_file_path);
if ($temp_type === NULL) {
return false;
}
switch ($temp_type) {
case IMAGETYPE_GIF:
break;
case IMAGETYPE_JPEG:
break;
case IMAGETYPE_PNG:
break;
default:
return false;
}
$uploaded_file_path = UPLOADED_IMAGE_DESTINATION . $temp_file_name;
$processed_file_path = PROCESSED_IMAGE_DESTINATION . preg_replace('/\\.[^\\.]+$/', '.jpg', $temp_file_name);
move_uploaded_file($temp_file_path, $uploaded_file_path);
$result = create_watermark($uploaded_file_path, $processed_file_path);
if ($result === false) {
return false;
} else {
return array($uploaded_file_path, $processed_file_path);
}
}
$result = process_image_upload('File1');
if ($result === false) {
echo '<br>An error occurred during file processing.';
} else {
/*echo '<br>Original image saved as ' . $result[0] . '';*/
echo '<br>Odkaz na obrazek je zde';
echo '<br><img src="' . $result[1] . '" width="500px">';
echo '<br><div class="fb-share-button" data-href="' . $result[1] . '" data-type="button"></div>';
}
Related
I'm having a hard time implemeting the php code will ensure that all uploaded photos will be oriented correctly upon upload.
here is my upload.php function ...
function process_image_upload($field)
{
if(!isset($_FILES[$field]['tmp_name']) || ! $_FILES[$field]['name'])
{
return 'empty';
}
$temp_image_path = $_FILES[$field]['tmp_name'];
$temp_image_name = $_FILES[$field]['name'];
list($iwidth, $iheight, $temp_image_type) =
getimagesize($temp_image_path);
if ($temp_image_type === NULL) {
return false;
}
elseif( $iwidth < 400 )
return 'size';
switch ($temp_image_type) {
case IMAGETYPE_GIF:
break;
case IMAGETYPE_JPEG:
break;
case IMAGETYPE_PNG:
break;
default:
return false;
}
$uploaded_image_path = UPLOADED_IMAGE_DESTINATION . $temp_image_name;
move_uploaded_file($temp_image_path, $uploaded_image_path);
$thumbnail_image_path = THUMBNAIL_IMAGE_DESTINATION .
preg_replace('{\\.[^\\.]+$}', '.jpg', $temp_image_name);
$main_image_path = MAIN_IMAGE_DESTINATION . preg_replace('{\\.[^\\.]+$}', '.jpg', $temp_image_name);
$result =
generate_image_thumbnail($uploaded_image_path,
$thumbnail_image_path,150,150
); if( $result )
$result =
generate_image_thumbnail($uploaded_image_path,$main_image_path,400,400,
true);
return $result ? array($uploaded_image_path, $thumbnail_image_path) :
false;
}
if(isset($_POST['upload'])):
$result = process_image_upload('image');
if ($result === false) {
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>An error occurred while processing upload</p></div>');
} else if( $result === 'empty')
{
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>Please select a Image file</p></div>');
}
elseif( $result === 'size')
{
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>Image width must be greater than 400px;</p></div>');
}
else {
update_option('meme_message','<div style="margin-left:0;"
class="updated"><p>Image uploaded successfully</p></div>');
$guploaderr = false;
$count = intval(get_option('meme_image_count'));
update_option('meme_image_count', $count+1);
}
endif;
and here is some php that I know will work to rotate... but I don't know how to implement.
<?php
$image =
imagecreatefromstring(file_get_contents($_FILES['image_upload']
['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
}
// $image now contains a resource with the image oriented correctly
?>
I use a PHP file to upload images to my server from my web application and have recently hit some memory limit issues that I was hoping someone with more experience than me could help with. Most of the images uploaded have been from mobiles so the file size is very manageable but recently there have been some uploads from an SLR camera that have been causing the issues. These images are around 7-8MB in size and I had assumed our PHP memory limit of 64MB would handle this. Upon inspection I found the imagecreatefromjpeg() function in our crop function to be the culprit although I assume the memory has been filled up before this despite using imagedestroy() to clear any previously created images. Upon using ini_set('memory_limit') to up the limit to a much higher value I found the script worked as expected but I would prefer a cleaner solution. I have attached the code below and any help would be greatly appreciated.
ini_set('memory_limit', '256M');
if(isset($_POST)) {
############ Edit settings ##############
$ThumbSquareSize = 200; //Thumbnail will be 200x200
$ThumbPrefix = "thumbs/"; //Normal thumb Prefix
$DestinationDirectory = '../../../uploads/general/'; //specify upload directory ends with / (slash)
$PortfolioDirectory = '../../../images/portfolio/';
$Quality = 100; //jpeg quality
##########################################
$imID = intval($_POST['imageID']);
$image = $_POST['image'];
$data = $image['data'];
$name = $image['name']; //get image name
$width = $image['width']; // get original image width
$height = $image['height'];// orig height
$type = $image['type']; //get file type, returns "image/png", image/jpeg, text/plain etc.
$desc = $image['desc'];
$album = intval($image['album']);
$customer = intval($image['customer']);
$tags = $image['tags'];
$allTags = $_POST['allTags'];
$portType = intval($image['portType']);
$rating = intval($image['rating']);
$imData = array();
if(strlen($data) < 500) {
$dParts = explode('?', $data);
$path = $dParts[0];
$base64 = file_get_contents($path);
$data = 'data:' . $type . ';base64,' . base64_encode($base64);
}
function base64_to_jpeg($base64_string, $output_file) {
$ifp = fopen($output_file, "wb");
$data = explode(',', $base64_string);
fwrite($ifp, base64_decode($data[1]));
fclose($ifp);
return $output_file;
}
function base64_to_png($base64_string, $output_file) {
$img = str_replace('data:image/png;base64,', '', $base64_string);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$im = imagecreatefromstring($data);
if ($im !== false) {
imagepng($im, $output_file);
imagedestroy($im);
}
return $output_file;
}
if($stmt = $db -> prepare("UPDATE `images` SET name = ?, type = ?, description = ?, width = ?, height = ?, rating = ?, portType = ?, customer = ?, album = ?, dateModified = NOW() WHERE ID = ?")) {
$stmt -> bind_param("sssiiiiiii", $name, $type, $desc, $width, $height, $rating, $portType, $customer, $album, $imID);
if (!$stmt->execute()) {
echo false;
} else {
$delTags = "DELETE FROM tagLink WHERE imageID = $imID";
if(!$db->query($delTags)) {
echo $db->error;
}
if(sizeof($tags) > 0) {
foreach($tags as $tag) {
$tagQ = "INSERT INTO tagLink (imageID, tag) VALUES ($imID, '$tag')";
if(!$db->query($tagQ)) {
echo $db->error;
}
}
}
switch(strtolower($type))
{
case 'png':
$fname = $name . '(' . $imID . ').png';
$file = $DestinationDirectory . $fname;
$portfile = $PortfolioDirectory . $fname;
$thumbDest = $DestinationDirectory . $ThumbPrefix . $fname;
$CreatedImage = base64_to_png($data,$file);
break;
case 'jpeg':
case 'pjpeg':
case 'jpeg':
$fname = $name . '(' . $imID . ').jpeg';
$file = $DestinationDirectory . $fname;
$portfile = $PortfolioDirectory . $fname;
$thumbDest = $DestinationDirectory . $ThumbPrefix . $fname;
$CreatedImage = base64_to_jpeg($data,$file);
break;
default:
die('Unsupported File!'); //output error and exit
}
array_push($imData, $imID);
array_push($imData, $name);
array_push($imData, $type);
array_push($imData, $portType);
echo json_encode($imData);
if(!cropImage($width,$height,$ThumbSquareSize,$thumbDest,$CreatedImage,$Quality,$type))
{
echo 'Error Creating thumbnail';
}
}
$stmt -> close();
} else {
/* Error */
printf("Prepared Statement Error: %s\n", $db->error);
}
/* Close connection */
$db -> close();
include '../cron/updatePortfolio.php';
}
//This function corps image to create exact square images, no matter what its original size!
function cropImage($CurWidth,$CurHeight,$iSize,$DestFolder,$SrcImage,$Quality,$type)
{
//Check Image size is not 0
if($CurWidth <= 0 || $CurHeight <= 0)
{
return false;
}
if($CurWidth>$CurHeight)
{
$y_offset = 0;
$x_offset = ($CurWidth - $CurHeight) / 2;
$square_size = $CurWidth - ($x_offset * 2);
}else{
$x_offset = 0;
$y_offset = ($CurHeight - $CurWidth) / 2;
$square_size = $CurHeight - ($y_offset * 2);
}
switch(strtolower($type))
{
case 'png':
$imageX = imagecreatefrompng ( $SrcImage );
break;
case 'jpeg':
case 'pjpeg':
case 'jpeg':
$imageX = imagecreatefromjpeg ( $SrcImage );
break;
default:
return false;
}
$NewCanves = imagecreatetruecolor($iSize, $iSize);
if(imagecopyresampled($NewCanves, $imageX, 0, 0, $x_offset, $y_offset, $iSize, $iSize, $square_size, $square_size))
{
switch(strtolower($type))
{
case 'png':
imagepng($NewCanves,$DestFolder);
break;
case 'jpeg':
case 'pjpeg':
case 'jpeg':
imagejpeg($NewCanves,$DestFolder,$Quality);
break;
default:
return false;
}
if(is_resource($NewCanves)) {
imagedestroy($NewCanves);
}
return true;
}
}
Look in the php.ini at
upload_max_filesize = 40M
post_max_size = 40M
Change 40M to your max size
The following php script creates a thumb and is part of an image gallery package. Though since a php update to version 5.6, the code doesn't work anymore because the appearance of 'eregi' in a dependent file.
Does anyone knows an alternative function for 'eregi'?
<?php
include('config.inc.php');
$C_JGALL['extentions'] = "jpg|jpeg|gif|png";
if(is_dir('themes/' . $C_JGALL['gall_theme']) && file_exists('themes/' .$C_JGALL['gall_theme'] . '/' . $C_JGALL['gall_theme'] . '.css') && file_exists('themes/' . $C_JGALL['gall_theme'] . '/' . $C_JGALL['gall_theme'] . '.conf.php'))
{
include('themes/' . $C_JGALL['gall_theme'] . '/' . $C_JGALL['gall_theme'] . '.conf.php');
}
else
{
die('corrupt theme');
}
$MaxSize = $_GET['MaxSize'];
switch ($_GET['src']) {
case 'folder':
$src = $G_JGALL['inc_path'] . 'themes/' . $C_JGALL['gall_theme'] . '/images/folder.jpg';
break;
case 'question':
$src = $G_JGALL['inc_path'] . 'themes/' . $C_JGALL['gall_theme'] . '/images/no_image.jpg';
break;
default:
$src= $_GET['src'];
break;
}
function GetExtention($filename) {
$FileNameArray = explode('.',$filename);
return($FileNameArray[count($FileNameArray)-1]);
}
$ext = GetExtention($src);
$srcSize = getImageSize($src);
$srcRatio = $srcSize[0]/$srcSize[1];
$destRatio = $MaxSize/$MaxSize;
if ($destRatio > $srcRatio) {
$MaxSize = (($C_JGALL['gall_show_filenames'] != 'y') OR isset($_GET['view'])) ? $MaxSize : $MaxSize / 100 * 80;
$destSize[1] = $MaxSize;
$destSize[0] = $MaxSize*$srcRatio;
}
else {
$destSize[0] = $MaxSize;
$destSize[1] = $MaxSize/$srcRatio;
}
if(eregi($C_JGALL['extentions'],$ext) AND (substr($srcSize['mime'],0,5) == 'image'))
if(eregi("jpg|jpeg",$ext)) {
$destImage = imagecreatetruecolor($destSize[0],$destSize[1]);
$srcImage = imagecreatefromjpeg($src);
imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
imagejpeg($destImage,'',80);
}
elseif(eregi("gif",$ext)) {
$destImage = imageCreateTrueColor($destSize[0],$destSize[1]);
$srcImage = imageCreateFromGIF($src);
imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
imageGIF($destImage,'',80);
}
elseif(eregi("png",$ext)) {
$destImage = imageCreateTrueColor($destSize[0],$destSize[1]);
$srcImage = imageCreateFromPNG($src);
imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
imagePNG($destImage,'',80);
}
else {
die('ongeldige extentie of mime-type.');
}
// --> End
?>
I would look at the PHP Documentation, as you have identified already the function has been deprecated. They do however make a recommendation to replace it;
http://php.net/manual/en/function.eregi.php
TIP eregi() is deprecated as of PHP 5.3.0. preg_match() with the i (PCRE_CASELESS) modifier is the suggested alternative.
I have inherited a function which resizes images. It works well in most cases, but for some reason, in some cases the result of resizing the image is totally different than the image initially contained. The function is as follows:
function image_resize($source, $destination, $width, $height, $resizeMode='fit', $type = 'jpeg', $options = array()) {
$defaults = array(
'output' => 'file',
'isFile' => true,
'quality' => '100',
'preserveAnimation' => false,
'offsetTop' => 0,
'offsetLeft' => 0,
'offsetType' => 'percent'
);
foreach ($defaults as $k => $v) {
if (!isset($options[$k])) {
$options[$k] = $v;
}
}
if ($options['isFile']) {
$image_info = getimagesize($source);
$image = null;
switch ($image_info[2]) {
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($source);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($source);
break;
case IMAGETYPE_GIF:
$image = imagecreatefromgif($source);
break;
case IMAGETYPE_BMP:
$image = imagecreatefromwbmp($source);
break;
default :
return false;
}
} else {
$image = imagecreatefromstring($source);
}
//we have an image resource
$iwidth = imagesx($image);
$iheight = imagesy($image);
//We need $width and $height for this call
if (QM::isAcceptableProfilePhotoSize($width, $height) == false)
{
throw new Exception("Size of ".$width."x".$height." is not supported");
}
//determine ratios
$wratio = $width / $iwidth;
$hratio = $height / $iheight;
$mratio = min(array($wratio, $hratio));
$rimage = null;
switch ($resizeMode) {
case 'fit':
$rimage = imagecreatetruecolor($iwidth * $mratio, $iheight * $mratio);
$image = imagecopyresampled($rimage, $image, 0, 0, 0, 0, $iwidth * $mratio, $iheight * $mratio, $iwidth, $iheight);
break;
case 'crop':
$rratio = $width / $height;
if ($rratio < 1) {
$nwidth = $iwidth;
$nheight = $iwidth * 1/$rratio;
if ($nheight>$iheight) {
$nwidth = $nwidth*$iheight/$nheight;
$nheight = $iheight;
}
} else {
$nwidth = $iheight*$rratio;
$nheight = $iheight;
if ($nwidth>$iwidth) {
$nheight = $nheight*$iwidth/$nwidth;
$nwidth = $iwidth;
}
}
switch ($options['offsetType']) {
case 'percent':
$sx = ($iwidth-$nwidth)*$options['offsetLeft']/100;
$sy = ($iheight-$nheight)*$options['offsetTop']/100;
break;
default :
return false;
}
$rimage = imagecreatetruecolor($width, $height);
$image = imagecopyresampled($rimage, $image, 0, 0, $sx, $sy, $width, $height, $nwidth, $nheight);
break;
default :
return false;
break;
}
if (!is_writeable(dirname($destination))) {
throw new Exception(getcwd(). "/" .dirname($destination)." is not writeable");
}
switch ($options['output']) {
case 'file':
switch ($image_info[2]) {
case IMAGETYPE_JPEG:
return imagejpeg($rimage, $destination, $options['quality']);
case IMAGETYPE_PNG:
return imagepng($rimage, $destination, 0);
case IMAGETYPE_GIF:
return imagegif($rimage, $destination);
case IMAGETYPE_BMP:
return imagejpeg($rimage, $destination, $options['quality']);
default :
return false;
break;
}
return true;
break;
default :
return false;
break;
}
}
Example image causing the problem:
This image is successfully uploaded, but when I try to resize it, the resulting image is:
I call the function this way:
image_resize($ofile, $cfile, $width, $height, 'crop', 'jpeg');
Where $ofile is the original file, $cfile is the planned destination, $width is the desired width (90 in this case), $height is the desired height (90 in this case), 'crop' is the selected strategy and 'jpeg' is a certain $type value, which is unused in the function (as I have mentioned, I have inherited the code). Also, the only example where the problem could be reproduced is the attached image, which is a png, other png files are uploaded correctly, so I do not understand the cause of the issue and do not know how to solve it. Can anybody describe the cause of the problem? I have searched and experimented for a long while without achieving success.
i tried your "image_resize" function with your bird picture, and it works perfectly fine on my computer,
whether i set the source image to jpg or png, it works as expected :
However why not choosing "fit" instead of "crop" like so :
image_resize($ofile, $cfile, $width = 90, $height = 90, 'fit', 'jpeg');
Edit: based on other people's issues about getting black image after resizing PNG, this would be the correction:
function image_resize($source, $destination, $width, $height, $resizeMode='fit', $type = 'jpeg', $options = array()) {
$defaults = array(
'output' => 'file',
'isFile' => true,
'quality' => '100',
'preserveAnimation' => false,
'offsetTop' => 0,
'offsetLeft' => 0,
'offsetType' => 'percent'
);
foreach ($defaults as $k => $v) {
if (!isset($options[$k])) {
$options[$k] = $v;
}
}
if ($options['isFile']) {
$image_info = getimagesize($source);
$image = null;
switch ($image_info[2]) {
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($source);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($source);
break;
case IMAGETYPE_GIF:
$image = imagecreatefromgif($source);
break;
case IMAGETYPE_BMP:
$image = imagecreatefromwbmp($source);
break;
default :
return false;
}
} else {
$image = imagecreatefromstring($source);
}
//we have an image resource
$iwidth = imagesx($image);
$iheight = imagesy($image);
//determine ratios
$wratio = $width / $iwidth;
$hratio = $height / $iheight;
$mratio = min(array($wratio, $hratio));
$rimage = null;
switch ($resizeMode) {
case 'fit':
$rimage = imagecreatetruecolor($iwidth * $mratio, $iheight * $mratio);
imagealphablending( $rimage, false );
imagesavealpha( $rimage, true );
$image = imagecopyresampled($rimage, $image, 0, 0, 0, 0, $iwidth * $mratio, $iheight * $mratio, $iwidth, $iheight);
break;
case 'crop':
$rratio = $width / $height;
if ($rratio < 1) {
$nwidth = $iwidth;
$nheight = $iwidth * 1/$rratio;
if ($nheight>$iheight) {
$nwidth = $nwidth*$iheight/$nheight;
$nheight = $iheight;
}
} else {
$nwidth = $iheight*$rratio;
$nheight = $iheight;
if ($nwidth>$iwidth) {
$nheight = $nheight*$iwidth/$nwidth;
$nwidth = $iwidth;
}
}
switch ($options['offsetType']) {
case 'percent':
$sx = ($iwidth-$nwidth)*$options['offsetLeft']/100;
$sy = ($iheight-$nheight)*$options['offsetTop']/100;
break;
default :
return false;
}
$rimage = imagecreatetruecolor($width, $height);
imagealphablending( $rimage, false );
imagesavealpha( $rimage, true );
$image = imagecopyresampled($rimage, $image, 0, 0, $sx, $sy, $width, $height, $nwidth, $nheight);
break;
default :
return false;
break;
}
if (!is_writeable(dirname($destination))) {
throw new Exception(getcwd(). "/" .dirname($destination)." is not writeable");
}
switch ($options['output']) {
case 'file':
switch ($image_info[2]) {
case IMAGETYPE_JPEG:
return imagejpeg($rimage, $destination, $options['quality']);
case IMAGETYPE_PNG:
return imagepng($rimage, $destination, 0);
case IMAGETYPE_GIF:
return imagegif($rimage, $destination);
case IMAGETYPE_BMP:
return imagejpeg($rimage, $destination, $options['quality']);
default :
return false;
break;
}
return true;
break;
default :
return false;
break;
}
}
I'm having a black area at my output imagecopyresized() thumbnail image.
My code:
function thumbImage($src){
/* thumb */
list($height, $width) = getimagesize($src);
$rel_difference_thumb = array('width'=>0, 'height'=>0);
if($width > 79) { $rel_difference_thumb['width'] = ($width-79)/79; }
if($height > 105) { $rel_difference_thumb['height'] = ($height-105)/105; }
asort($rel_difference_thumb);
$newwidth_thumb = $width/(1+end($rel_difference_thumb));
$newheight_thumb = $height/(1+end($rel_difference_thumb));
$newwidth_thumb = round($newwidth_thumb);
$newheight_thumb = round($newheight_thumb);
$jpeg_quality_thumb = 90;
$thumbloc = 'images/users/privAlbum/thumb/'.$USER . md5(uniqid()) . '.jpg';
switch(exif_imagetype($src)) {
case IMAGETYPE_GIF:
$img_r_thumb = imagecreatefromgif($src);
break;
case IMAGETYPE_JPEG:
$img_r_thumb = imagecreatefromjpeg($src);
break;
case IMAGETYPE_PNG:
$img_r_thumb = imagecreatefrompng($src);
break;
default:
echo json_encode(array('error' => 'Ingen bild!'));
exit(0);
break;
}
$dst_r_thumb = ImageCreateTrueColor( $newwidth_thumb, $newheight_thumb );
imagecopyresized($dst_r_thumb, $img_r_thumb, 0, 0, 0, 0, $newwidth_thumb , $newheight_thumb, $width, $height);
if( imagejpeg($dst_r_thumb,$thumbloc,$jpeg_quality_thumb) ) {
return true;
}
imagedestroy($img_r_thumb);
}
Why is this happening? How can I fix this?
list($height, $width) = getimagesize($src); should be list($width, $height) = getimagesize($src);
as said on the manual on getimagesize :
Returns an array with 7 elements:
Index 0 and 1 contains respectively
the width and the height of the image.