Attempting to optimize a pixel reading and outputing function - php

$img = imagecreatefrompng("img/".$image);
$w = imagesx($img);
$h = imagesy($img);
$pixelcount = 0;
echo "<div id='container' style='width: {$w}px; height: {$h}px;'>\r\n";
for($y=0;$y<$h;$y++) {
for($x=0;$x<$w;$x++) {
$rgb = imagecolorat($img, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$alpha = (imagecolorat($img,$x,$y) & 0x7F000000) >> 24;
if($alpha == 127)
$newcolor = "transparent";
else
$newcolor = sprintf('#%02X%02X%02X', $r, $g, $b);
if(isset($prevcolor) && strcmp($newcolor, $prevcolor) != 0)
{
echo "<div style='background: {$prevcolor}; height: 1px; width: {$pixelcount}px; float: left;'></div>\r\n";
$pixelcount = 0;
}
$prevcolor = $newcolor;
$pixelcount++;
}
echo "<div style='background: {$prevcolor}; height: 1px; width: {$pixelcount}px; float: left;'></div>\r\n";
unset($prevcolor);
$pixelcount = 0;
}
echo "</div>\r\n";
Here's a link to the tool in its current form.
http://schnell.dreamhosters.com/folio/pixelread.php?image=link.png
Mousewheel up, I and +/= key zoom in. Mousewheel down, O and -/_ key zoom out. No need to focus on any particular element, the entire document registers a keystroke/mousewheel.
Edit - Thanks for the fix that that one problem, guys! Got a new one now though. If you go to the tool and attempt to blow it up by zooming in, the sprite just falls apart. If you leave it alone and do nothing, it looks fine. What's weird too is that you can't fix the picture by reseting the size, it will stay messed up until you refresh the page.
Edit2 - Found the source of the trouble.
function resize(width, height)
{
$('div#container').css('height', factor * height);
$('div#container').css('width', factor * width);
$('div#container > div').css('height', factor).css('width', function(i, val) { return parseInt(val * factor) + 'px'; });
$('div#container').css('margin-top', ($(window).height() - $('div#container').height())/2 + "px");
}
Width isn't getting multiplied by 'factor' for some reason. I'm trying to do it in such a way that jQuery does it to each and every child div, basing the new width off the old, without having to do a huge for loop or anything, but nothing I'm coming up with is working.
Edit3 - Finally got it working! I just stored the original lengths of each div as the 'id' attribute in each and then access that when it comes time to resize everything. Thanks to everyone who put up with this and stuck with me to see it through. I swear the resizing is smoother than before! :D

Your code isn't resetting the pixel count after each run of colour. I think you need this:
if(isset($prevcolor) && strcmp($hex, $prevcolor) != 0) {
echo "<div style='background: {$prevcolor}; height: 1px; width: {$pixelcount}px; float: left;'></div>\r\n";
$pixelcount = 0;
}

I believe that the problem lies in the fact that, in the inner loop, you never reset $pixelcount after you use it. Consequently, it's just an accumulation of the total pixels of the row, meaning that each time you print you get a progressively larger width.
Based on your description, you'd want to reset it when you switch colours:
if(isset($prevcolor) && strcmp($hex, $prevcolor) != 0) {
echo "<div style='background: {$prevcolor}; height: 1px; width: {$pixelcount}px; float: left;'></div>\r\n";
$pixelcount = 0; // Incremented back to 1 below
}
The resizing problem comes from the resize function, where width is now set inappropriately because the base width of each block is no longer 1:
var cssObj = {
'width' : factor, // This factor needs to be multiplied by the original width
'height' : factor
};
$('div#container > div').css(cssObj);
I'm sure there's a better way to do this, but you could get the width upfront:
$('div#container').css('margin-top',
($(window).height() - $('div#container').height())/2 + "px");
$('div#container > div').each(function() {
$(this).data('originalWidth', $(this).width());
});
...then in the resize function:
$('div#container > div')
.css('height', factor)
.css('width', function() {
return $(this).data('originalWidth') * factor;
});

Related

how to make a php file work more than once

I have a little generator, It generate a random phone numbers and here is my code.
<?php
limit_phone = 8; //limit phone number
$randomphone = substr(str_shuffle(str_repeat("0123456789", $limit_phone)), 0, $limit_phone); //random numbers
$randomphonecomp = array('010','011','012','015'); // company
$randomphonecomp1 = array_rand($randomphonecomp);
$phonefinaal = $randomphonecomp[$randomphonecomp1] . $randomphone;
echo $phonefinaal. "<br>";
?>
What I want is, when i run this file to work more than one time, means that i want this file to generate automatically with out stop until i stop the page from the browser
You can use a loop to generate specified number of phone numbers, Don't use an infinite loop, it will kill your browser and you will not able to stop the loop.
<?php
$total_numbers = 100;
$i=1;
while($i<=$total_numbers){
$limit_phone = 8; //limit phone number
$randomphone = substr(str_shuffle(str_repeat("0123456789", $limit_phone)), 0, $limit_phone); //random numbers
$randomphonecomp = array('010','011','012','015'); // company
$randomphonecomp1 = array_rand($randomphonecomp);
$phonefinaal = $randomphonecomp[$randomphonecomp1] . $randomphone;
echo $phonefinaal. "<br>";
$i++;
}
?>
As #bcperth said, you most likely need to generate phone numbers using Javascript in the page, it could be something like this:
var divNumbers = document.getElementById("numbers")
var btnStop = document.getElementById("stop")
function generate() {
var randomphone = ""
for(var i = 0; i < 8; ++i) randomphone += Math.floor(Math.random()*10)
var randomcomp = ['010', '011', '012', '015'][Math.floor(Math.random()*4)] + ""
divNumbers.innerHTML += randomcomp + randomphone + "<br>"
}
generate() // first generated number
var intervalGen = setInterval(generate, 2000) // others generated number
function stop() {
clearInterval(intervalGen)
}
btnStop.addEventListener("click", stop)
#stop {
border: 1px solid grey;
padding: 2px 5px;
cursor: pointer;
}
<span id="stop"> STOP </span>
<div id="numbers"></div>
Documentation:
setInterval() - Web APIs | MDN
Math.random() - JavaScript | MDN
Math.floor() - JavaScript | MDN

