diff --git a/doc/src/set.txt b/doc/src/set.txt
index 6b59bf1332c2868bd63e256c76bd6949f76ddfcf..0b428d56edcc9e4cc495148e1ffb6e5ff3abb66a 100644
--- a/doc/src/set.txt
+++ b/doc/src/set.txt
@@ -80,6 +80,7 @@ keyword = {type} or {type/fraction} or {mol} or {x} or {y} or {z} or \
     value can be an atom-style variable (see below)
   {image} nx ny nz
     nx,ny,nz = which periodic image of the simulation box the atom is in
+    any of nx,ny,nz can be an atom-style variable (see below)
   {bond} value = bond type for all bonds between selected atoms
   {angle} value = angle type for all angles between selected atoms
   {dihedral} value = dihedral type for all dihedrals between selected atoms
diff --git a/src/set.cpp b/src/set.cpp
index 4ed07d423b112fd59c51ee8e3f24c73dbe8ab1b3..b97a96167c623f22fa8533e37527b869ab09d858 100644
--- a/src/set.cpp
+++ b/src/set.cpp
@@ -327,15 +327,18 @@ void Set::command(int narg, char **arg)
       ximageflag = yimageflag = zimageflag = 0;
       if (strcmp(arg[iarg+1],"NULL") != 0) {
         ximageflag = 1;
-        ximage = force->inumeric(FLERR,arg[iarg+1]);
+        if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) varparse(arg[iarg+1],1);
+        else ximage = force->inumeric(FLERR,arg[iarg+1]);
       }
       if (strcmp(arg[iarg+2],"NULL") != 0) {
         yimageflag = 1;
-        yimage = force->inumeric(FLERR,arg[iarg+2]);
+        if (strstr(arg[iarg+2],"v_") == arg[iarg+2]) varparse(arg[iarg+2],2);
+        else yimage = force->inumeric(FLERR,arg[iarg+2]);
       }
       if (strcmp(arg[iarg+3],"NULL") != 0) {
         zimageflag = 1;
-        zimage = force->inumeric(FLERR,arg[iarg+3]);
+        if (strstr(arg[iarg+3],"v_") == arg[iarg+3]) varparse(arg[iarg+3],3);
+        else zimage = force->inumeric(FLERR,arg[iarg+3]);
       }
       if (ximageflag && ximage && !domain->xperiodic)
         error->all(FLERR,
@@ -789,6 +792,9 @@ void Set::set(int keyword)
       int xbox = (atom->image[i] & IMGMASK) - IMGMAX;
       int ybox = (atom->image[i] >> IMGBITS & IMGMASK) - IMGMAX;
       int zbox = (atom->image[i] >> IMG2BITS) - IMGMAX;
+      if (varflag1) ximage = static_cast<int>(xvalue);
+      if (varflag2) yimage = static_cast<int>(yvalue);
+      if (varflag3) zimage = static_cast<int>(zvalue);
       if (ximageflag) xbox = ximage;
       if (yimageflag) ybox = yimage;
       if (zimageflag) zbox = zimage;