コード例 #1
0
function uploadTempImage($courseID)
{
    // UPLOADING IMAGE
    $allowedExts = array("jpeg", "jpg", "JPG", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    $showAlert = false;
    if (($_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/pjpeg" || $_FILES["file"]["type"] == "image/x-png" || $_FILES["file"]["type"] == "image/png") && in_array($extension, $allowedExts)) {
        if ($_FILES["file"]["error"] > 0) {
            echo 'Return Code: ' . $_FILES["file"]["error"] . '<br>';
        } else {
            if ($extension === "png") {
                function png2jpg($originalFile, $outputFile, $quality)
                {
                    $image = imagecreatefrompng($originalFile);
                    imagejpeg($image, $outputFile, $quality);
                    imagedestroy($image);
                }
                $originalFile = "images/" . $courseID . "." . $extension;
                $outputFile = "images/" . $courseID . ".jpg";
                $quality = "95";
                png2jpg($originalFile, $outputFile, $quality);
            }
            move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $courseID . "." . $extension);
            $size = getimagesize("images/" . $courseID . ".jpg");
            $imageWidth = $size[0];
            $imageHeight = $size[1];
            // TEMPLATE ARRAY (templateName, minWidth,minHeight, ratioWidth,ratioHeight)
            $templates = $GLOBALS['templates'];
            // RATIO ARRAY (ratioX, ratioY)
            $ratios = $GLOBALS['ratios'];
            echo "<script>\n\t\t\t\t\t\t\$(window).load(function(){\n\n\t\t\t\t\t\t    var jcrop_api;\n\t\t\t\t\t\t    var i, ac;\n\t\t\t\t\t\t    var originalWidth = " . $imageWidth . ",\n\t\t\t\t\t\t        originalHeight = " . $imageHeight . ",\n\t\t\t\t\t\t        aspectRatio = 0,\n\t\t\t\t\t\t        displayHeight = 0,\n\t\t\t\t\t\t        displayWidth = 0;\n\n\t\t\t\t\t\t    initJcrop();\n\n\t\t\t\t\t\t    function initJcrop()//{{{\n\t\t\t\t\t\t        {\n\t\t\t\t\t\t            \$('#cropbox').Jcrop({\n\t\t\t\t\t\t                onSelect: updateCoords,\n\t\t\t\t\t\t                boxWidth: 630, \n\t\t\t\t\t\t                boxHeight: 500\n\t\t\t\t\t\t            }, function() {\n\t\t\t\t\t\t                jcrop_api = this;\n\t\t\t\t\t\t            });\n\t\t\t\t\t\t            // jcrop_api = \$.Jcrop('#cropbox');\n\n\t\t\t\t\t\t            \$('#can_click,#can_move,#can_size')\n\t\t\t\t\t\t            .attr('checked','checked');\n\n\t\t\t\t\t\t            \$('#ar_lock,#size_lock,#bg_swap').attr('checked',false);\n\n\t\t\t\t\t\t        }\n\t\t\t\t\t\t    //}}}\n\n\n\t\t\t\t\t\t    // A handler to kill the action\n\t\t\t\t\t\t    // Probably not necessary, but I like it\n\t\t\t\t\t\t    function nothing(e) {\n\t\t\t\t\t\t        e.stopPropagation();\n\t\t\t\t\t\t        e.preventDefault();\n\t\t\t\t\t\t        return false;\n\t\t\t\t\t\t    }\n\t\t\t\t\t\t    function updateCoords(c) {\n\t\t\t\t\t\t        \$('#x').val(c.x);\n\t\t\t\t\t\t        \$('#y').val(c.y);\n\t\t\t\t\t\t        \$('#w').val(c.w);\n\t\t\t\t\t\t        originalWidth = c.w;\n\t\t\t\t\t\t        \$('#h').val(c.h);\n\t\t\t\t\t\t        originalHeight = c.h;\n\t\t\t\t\t\t        aspectRatio = c.w/c.h;\n\t\t\t\t\t\t        \$('#formSubmit').removeClass('disabled');\n\t\t\t\t\t\t        if (\$('.ratio').hasClass('active')) {\n\t\t\t\t\t\t            \$('#targetWidth').val(Math.round(c.w));\n\t\t\t\t\t\t            \$('#targetHeight').val(Math.round(c.h));\n\t\t\t\t\t\t        }\n\t\t\t\t\t\t    }\n\t\t\t\t\t\t    function checkCoords()\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (parseInt(\$('#w').val())) return true;\n\t\t\t\t\t\t\t\talert('Please select a crop region then press submit.');\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t    function checkSizes(ratioString) {\n\t\t\t\t\t\t        var ratio = ratioString.split('|'),\n\t\t\t\t\t\t            themeWidth = parseInt(ratio[0], 10),\n\t\t\t\t\t\t            themeHeight = parseInt(ratio[1], 10);\n\t\t\t\t\t\t            if (imageWidth > themeWidth && imageHeight > themeHeight) {\n\t\t\t\t\t\t                return true;\n\t\t\t\t\t\t            }\n\t\t\t\t\t\t    }\n\t\t\t\t\t\t    \$('#targetWidth').focusout(function (e) {\n\t\t\t\t\t\t        var targetWidth = parseInt(\$(this).val(), 10),\n\t\t\t\t\t\t            targetHeight = targetWidth/aspectRatio;\n\n\t\t\t\t\t\t        if(targetWidth > displayWidth){\n\t\t\t\t\t\t            \$('#targetHeight').val(Math.round(targetHeight));\n\t\t\t\t\t\t        } else {\n\t\t\t\t\t\t            \$('#targetHeight').val(displayHeight);\n\t\t\t\t\t\t            \$('#targetWidth').val(displayWidth);\n\t\t\t\t\t\t        }\n\t\t\t\t\t\t    });\n\t\t\t\t\t\t    \$('#targetHeight').focusout(function (e) {\n\t\t\t\t\t\t        var targetHeight = parseInt(\$(this).val(), 10),\n\t\t\t\t\t\t            targetWidth = targetHeight*aspectRatio;\n\t\t\t\t\t\t        if(targetHeight > displayHeight){\n\t\t\t\t\t\t            \$('#targetWidth').val(Math.round(targetWidth));\n\t\t\t\t\t\t        } else {\n\t\t\t\t\t\t            \$('#targetHeight').val(displayHeight);\n\t\t\t\t\t\t            \$('#targetWidth').val(displayWidth);\n\t\t\t\t\t\t        }\n\t\t\t\t\t\t    });\n\t\t\t\t\t\t    \$('#cropForm').submit(function (e) {\n\t\t\t\t\t\t      if (\$('#h').val() === '') {\n\t\t\t\t\t\t        alert('You must select an area to crop');\n\t\t\t\t\t\t        return;\n\t\t\t\t\t\t      }\n\t\t\t\t\t\t    });\n\t\t\t\t\t\t    \$('.freeTransform').click(function (e) {\n\t\t\t\t\t\t        jcrop_api.setOptions({\n\t\t\t\t\t\t            aspectRatio: 0,\n\t\t\t\t\t\t            minSize: [ 0, 0 ]\n\t\t\t\t\t\t        });\n\t\t\t\t\t\t        jcrop_api.focus();\n\t\t\t\t\t\t        \$('.btn.active').removeClass('active');\n\t\t\t\t\t\t        \$(this).addClass('active');\n\t\t\t\t\t\t        \$('#sizeRestriction').html('No Minimum Size');\n\t\t\t\t\t\t        displayHeight = 0;\n\t\t\t\t\t\t        displayWidth = 0;\n\t\t\t\t\t\t    });\n\t\t\t\t\t";
            // Output template functions
            for ($row = 0; $row < count($templates); $row++) {
                $templateName = $templates[$row][0];
                $minWidth = $templates[$row][1];
                $minHeight = $templates[$row][2];
                $ratioX = $templates[$row][3];
                $ratioY = $templates[$row][4];
                if ($imageWidth >= $minWidth && $imageHeight >= $minHeight) {
                    echo '
							    $(".' . $templateName . '").click(function (e) {
						        e.preventDefault();
						        jcrop_api.setOptions({ 
						            aspectRatio: ' . $ratioX . '/' . $ratioY . ',
						            minSize: [' . $minWidth . ', ' . $minHeight . ']
						        });
						        jcrop_api.setSelect([ 50, 50, 100, 100 ]);
						        jcrop_api.focus();
						        $(".btn.active").removeClass("active");
						        $("#imageName").val("' . $templateName . '");
						        $(this).addClass("active");
						        $("#targetHeight").val(' . $minHeight . ');
						        $("#targetWidth").val(' . $minWidth . ');
						        $(".outputSize").hide();
						    });
							';
                } else {
                    echo '$(".' . $templateName . '").addClass("disabled btn-danger").removeClass("btn-default");
							$(".' . $templateName . '").append("<i class=\\"fa fa-ban\\"></i>");
							';
                    $showAlert = true;
                }
            }
            // Output ratio functions
            for ($row = 0; $row < count($ratios); $row++) {
                $ratioX = $ratios[$row][0];
                $ratioY = $ratios[$row][1];
                echo '
					    $(".aspectRatio_' . $ratioX . 'x' . $ratioY . '").click(function (e) {
					        e.preventDefault();
					        jcrop_api.setOptions({ aspectRatio: ' . $ratioX . '/' . $ratioY . ' });
					        jcrop_api.setSelect([ 50, 50, 350, 350 ]);
					        jcrop_api.focus();
					        $(".btn.active").removeClass("active");
					        $(".outputSize").show();
					        $(this).addClass("active");
					        $("#imageName").val("' . $temp[0] . '_' . $ratioX . 'x' . $ratioY . '");
					        displayHeight = 0;
					        displayWidth = 0;
					    });
						';
            }
            echo '});
					</script>';
            echo '
						<h3>Step 2: Crop your Image</h3>
						<div class="row-fluid">';
            if ($showAlert) {
                echo '
								<div class="alert alert-danger" style="margin-top: 20px;">
									<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
									<p><strong><i class="fa fa-ban"></i> Warning!</strong> Some themes have been disabled because your image is too small.</p>
									<p>The image you uploaded is <strong>' . $imageWidth . 'x' . $imageHeight . '</strong></p>
								</div>
							';
            }
            echo '<div id="imageWrapper">
								<img src="images/' . $courseID . '.jpg" id="cropbox"  />
							</div>
						<div id="themeSelect">
							<p><em>Choose a Theme or a Ratio:</em></p>
							<ul id="themeList" class="list-unstyled">';
            for ($row = 0; $row < count($templates); $row++) {
                $templateName = $templates[$row][0];
                $minWidth = $templates[$row][1];
                $minHeight = $templates[$row][2];
                echo '<li><a href="#" class="' . $templateName . ' btn btn-default btn-block template" ><img src="../../images/template_thumbs/' . $templateName . '.png"><span class="dimensions">' . $minWidth . 'x' . $minHeight . '</span></a></li>';
            }
            for ($ratioRow = 0; $ratioRow < count($ratios); $ratioRow++) {
                $ratioX = $ratios[$ratioRow][0];
                $ratioY = $ratios[$ratioRow][1];
                echo '<li><a href="#" class="aspectRatio_' . $ratioX . 'x' . $ratioY . ' btn btn-default btn-block ratio">' . $ratioX . ':' . $ratioY . '</a></li>';
            }
            echo '
								<li><a href="#" class="freeTransform btn btn-default btn-block ratio active">Free</a></li>
							</ul>
						</div>
						<form action="wizard_image_crop.php" method="post" onSubmit="return checkCoords();" id="cropForm">
							<input type="hidden" name="task" value="cropImage" />
							<input type="hidden" name="courseID" value="' . $courseID . '" />
							<input type="hidden" id="x" name="x" />
							<input type="hidden" id="y" name="y" />
							<input type="hidden" id="w" name="w" />
							<input type="hidden" id="h" name="h" />
							<div class="well well-sm imageFields">
								<div class="form-group">
									<label for="imageName">Image Name: </label>
									<input type="text" class="form-control" id="imageName" name="imageName" placeholder="Image Name" value="' . $temp[0] . '" style="width: 200px;">
								</div>
								<div class="form-group outputSize">
									<label>Image Output Size: </label>
									<label for="targetWidth" class="sr-only">Target Width: </label>
									<input type="text" class="form-control" id="targetWidth" name="targetWidth" style="width: 60px;"> X 
									<label for="targetHeight" class="sr-only">Target Height: </label>
									<input type="text" class="form-control" id="targetHeight" name="targetHeight" style="width: 60px;">
								</div>
							</div>
							<a href="wizard_image_crop.php?task=selectImage" class="btn btn-default" style="margin-bottom:5px;"><i class="fa fa-chevron-circle-left"></i> Pick New Image</a>
							<button type="submit" id="formSubmit" class="btn btn-primary disabled"><i class="fa fa-plus-circle"></i> Add Image</button>
							<a class="btn btn-info" data-toggle="modal" href="#modal-id"><i class="fa fa-question-circle"></i> Help</a>
						</form>
						<div class="modal fade" id="modal-id">
							<div class="modal-dialog">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
										<h4 class="modal-title">Image Crop Help</h4>
									</div>
									<div class="modal-body">
										<p>To crop and upload your image:</p>
										<ol>
											<li>Click a theme or aspect ratio</li>
											<li>Use your mouse to select the part of the image you want</li>
											<li>Change the image name (optional)</li>
											<li>Change the image output size (optional for ratios)</li>
											<li>Click &ldquo;Add Image&rdquo;</li>
										</ol>
									</div>
									<div class="modal-footer">
										<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
									</div>
								</div><!-- /.modal-content -->
							</div><!-- /.modal-dialog -->
						</div><!-- /.modal -->
							';
        }
    } else {
        echo '<div>
						<div class="alert alert-danger">
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<strong>Error!</strong> Invalid file
						</div>
						<a href="wizard_image_crop.php?task=selectImage" class="btn btn-default"><i class="fa fa-chevron-circle-left"></i> Go Back</a>
					</div>';
    }
}
コード例 #2
0
function uploadTempImage($courseID)
{
    // UPLOADING IMAGE
    $allowedExts = array("jpeg", "jpg", "JPG", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    if (($_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/pjpeg" || $_FILES["file"]["type"] == "image/x-png" || $_FILES["file"]["type"] == "image/png") && in_array($extension, $allowedExts)) {
        if ($_FILES["file"]["error"] > 0) {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        } else {
            if ($extension === "png") {
                function png2jpg($originalFile, $outputFile, $quality)
                {
                    $image = imagecreatefrompng($originalFile);
                    imagejpeg($image, $outputFile, $quality);
                    imagedestroy($image);
                }
                $originalFile = "images/" . $courseID . "." . $extension;
                $outputFile = "images/" . $courseID . ".jpg";
                $quality = "95";
                png2jpg($originalFile, $outputFile, $quality);
            }
            move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $courseID . "." . $extension);
            $size = getimagesize("images/" . $courseID . ".jpg");
            $imageWidth = $size[0];
            $imageHeight = $size[1];
            if ($imageHeight < '256' || $imageWidth < '860') {
                echo '<div style="margin-left:20px;"><p>Image is too small. The minimum size is 860 x 256px.</p>
							<a href="wizard_image_crop.php?task=selectImage" class="btn"><i class="fa fa-chevron-circle-left"></i> Pick New Image</a>';
                exit;
            }
            echo "<div style=\"margin-left:20px;\">\n\t\t\t\t\t\t<script language=\"Javascript\">\n\t\t\t\t\t\t\t\$(function(){\n\t\t\t\t\t\t\t\t\$('#cropbox').Jcrop({\n\t\t\t\t\t\t\t\t\taspectRatio: 215/64,\n\t\t\t\t\t\t\t\t\tminSize: [860, 256],\n\t\t\t\t\t\t\t\t\tsetSelect:   [ 0, 100, 860, 256 ],\n\t\t\t\t\t\t\t\t\tonSelect: updateCoords,\n\t\t\t\t\t\t\t\t\tboxWidth: 630, \n\t\t\t\t\t\t\t\t\tboxHeight: 500\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tfunction updateCoords(c)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\$('#x').val(c.x);\n\t\t\t\t\t\t\t\t\$('#y').val(c.y);\n\t\t\t\t\t\t\t\t\$('#w').val(c.w);\n\t\t\t\t\t\t\t\t\$('#h').val(c.h);\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tfunction checkCoords()\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (parseInt(\$('#w').val())) return true;\n\t\t\t\t\t\t\t\talert('Please select a crop region then press submit.');\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t</script>\n\t\t\t\t\t\t<!-- This is the image we're attaching Jcrop to -->\n\t\t\t\t\t\t<img src=\"images/" . $courseID . ".jpg\" id=\"cropbox\" />\n\n\t\t\t\t\t\t<!-- This is the form that our event handler fills -->\n\t\t\t\t\t\t<form action=\"wizard_image_crop.php\" method=\"post\" onSubmit=\"return checkCoords();\">\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"task\" value=\"cropImage\" />\n\t\t\t\t\t\t\t<input type=\"hidden\" name=\"courseID\" value=\"" . $courseID . "\" />\n\t\t\t\t\t\t\t<input type=\"hidden\" id=\"x\" name=\"x\" />\n\t\t\t\t\t\t\t<input type=\"hidden\" id=\"y\" name=\"y\" />\n\t\t\t\t\t\t\t<input type=\"hidden\" id=\"w\" name=\"w\" />\n\t\t\t\t\t\t\t<input type=\"hidden\" id=\"h\" name=\"h\" />\n\t\t\t\t\t\t\t<button type=\"submit\" class=\"btn\"><i class=\"fa fa-plus-circle\"></i> Add Image</button>\n\t\t\t\t\t\t\t<a href=\"wizard_image_crop.php?task=selectImage\" class=\"btn\"><i class=\"fa fa-chevron-circle-left\"></i> Pick New Image</a>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t</div>";
        }
    } else {
        echo '<p style="margin-left:20px">Invalid file</p><p style="margin-left:20px"><a href="wizard_image_crop.php?task=selectImage" class="btn">Go Back</a></p>';
    }
}
コード例 #3
0
ファイル: printPDF.php プロジェクト: rahool/maplocator
function printFPDF($pdfobj){

	require('fpdf/fpdf.php');

	$DIRPATH = $_SERVER['SCRIPT_FILENAME'];

	// remove the file name and append the new directory name
	if (PHP_OS == "WINNT" || PHP_OS == "WIN32") {
		$pos1 = strrpos($DIRPATH,'\\');
		$DIRPATH= substr($DIRPATH,0,$pos1)."\\pdf\\";
	}else{
		$pos1 = strrpos($DIRPATH,'/');
		$DIRPATH= substr($DIRPATH,0,$pos1)."/pdf/";
	}
	$pdf_FILE_NAME = session_id(). "MapLocator.pdf";
	$pdf_FILE_PATH = $DIRPATH. $pdf_FILE_NAME ;

	$pdf = new FPDF('P', 'pt', array(640,450));
	$pdf->AddPage();
	$pdf->SetFont('Arial','B',10);

	$domain = getenv("HTTP_HOST");

	//base map
	$base_url = $pdfobj->BaseUrl;
	$base_url = str_replace(' and ','&' ,$base_url);

	if (strpos($base_url,'http://') === false) {
		//since client sends only relative path a full http url needs to constructed here
		$base_url = 'http://'. $domain. $base_url;
		//echo 'here';
	}


	$base_image = createImageForPDF($base_url,$DIRPATH.'base');
	$base_image_jpeg = $DIRPATH.'base'.session_id() .'.jpeg';
	png2jpg($base_image, $base_image_jpeg, 100);

	$layerURL = $pdfobj->LayerURL;

	$layerURL = str_replace(' and ','&' ,$layerURL );

	//since client sends only relative path a full http url needs to constructed here
	$layerURL = 'http://'. $domain. $layerURL;
	$layer = $pdfobj->Layer;
	$legendURL = $pdfobj->LegendURL;
	$legendURL = 'http://'. $domain. $legendURL;
	$legendURL = str_replace(' and ','&' ,$legendURL );

	$image = createImageForPDF($layerURL,$DIRPATH.$layer);

	$image_jpeg = $DIRPATH.$layer.session_id() .'.jpeg';
	png2jpg($image, $image_jpeg, 100);

	$url = 'http://'. $domain. base_path().'ImageMerge.php?baseimage='.$base_image_jpeg.'&overlayimage='.			$image_jpeg;

	$merged_image_buff = file_get_contents($url);

	$final_image =$DIRPATH.'merge.jpeg';

	$fh = fopen($final_image,"w");
  	fwrite($fh,$merged_image_buff);
	fclose($fh);


	$pdf->Image($final_image,0,30);

	$image = createImageForPDF($legendURL,$DIRPATH.$layer.'_legend');
	$image_jpeg = $DIRPATH.$layer.'_legend'.session_id() .'.jpeg';
	png2jpg($image, $image_jpeg, 100);
	$size = getimagesize($image);
	$width = $size[0];
	$height = $size[1];



	$pdf->sety(25);
	$pdf->Cell(0,0,"Layer Name: ". $pdfobj->LayerName);


	$top_scale = $pdfobj->TopScale;
	$bottom_scale = $pdfobj->BottomScale;


	$pdf->Text(0,430,"Scalebar: ");
	$pdf->Text(50,430,"| ".$top_scale." |");
	$pdf->Text(50,430,"  _____ ");
	$pdf->Text(50,440,"| ".$bottom_scale." |");
	$pdf->Text(475,445,"Created by Map Locator");


	if($width < 100){//show legend on the map/same page
		$pdf->Image($image_jpeg,640 - $width,30);
		$pdf->sety(20);
		$pdf->setX(-75);
		$pdf->Cell(20,10,"Legend ");
	}else{//show legend on the next page
		$pdf->AddPage();
		$pdf->Image($image_jpeg,0,30);
		$pdf->sety(20);
		$pdf->setX(5);
		$pdf->Cell(20,10,"Legend ");
	}



	$pdf->Output($pdf_FILE_PATH,'F');
	$pdf->Close();
	return $pdf_FILE_NAME;


}
コード例 #4
0
ファイル: png2jpg.php プロジェクト: silentred/learning-path
<?php

// Quality is a number between 0 (best compression) and 100 (best quality)
function png2jpg($originalFile, $outputFile, $quality = 50)
{
    $image = imagecreatefrompng($originalFile);
    $bg = imagecreatetruecolor(imagesx($image), imagesy($image));
    imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
    imagealphablending($bg, TRUE);
    imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
    imagedestroy($image);
    //$quality = 50; // 0 = worst / smaller file, 100 = better / bigger file
    imagejpeg($bg, $outputFile, $quality);
    imagedestroy($bg);
}
$fireDir = '/home/jason/projects/product-img/';
$files = scandir($fireDir);
foreach ($files as $file) {
    if (is_file($file)) {
        $inputFile = $fireDir . $file;
        $info = pathinfo($file);
        $outputFile = $fireDir . $info['filename'] . '.jpg';
        if (isset($info['extension']) && $info['extension'] == 'png') {
            png2jpg($inputFile, $outputFile, 100);
        }
    }
}
コード例 #5
0
 public function compressPNG()
 {
     $tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
     $file_name = pathinfo($this->name, PATHINFO_FILENAME);
     $im = imagecreatefrompng($this->tmp_name);
     if (!check_transparent($im)) {
         png2jpg($this->tmp_name, $tmp_dir . '/' . $file_name . '.jpg');
         $this->compressJPEG($tmp_dir . '/' . $file_name . '.jpg', $file_name . '.png');
         $this->name = $file_name . '.png';
     }
 }
コード例 #6
0
ファイル: index.php プロジェクト: x-f/dl-fldigi-xmlrpc
 list($width) = @getimagesize($wf_src);
 if ($width > 100) {
     if (!isset($_GET['c'])) {
         $wf = file_get_contents($wf_src);
         ob_start("ob_gzhandler");
         header('Accept-Encoding: gzip');
         if (isset($_GET['b'])) {
             echo base64_encode($wf);
         } else {
             header("Content-type: image/png");
             echo $wf;
         }
         ob_flush();
     } else {
         //copy($wf_src, dirname(__FILE__) . "/wf-" . $_GET['wf'] . "-web.png");
         png2jpg($wf_src, dirname(__FILE__) . "/wf-" . $_GET['wf'] . "-web.jpg", 80);
         if (!isset($_GET['a'])) {
             $wf = file_get_contents(dirname(__FILE__) . "/wf-" . $_GET['wf'] . "-web.jpg");
             header("Content-type: image/jpeg");
             echo $wf;
         } else {
             echo ".";
         }
     }
 } else {
     // invalid image
     if (isset($_GET['c'])) {
         if (!isset($_GET['a'])) {
             error_log($_GET['wf'] . ": serving cached");
             $wf = file_get_contents(dirname(__FILE__) . "/wf-" . $_GET['wf'] . "-web.jpg");
             header("Content-type: image/jpeg");