1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-07-24 18:21:48 +02:00

Adding testcase for #40

This commit is contained in:
Mikael Roos
2014-11-24 10:46:50 +01:00
parent 188f8cd64d
commit d4a03b70dd
4 changed files with 125 additions and 2 deletions

View File

@@ -1725,14 +1725,15 @@ class CImage
$details['src'] = $this->imageSrc;
$lastModified = filemtime($this->pathToImage);
$details['src-gmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
$details['cache'] = basename($this->cacheFileName);
$lastModified = filemtime($this->cacheFileName);
$details['cache-gmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
$details['width'] = $this->width;
$details['height'] = $this->height;
$details['aspectRatio'] = round($this->width / $this->height, 3);
return json_encode($details, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}

View File

@@ -133,6 +133,8 @@ Revision history
v0.5.x (latest)
* Improving template for tests in `webroot/tests` when testing out #40.
* Adding testcase for #40.
* Adding option `convolve` taking comma-separated list of 11 float-values, wraps and exposes `imageconvoluttion()`. #4
* Adding option `dpr, device-pixel-ratio` which defaults to 1. Set to 2 to get a twice as large image. Useful for Retina displays. Basically a shortcut to enlarge the image.
* Adding utility `cache.bash` to ease gathering stats on cache usage. #21

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 KiB

View File

@@ -0,0 +1,120 @@
<!doctype html>
<head>
<meta charset='utf-8'/>
<title>Testing img for issue 40 - no ratio</title>
<style>
body {background-color: #ccc;}
</style>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
window.getDetails = function (url, id) {
$.getJSON(url, function(data) {
element = document.getElementById(id);
element.innerHTML = "width: " + data.width + "\nheigh: " + data.height + "\naspect-ratio: " + data.aspectRatio;
});
}
</script>
</head>
<body>
<h1>Testing issue 40 - no ratio</h1>
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
$imgphp = "../img.php?src=";
$images = array(
'issue40/source.jpg',
);
$testcase = array(
'&nc&width=652&height=466',
'&nc&width=652&height=466&no-ratio',
'&nc&width=652&height=466&crop-to-fit',
'&nc&width=652&aspect-ratio=1.4',
'&nc&width=652&aspect-ratio=1.4&no-ratio',
'&nc&width=652&aspect-ratio=1.4&crop-to-fit',
);
?>
<h2>Images used in test</h2>
<p>The following images are used for this test.</p>
<?php foreach($images as $image) : ?>
<p>
<code>
<a href="img/<?=$image?>"><?=$image?></a>
<a href="<?=$imgphp . $image . '&json'?>">(json)</a>
<a href="<?=$imgphp . $image . '&verbose'?>">(verbose)</a>
</code>
<br>
<img src="<?=$imgphp . $image?>"></p>
<p></p>
<pre id="<?=$image?>"></pre>
<script type="text/javascript">window.getDetails("<?=$imgphp . $image . '&json'?>", "<?=$image?>")</script>
<?php endforeach; ?>
<h2>Testcases used for each image</h2>
<p>The following testcases are used for each image.</p>
<?php foreach($testcase as $tc) : ?>
<code><?=$tc?></code><br>
<?php endforeach; ?>
<h2>Applying testcase for each image</h2>
<?php
$ch1 = 1;
foreach($images as $image) :
?>
<h3><?=$ch1?>. Using source image <?=$image?></h3>
<p>
<code>
<a href="img/<?=$image?>"><?=$image?></a>
<a href="<?=$imgphp . $image . '&json'?>">(json)</a>
<a href="<?=$imgphp . $image . '&verbose'?>">(verbose)</a>
</code>
<br>
<img src="<?=$imgphp . $image?>">
</p>
<pre id="<?=$ch1?>"></pre>
<script type="text/javascript">window.getDetails("<?=$imgphp . $image . '&json'?>", "<?=$ch1?>")</script>
<?php
$ch2 = 1;
foreach($testcase as $tc) :
$tcId = "$ch1.$ch2";
?>
<h4>Testcase <?=$tcId?>: <?=$tc?></h4>
<p>
<code>
<a href="<?=$imgphp . $image . $tc?>"><?=$image . $tc?></a>
<a href="<?=$imgphp . $image . $tc . '&json'?>">(json)</a>
<a href="<?=$imgphp . $image . $tc . '&verbose'?>">(verbose)</a>
</code>
<br>
<img src="<?=$imgphp . $image . $tc?>">
</p>
<pre id="<?=$tcId?>"></pre>
<script type="text/javascript">window.getDetails("<?=$imgphp . $image . $tc . '&json'?>", "<?=$tcId?>")</script>
<?php $ch2++; endforeach; ?>
<?php $ch1++; endforeach; ?>