I built an admin panel which has image upload… to avoid issues for my client when adding gallery images i added some auto choosing options.
So the gallery was always
Image 1 - Portrait
Image 2 - Landscape
And that sequence just repeated over and over again, so when my server action was cropping and resizing images for them it would know if it was cropping for a portrait or a landscape end result image. This was achieved pretty easily with the following.
This made all odd numbers = 1 so it was pretty easy to do considering all odd positions were Portrait and all evens were Landscape.
Now they asked for a change, and the new order will be
Image 1 - Landscape
Image 2 - Portrait
Image 3 - Portrait
Image 4 - Landscape
And that new sequence just repeats over and over.
Is there any mathematical way like that modulo operator idea to adjust my condition to make the new sequence auto choose L,P,P,L , L,P,P,L , L,P,P,L
I can not think of a way, but hoping someone is a maths boffin.
What are your server action steps and are you using a repeat step for this? Or 4 separate resize steps?
What is image_position.value and where does it come from?
Ok i am still not sure i understand which part do you want to change? Something in the server action or something on the front end where they select the images?
If the user enters an image position i need it to auto change the orientation radio button to either Landscape or Portrait depending on the position number they chose.
Image
Position
Orientation
Image01.jpg
1
L
Image02.jpg
2
P
Image03.jpg
3
P
Image04.jpg
4
L
Image05.jpg
5
L
Image06.jpg
6
P
Image07.jpg
7
P
Image08.jpg
8
L
Image09.jpg
9
L
Image10.jpg
10
P
Image11.jpg
11
P
Image12.jpg
12
L
Before this design alteration they made it was so simple, all Odd numbers were P and all Even numbers were L.
Now it makes no difference if the number is Even or Odd it could be L or P, but I assume mathematically there is some way to distinguish a pattern somehow.
This is more based on the content management system that is saving out the images at various sizes and various orientations as they have about 10k images, so often the original image could be a landscape @ 8000px x 4000px and they choose to show it as a portrait image in the gallery rather.
After the front end form has all their choices made and writes it to the database then a secondary server action goes in and saves out all Portrait images at 300px x 500px and crops to ensure even if the original was a landscape it is now cropped to portrait.
This takes whatever number has been typed into the position field rather than the index of the repeat, they could select 12 images for a single batch and the first image could be a hero image, and the second could be a highlight image, and 3-8 are Gallery images, so it has to rather go off the position they manually input rather than the position of display in the repeat.