PHP to ouput html code for text gradient or "rainbow text" of sorts

Let me start by saying I have scoured the internet all day looking for a solution, and I'm just stumped. I managed to find enough code snippets to put together an "almost" working version of what I need -- but to be completely honest I'm just lost when it comes to how to make it work.
Here's what I'm trying to do:
I'm trying to make a php function that will take 2 or maybe 3 colors, and apply them as a smooth gradient to a text string. I need the function to output the actual HTML code for the gradient. How I envision it working is: it will take the message string and split it into the individual characters, and then color each character in such a way that when it's displayed with the html output, it will look like a smooth fade from one color to the next. Right now I'm testing the function with 2 colors that I've just defined inside it, (FF0000 and 0000FF). I can't seem to get it to color the entire string. It seems to grab the first letter, and do part of the transition, and then just stop.
Here's a screenshot of what I'm trying to make it look like:
Here's a screenshot of what mine comes out looking like (including the html output for explanation sake)
Here's the code that I'm using:
<?php
function html2rgb($color)
{
if ($color[0] == '#')
$color = substr($color, 1);
if (strlen($color) == 6)
list($r, $g, $b) = array($color[0].$color[1],
$color[2].$color[3],
$color[4].$color[5]);
elseif (strlen($color) == 3)
list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
else
return false;
$r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
return array($r, $g, $b);
}
function rgb2html($r, $g=-1, $b=-1)
{
if (is_array($r) && sizeof($r) == 3)
list($r, $g, $b) = $r;
$r = intval($r); $g = intval($g);
$b = intval($b);
$r = dechex($r<0?0:($r>255?255:$r));
$g = dechex($g<0?0:($g>255?255:$g));
$b = dechex($b<0?0:($b>255?255:$b));
$color = (strlen($r) < 2?'0':'').$r;
$color .= (strlen($g) < 2?'0':'').$g;
$color .= (strlen($b) < 2?'0':'').$b;
return '#'.$color;
}
echo "<h1>Result:</h1>";
$src_color = html2rgb('FF0000');
$dst_color = html2rgb('0000FF');
print_r($dst_color);
for($i=0; $i<3; $i++)
$step_color[$i] = ( $dst_color[$i] - $src_color[$i] ) / 30.30;
// step_color array contains difference between adjacent color stripes
$html_out = ''; // html code container
for($j=0; $j<60; $j++)
{
// generate color stripe code
$message = 'I am trying to make this text string fade from one color to another';
$counter = strlen($message);
$array = str_split($message);
$mycount = 0;
if($mycount < $counter){
$line = '<b><font color=" '.rgb2html($src_color).';">'.$array[$mycount].'</font></b>';
$html_out .= "{$line}"; // save color stripe to display HTML code later
$mycount = $mycount + 1;
}
echo $line; // output color stripe to browser
for($i=0; $i<1; $i++) // incrementing each color component
$src_color[$i] += $step_color[$i];
}
?>
<h1>HTML Code:</h1>
<pre><?php
// output HTML code replacing < and > with < and >
$stuff = strtr($html_out, array('&' => '&',
'<' => '<',
'>'=> '>'));
echo $stuff;
I'm fairly new to this sort of thing, so please don't be too brutal on me if my code is "arse-backwards" or poor. Can anyone point me in the right direction? I'm just at a loss for how to get it to do what I want it to do.
Thank you very much for taking the time to read this, and for any advice you can offer!
Edit: image link for bottom screenshot to make it easier to see
http://i.stack.imgur.com/vsfdQ.jpg
UPDATE -- Ok, I've re-written most of the function and I almost have it working. The issue that I'm having now is that it's repeating the entire string over and over. It is applying the fade, but not the way it's supposed to. I need it to fade from one color to the next across the string. Here is a new screenshot of what it's doing now:
Here's the link for that so you can see it easier:
http://i.stack.imgur.com/X0Pmq.jpg
Here's the new code that I'm using:
<?php
function rgb($rgb) {
$ret = '';
foreach ($rgb as $x) {
// Make sure the RGB values are 0-255...
$x = max(0, min(255, $x));
// create a 2 digit hex value for this color component...
$ret .= ($x < 16 ? '0'.dechex($x) : dechex($x));
}
return '#'.$ret;
}
// Returns a fade of $from into $to by $amount ($from and $to are RGB arrays)...
function fade($from, $to, $amount) {
$rgb = array();
// Go through the RGB values and adjust the values by $amount...
for ($i = 0; $i <= 2; $i++) {
$rgb[$i] = (($to[$i] - $from[$i]) * $amount) + $from[$i];
}
return $rgb;
}
$string = 'testing out the fade function here';
//$string1 = strlen($string);
for ($j = 0; $j < 1; $j += .01) {
$color = rgb(fade(array(255,0,0), array(0,255,0), $j));
for($i=0;$i<strlen($string);$i++){
echo "<font style='color:$color'>$string[$i]</font>";
}
}
Is anyone able to tell me how to make it print the string just ONCE, with the fade properly applied to the string?
Thank you all so much for all of your time and expertise!
Check second example as it is more of what you're looking for.
Just use php to add the html elements and their ids or classes and then use css to give the gradient.
Example:
#id_of_element { /*or class of element*/
background: -webkit-linear-gradient(left, red , blue);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
/* the following would cover other browsers...not sure about IE */
background: -webkit-linear-gradient(left, red , blue); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, red, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, red, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, red , blue); /* Standard syntax */
/* then just add the -o- or -moz- etc. */
}
Depending on which angle or direction you want to gradient to go -> just use php (and/or javascript) to alter the value of the background: -webkit-linear-gradient(direction, color1 , color2);
THE FOLLOWING IS THE CODE EXAMPLE
Try the code below as an example:
Afterwards, open the page up in a web browser. It should have text that goes from black to white.
After APPEND this to the url:
?color1=FFFFFF&color2=000000
So the full url should look something like this:
http://yoursite.com/pageName.php?color1=FFFFFF&color2=000000
Now the gradient is reversed. because color1 originally started out as #000000 but the php switched it because of the value it had from the GET request.
Here is the code example:
<?php
$textOutput = '';
?>
<?php if(isset($_GET['color1']) && isset($_GET['color2'])):
$textOutput = '';
$userFirstInput = $_GET['color1']; // these are the posts or gets you send from your form
$userSecondInput = $_GET['color2']; // these are the posts or gets you send from your form
$firstColor = $userFirstInput; // #FFFFFF for example
$secondColor = $userSecondInput; // #000000 for example
$textOutput .= '.spans{';
$textOutput .= 'background: -webkit-linear-gradient(left, #'. $firstColor . ', #'.$secondColor .');';
$textOutput .= '-webkit-background-clip: text;';
$textOutput .= '-webkit-text-fill-color: transparent;';
?>
<?php else:
$textOutput = '';
$textOutput .= '.spans{';
$textOutput .= 'background: -webkit-linear-gradient(left, #000000 , #FFFFFF);';
$textOutput .= '-webkit-background-clip: text;';
$textOutput .= '-webkit-text-fill-color: transparent;';
?>
<?php endif ?>
<!DOCTYPE html>
<html>
<head>
<style>
<?php echo $textOutput; ?>
</style>
<span class="spans">IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII</span>
</body>
</html>
If you need help getting the user input, that I can help with as well. I use ajax to send a post or get up to PHP and check/sanitize the inputs.
Why don't do like that
$string = 'My text'
$count = 0;
for($i=0,$i<=255,$i++){
for($i_i=0,$i_i<=255,$i_i++){
for($i_i_i=0,$i_i_i<=255,$i_i_i++){
echo '<span style="color:rgb('.$i.','.$i_i.','.$i_i_i.')">'.$string[$count].'</span>';
if($count == strlen($string))break;
$count++;
}
if($count == strlen($string))break;
}
if($count == strlen($string))break;
}
Or set some other values of $i... to get another colors.

