In order to accommodate multiple types of image encryption, a multi-image encryption algorithm for 2D and 3D images is designed in this paper. After recording the type and number of images, the pixels/coordinates of multiple images are stored in a cube block and are subjected to confusion and diffusion operations. The confusion step uses the random length sequence position swapping method to swap a row (column) vector of variable length with another row (column) vector of the same length at a random position. The diffusion is done by Exclusive OR to combine pixels/coordinates at different locations with different chaotic matrices. Finally, the cipher images are output one by one. Experimental simulations and security analysis verify the effectiveness and security of the algorithm.