Page 1 of 1

not resizing or writing out new file

Posted: 2014-11-25T22:37:08-07:00
by smroczek
output
18 fromfile is /home/vhosts/greatgrow.com/httpdocs/backoffice/tmp/57575899.jpg
tofile is /home/vhosts/greatgrow.com/httpdocs/backoffice/documents/picture/picgrp0001/img_0001_0001.jpg

Code: Select all

function resizepicture($size,$fromfile,$tofile,$quality=100,$JPEG_FileName)
{ 

// (" 9 fromfile is $fromfile fromfile is $fromfile<br>");

	$quality=100; // <-- unnecessary, since that is the default in the function definition above

	 //  (" 13 size is $size<br> fromfile is $fromfile<br> tofile is $tofile <br>"); 
	//die; 
	
	$fromfile = formatFileName($fromfile);
	$tofile = formatFileName($tofile);
	print   ("<br> 18  fromfile is $fromfile <br> tofile is $tofile <br><br>");

	if (!(is_file($fromfile) )) 
	{
		die("First argument to resize function references a file (\$fromfile\") that does not exist,"
			." in this script.\n");
	}
	
	if (!(is_readable($fromfile))) 
	{
		die("First argument to resize function references a file (\"$fromfile\") "
			." or is not readable by this script.\n");
	}
	$workfile ='/tmp/'.$JPEG_FileName; 
	//$workfile =$fromfile;
	$strsize = (filesize($fromfile)); 
	$currentimagesize = getimagesize($fromfile);

	$Picimage_width = $currentimagesize[0];
	$Picimage_height= $currentimagesize[1];
		
	$sizefactor = 1.0;
	if ($Picimage_height > $Picimage_width) 
	{ $sizefactor = (double) ($size / $Picimage_height);}
	else 
	{$sizefactor = (double) ($size / $Picimage_width) ;}

	$newsf = round($sizefactor ,3);
  
  	if ($newsf == 1.001) 	{$sizefactor = 1.0;   }
	if ($sizefactor == 1.00013908)  	{$sizefactor = 1.0;  }
	 
	if ($sizefactor !== 1.0) {
		$newwidth = (int) ($Picimage_width * $sizefactor);
		$newheight = (int) ($Picimage_height * $sizefactor); }
		
$resource= NewMagickWand();  /* create a new MagickWand resource */

$status = MagickReadImage($resource, $workfile );
if ($status == MagickFalse) {print(" 56 Unable to Read $workfile<br> \n");}
if ($status == MagickTrue) {print(" 57 able to Read $workfile<br> \n");}

$status = MagickTransformImage($resource, NULL, $newwidth . "x" . $newheight);
if ($status == MagickFalse) {print(" 94 Unable to TransformImage  $workfile<br> \n");}

$status = MagickSetImageCompressionQuality($resource, $quality);
if ($status == MagickFalse) {print(" Unable to Compression Quality  $workfile<br> \n");}
	
$status = MagickSetImageFormat($resource, 'JPEG');
if ($status == MagickFalse) {print(" Unable to image format  $workfile<br> \n");}
	
$status =MagickWriteImage($resource, $tofile);
if ($status == MagickFalse) {print(" Unable to write image    $tofile<br> \n");}

 print("70 status is $status tofile is $tofile <br>");

DestroyMagickWand($resource);
	
	//("<br> ok <br>");
	
}