Best way to generate a random background colour with php on page load

I am trying to create some code that generates a random background colour on page load, but also out puts text with a colour dependant on the background colour. EG if the background colour is dark, it will display light text.
So far I have created the following, which works - though i'm not sure if this is the best way to achieve it.
I created an array that decides at random whether the background colour should be light or dark, and have done this so I can have two alternate font colours based on the $scheme. Im sure there will be a much more dynamic way to do this?
Then I have set two more arrays listing multiple colours for both the dark and light schemes, with an elseif statement to output the relevant css.
There is a couple of things about this that i'd like to query:
1) why is the last string in an array never outputted? it make it so I have to add a blank string in every array just so the one prior isn't omitted.
2) what is the best practice to achieve this, as well as the most dynamic method.
<?php
header("Content-type: text/css; charset: UTF-8");
$input = array("dark", "light", "");
$rand_keys = array_rand($input, 2);
$scheme = $input[$rand_keys[0]];
if ($scheme == "dark") {
$darkBg = array('212a34', '383838', '000');
$rand_keys_1 = array_rand($input, 2);
$bg_colour = $darkBg[$rand_keys_1[0]];
echo 'body {background-color:#' . "$bg_colour" . '}';
echo 'h2 { color:#fff; }';
}
elseif ($scheme == "light") {
$lightBg = array('ebecee', '31a989', 'fff');
$rand_keys_2 = array_rand($input, 2);
$bg_colour = $lightBg[$rand_keys_2[0]];
echo 'body {background-color:#' . "$bg_colour" . '}' ;
echo 'h2 { color:#000; }';
}
else { echo 'body {background-color: #ef3c39;}'; }
?>
// Should probably have noted, It will be a predefined list of colours
For anyone who is interested, I have found a better method to be the following in terms of reducing the amount of code, getting a better random distribution and also more dynamic.
<?php
$bgColours = array(
"414245"=>"dark", //one
"333333"=>"dark", //two
"e25359"=>"dark", //three
"ebeced"=>"light", //six
"edd6b4"=>"light" //seven
);
$bgColour = (array_rand($bgColours,1));
$colourScheme = $bgColours[$bgColour];
if ("$colourScheme" == "dark") {
echo 'body {background-color:#' . "$bgColour" . '}';
echo 'h2 { color:#fff; }';
}
elseif ($colourScheme == "light") {
echo 'body {background-color:#' . "$bgColour" . '}' ;
echo 'h2 { color:#333333; }';
}
else { echo 'body {background-color: #ef3c39;}'; }
?>
As Dagon has said this sounds like a horrible idea for a UI but here is how I would do it:
//starts off with dark text
$textcolor = '222222';
$rand1 = rand(0,255);
$rand2 = rand(0,255);
$rand3 = rand(0,255);
$bgcolor = sprintf("%02X",$rand1) . sprintf("%02X",$rand2) . sprintf("%02X",$rand3);
$total = $rand1 + $rand2 + $rand3;
//if total is less than 400 it is most likely a darker color unless one or more color is accounting for most of the 400
if($total < 400 && $rand1 < 180 && $rand2 < 180 && $rand3 < 180) {
$textcolor = 'dddddd';
}
It isn't perfect but 99% of the time the text is readable compared to the background.
This will do the trick:
echo dechex(mt_rand(0, 0xFFFFFF));
if you want random from a set of known colors you do the following:
$colors = array($color1, $color2);
echo $colors[array_rand($colors)];

Rating system and CSS sprites

I have implemented three star rating system based on popularity count in my website, but now my client wants to change colors of those three stars (default blue) to red, blue and green which shows the (degree of) popularity.
I've implemented this star rating system using CSS sprites, where I included two star images - golden and gray, in one sprite and displaying these using some logic. Works fine for one color, but how to implement three colours for each star?
HTML
<div class="star-box">
<li>
<span class="stars"><?php echo $position;?></span>
</li>
</div>
PHP
if( !isset($_SESSION['ranking']) || $_SESSION['ranking']['points'] <= 1000 ) {
if( !isset($_SESSION['ranking']['points']) || $_SESSION['ranking']['points'] == '' ) {
$position = '0px';
$position = 0.00;
} else {
$position = ($_SESSION['ranking']['points'] * 0.14).'px';
$position = 0.75;
}
$str1 = 'class="active" ';
$str1 .= ' style="background-position:'.$position.' 9px;"';
}
if( $_SESSION['ranking']['points'] > 1000 && $_SESSION['ranking']['points'] <= 5000 ) {
if( !isset($_SESSION['ranking']['points']) || $_SESSION['ranking']['points'] == '' ) {
$position = '0px';
$position = 0.00;
} else {
$position = ($_SESSION['ranking']['points']*0.035).'px';
$position = 1.40;
}
}
jQuery
$(function() {
$('span.stars').stars();
});
$.fn.stars = function() {
return $(this).each(function() {
// get the value
var val = parseFloat($(this).html());
// make sure that the value is in (0 - 5) range, multiply to get width
val = Math.round(val * 4) / 4;
var size = Math.max(0, (Math.min(5, val))) * 16;
// create stars holder
var $span = $('<span />').width(size);
// replace the numerical value with stars
$(this).html($span);
});
}
CSS
span.stars, span.stars span {
display: block;
background: url(../../images/stars.png) 0 -16px repeat-x;
width: 50px;
height: 20px;
text-indent: -9999px;
}
span.stars span {
background-position: 0 0;
}
SPRITE IMAGE :
You could use session variables etc to control your CSS directly by using a php/css file. You could set star color, sprite position, all based on logic.
Link to your css
<link rel='stylesheet' type='text/css' href='css/style.php' />
Your css/php document
<?php
header("Content-type: text/css; charset: UTF-8");
$CSSposition = $position;
?>
span.stars span {
background-position: <?php echo $CSSposition ?>;
}
Here's a link to php/css document tutorial click here
Check this tutorial on knockout they show how to do the star rating system which you can apply to your code http://learn.knockoutjs.com/#/?tutorial=custombindings

Cannot change src of image with Javascript in some versions of Chrome

Never could have imagined that chrome would have been the browser giving me grief, but the slideshow for our new website does not function properly in some versions of Chrome.
The error occurs here:
"mainPicture.src = \''.$directory.$current_pic.'\'; setMarkerPos('.$i.')"
Claiming that I can't modify mainPicture, an id that doesn't exist.
Obviously, other browsers don't have a problem seeing this object.
All help is much appreciated!
.
You can find the page here.
Source code:
<?php
/********************************************************************
* GATHER IMAGES FROM IMAGE DIRECTORY *
********************************************************************/
// Define directory where images are stored
$directory = "../../images/slideshow/";
// Create blank array to store image names
$pic_array = array("");
$num_pics;
// Create number to define position of images in array
$counter = 0;
// Gather pictures from image directory
if(is_dir($directory))
{
// Open directory to view files
if($dh = opendir($directory))
{
// Continue while still files to view
while(($file = readdir($dh)) !== false)
{
// Stop if picture limit of 6 reached
if($counter == 6)
break;
// Gather if object found is file or directory
$file_check = filetype($directory.$file);
// If object is a file, add it to the slideshow
if ($file_check == "file")
{
$extension = substr($file, strpos($file, "."));
if ($extension == ".png" || $extension == ".jpg")
{
$pic_array[$counter] = $file;
$counter++;
}
}
}
}
}
// Determine number of pics gathered
$num_pics = count($pic_array);
?>
<html>
<head>
<link href="scripts/slideshow.css" rel="stylesheet" type="text/css">
<?php
/********************************************************************
* CONTROL BEHAVIORS OF SLIDESHOW *
********************************************************************/
?>
<!-- Begin script to control slideshow -->
<script type = "text/javascript">
var thumbTop = 450; // starting value of thumb.style.top (make sure multiple of increment)
var highestTop = 342; // highest point mask can be on screen ,-, (make sure multiple of increment)
var lowestTop = 450; // lowest point mask can be on screen ,_, (make sure multiple of increment)
var delay = 2; // speed in which slide up and down methods are called
var increment = 5; // value that thumbTop increments with each method call
var intervalUp; // interval for thumb upward movements
var intervalDown; // interval for thumb downward movements
function startThumbSlideUp()
{
window.clearInterval(intervalDown);
intervalUp = window.setInterval(thumbSlideUp,delay);
}
function startThumbSlideDown()
{
window.clearInterval(intervalUp);
intervalDown = window.setInterval(thumbSlideDown,delay);
}
function thumbSlideUp()
{
thumbTop -= increment;
if (thumbTop <= highestTop)
{
thumbTop = highestTop;
window.clearInterval(intervalUp);
}
else
thumbMask.style.top = thumbTop;
}
function thumbSlideDown()
{
// Added to fix issue where images would start from too large a height
if (thumbTop <= highestTop)
thumbTop = highestTop;
thumbTop += increment;
if (thumbTop >= lowestTop)
{
thumbTop = lowestTop;
window.clearInterval(intervalDown);
}
else
thumbMask.style.top = thumbTop;
}
// Move marker above image <pos>
function setMarkerPos(pos)
{
marker.style.left = 600 - (66 * (pos)) + 19;
}
</script>
</head>
<?php
/********************************************************************
* DISPLAY SLIDESHOW *
********************************************************************/
// Start body and make images unhighlightable
echo '<body onselectstart="return false" style="margin: 0px;">';
// Create base value to increment horizontal position of thumbnails
$curr_thumb_left = 595; // (ignore this comment) 660<width of image> - 66<width of thumb> - 10<space between side> // 660
// Create and display main (large) image and image thumbnails
echo '<div id="mask" onmouseout = "startThumbSlideDown()" onmouseover = "startThumbSlideUp();">
';
echo '<img src = "'.$directory.$pic_array[0].'" id = "mainPicture" height = "420" width = "660" style = "z-index: -1; position:absolute;"/>
';
echo '<div id="thumbMask" height="66" width="660" style="z-index: 1; top: 450px; position: absolute;">
';
echo '<img id="marker" src="images/marker.png" height="10" width="10" style="z-index: 2; top: 0px; position: absolute;" onload="setMarkerPos(0);"/>';
// Search through image array, then assign names to and display thumbnails
for ($i=0; $i < $num_pics; $i++)
{
// Point to pic in array
$current_pic = $pic_array[$i];
// Create and display image thumbnails
if ($current_pic !== "")
{
echo '<img src = "'.$directory.$current_pic.'" id = "thumb'.$i.'" height = "50" width = "50" style = "left:'.$curr_thumb_left.'px; top: 10px; border: 3px white solid; position: absolute;" onclick = "mainPicture.src = \''.$directory.$current_pic.'\'; setMarkerPos('.$i.')"/>
';
// Move left value to the left [50px width + (3px padding * 2 sides) + 10px space between = 66px]
$curr_thumb_left -= 66;
}
}
echo '</div>';
echo '</div>';
?>
</body>
</html>
Chrome doesn't make image elements available by just their "id" value; you have to use document.getElementById("mainPicture") to get a reference to the DOM element. That'll work in all browsers anyway, so it's safe to just code it that way.
You are attempting to alter the src of mainPicture as though it were a global variable:
mainPicture.src = '.....';
Try referencing mainPicture by its id instead:
document.getElementById('mainPicture').src = '......';
You're not actually setting what mainPicture is, other browsers must be guessing whereas Chrome is doing what it should. Change:
echo '<img src = "'.$directory.$current_pic.'" id = "thumb'.$i.'" height = "50" width = "50" style = "left:'.$curr_thumb_left.'px; top: 10px; border: 3px white solid; position: absolute;" onclick = "mainPicture.src = \''.$directory.$current_pic.'\'; setMarkerPos('.$i.')"/>
to
echo '<img src = "'.$directory.$current_pic.'" id = "thumb'.$i.'" height = "50" width = "50" style = "left:'.$curr_thumb_left.'px; top: 10px; border: 3px white solid; position: absolute;" onclick = "document.getElementById('mainPicture').src = \''.$directory.$current_pic.'\'; setMarkerPos('.$i.')"/>

Categories