# /media/bill/PROJECTS/Qnial/MY_NDFS/imagemagic howell-image-translate-rotate.ndf # www.BillHowell.ca 30Jun2015 initil based on # /home/bill/Projects/Stalin supported Hitler/animations - Howell/0_gimp howell-image-transcale.ndf # [Timing, translations, rotations] of a Spiral galaxy (no scaling here) # Currently assumes linear [translation, rotation] write 'loading loaddefs '/home/bill/Documents_Toshiba/Dark matter, spiral galaxies, and galactic current sheets/0_imagemagic howell-image-translate-rotate.ndf' ; lq_dark IS loaddefs '/home/bill/Documents_Toshiba/Dark matter, spiral galaxies, and galactic current sheets/0_imagemagic howell-image-translate-rotate.ndf' #***************** # Debugging flag_break = l ; # There is now the additional spec "class_cde" !! (screwed up old code) # dir_DarkMatter := #******************* write 'loading /home/bill/Projects/Dark matter, spiral galaxies, and galactic current sheets/0_imagemagic howell-image-translate-rotate.ndf' ; frames_per_sec := 24 ; sizeOutRatio := 0 ; fNameLen := 6 ; flag_test := l ; dir_base := '/home/bill/Projects/Dark matter, spiral galaxies, and galactic current sheets/' ; dir_Birkeland := '' ; dir_combined := '' ; dir_Tests := '' ; dir_stars := '' ; fpath_crop := '' ; fname_logr := '' ; fpath_tran := '' ; #**************************** # simple generic text & file operators file_identify IS OP filepath { NONLOCAL fname_logr ; host link 'identify >"' fname_logr '" "' filepath '"' ; fin := open fname_logr "r ; fProp_text := readfile fin ; close fin ; len_tr := (- Each (gage shape) fProp_text filepath) - 1 ; %write link 'len_tr = ' (string len_tr) ; ident := len_tr takeright fProp_text ; %string_split_by_string_with_sub S1 S2 S3 ; % splits S3 at each point that S1 occurs, ; % and puts in S2 in place of S1 ; string_split_by_string_with_sub ' ' '' ident } fi IS file_identify link dir_base 'Birkeland.png' numStr_pad IS OP integerIn strLen charPad { integerStr := string integerIn ; padNum := strLen - (gage shape integerStr) ; link (padNum reshape charPad) integerStr } shorten IS OP str { IF isstring str THEN IF 30 < (gage shape str) THEN 30 take str ELSE str ENDIF ELSE str ENDIF } dat_display IS OP dat { datShort := EACH shorten dat } string_off IS OP realNum { IF realNum >= 0 THEN link '+' (string (floor realNum)) ELSE string floor realNum ENDIF } # I don't know how to convert images to video from commandline # imagemagic commandline image->video images_to_video IS OP dir_src dir_ot fname_base_out { convert -delay 100 -quality 75 photo1.jpg photo2.jpg movie.mpg } image_repage IS OP fpath_in fpath_ot { ftype resXY resXY_offXY bitSize class fsize usize timet := file_identify fpath_in ; xRes yRes := string_split_by_string_with_sub 'x' '' resXY ; host link 'convert "' fpath_in '"' ' -gravity center -repage ' (char 39) xRes 'x' yRes '+0+0' (char 39) ' +repage ' ' "' fpath_ot '"' } #IF flag_break = l THEN Break ; ENDIF ; #*************** # Basic image manipulations - remove rotations etc! # For images with rotation problems : # 28Apr2015 AH HAH! use imagemagic to rotate initial source image, # but also need to rotate&save with Image Viewer as well! # Careful - Image Viewer tries to save as tiff, # irrespective of file extension! # Read & Remove EXIF Data From the Command Line # http://hacktux.com/read/remove/exif # mogrify -strip imagename.jpg # mogrify - This cleans up the image specs so they won't interfer later mogrify IS OP fpath { cmd := link 'mogrify -strip "' fpath '"' ; host cmd ; } mog IS mogrify link '/home/bill/Projects/Stalin supported Hitler/animations - Howell/Opening_Context/I_1_4_Battle_of_Oil/' 'MilAtlas - Africa Operation Compass, British pushback Italians Dec1940-Feb41.jpg' # This is for [90, 180] degree rotations of initial image file image_source_rotate IS OP angle directory fname_in fname_ot { fin := link directory fname_in ; fot := link directory fname_ot ; % ; mogrify fin ; % ; ftype resXY resXY_offXY bitSize class fsize usize timet := file_identify fot ; resX resY := EACH tonumber (string_split_by_string_with_sub 'x' '' resXY) ; IF resX < resY THEN arrow := '<' ; ELSE arrow := '>' ; ENDIF ; write (ftype resXY resXY_offXY bitSize class fsize usize timet ) ; cmd := link 'convert "' fin '"' ' -rotate ' (char 39) angle arrow (char 39) ' +repage ' ' "' fot '"' ; host cmd ; write 'image_source_rotate result: ' ; write 'NOTE - you must rotate & save the result with image viewer! : ' ; write 'Also - width/height ration affects some efforts & prevents rotated output' ; ftype resXY resXY_offXY bitSize class fsize usize timet := file_identify fot } # 01Jul2015 - Comments http://www.imagemagick.org/script/command-line-processing.php#geometry Finally, use @ to specify the maximum area in pixels of an image, again while attempting to preserve aspect ratio. (Pixels take only integer values, so some approximation is always at work.) In the following example, an area of 10000 pixels is requested. The resulting file has dimensions 115x86, which has 9890 pixels. convert logo: -resize '@10000' wiz10000.png This might be better than specing the x & y, if the latter doesn't work. # Use > to shrink an image only if its dimension(s) are larger than the corresponding width and/or height arguments. Use < to enlarge an image only if its dimension(s) are smaller than the corresponding width and/or height arguments. In either case, if a change is made, the result is as if the > or < operator was not present. So, in the third example above, we specified 100x200> and the original image size is 640x480, so the image size is reduced as if we had specified 100x200. However, in the fourth example above, there will be no change to its size. # # Maybe the problem is that the resizing is based on the "enclosing envelope" and NOT the rotated x&y. In that case, the new geometry "computer screen based geometry" has to be calculated. # # http://stackoverflow.com/questions/14751011/how-to-rotate-an-image-without-changing-its-size answered Aug 16 '13 at 19:58, Enyby convert image.jpg -distort SRT -45 rotate_cropped_image.png See http://www.imagemagick.org/Usage/warping/#animations Example: Animated GIF See also help on -distort: http://www.imagemagick.org/script/command-line-options.php?#distort # answered Feb 7 '13 at 12:22, lizarisk I've found this answer on Imagemagick forum: A simple solution without knowing what the original size of the image was, is to use the Alpha Composite Operator 'Src' as a 'crop to this image size' type of operation. See: http://www.cit.gu.edu.au/~anthony/graphics/imagick6/compose/#src For example (ImageMagick version 6 only): convert image.jpg \( +clone -background black -rotate -45 \) \ -gravity center -compose Src -composite rotate_cropped_image.png # rot IS image_source_rotate '+90' dir_base 'MilAtlas - Africa Operation Compass, British pushback Italians Dec1940-Feb41.jpg' 'MilAtlas - Africa Operation Compass, British pushback Italians Dec1940-Feb41 rotated.jpg' #IF flag_break = l THEN Break ; ENDIF ; image_source_resize IS OP dir_source f_source f_result resX resY { p_src := link dir_source f_source ; p_res := link dir_source f_result ; % ; mogrify p_src ; % ; ftype resXY resXY_offXY bitSize class fsize usize timet := file_identify p_src ; write 'ftype resXY resXY_offXY bitSize class fsize usize timet = ' ; write (ftype resXY resXY_offXY bitSize class fsize usize timet ) ; cmd := link 'convert "' p_src '" -resize ' (string resX) '!x' (string resY) '! "' p_res '"' ; write cmd ; host cmd ; ftype resXY resXY_offXY bitSize class fsize usize timet := file_identify p_res } # img_resize IS image_source_resize dir_base 'Spiral galaxy - abyss.uoregon.edu - heic0506a.png' 'Spiral galaxy - abyss.uoregon.edu - heic0506a cropped.png' 336 336 # file_identify IS OP filepath : # Strange 0- sometimes 8 parameters + p_name, sometimes 9? # Add or remove "class_cde" in list : ftype resXY resXY_offXY bitSize class class_cde fsize usize timet ftype resXY resXY_offXY bitSize class fsize usize timet # image_source_resize_same IS OP dir_source f_source dir_target f_target f_result { p_src := link dir_source f_source ; p_tgt := link dir_target f_target ; p_res := link dir_target f_result ; % ; mogrify p_src ; % ; ftype resXY resXY_offXY bitSize class fsize usize timet := file_identify p_src ; write 'ftype resXY resXY_offXY bitSize class fsize usize timet = ' ; write (ftype resXY resXY_offXY bitSize class fsize usize timet ) ; resX resY := string_split_by_string_with_sub 'x' '' resXY ; cmd := link 'convert "' p_tgt '" -resize ' resX '!x' resY '! "' p_res '"' ; write cmd ; host cmd ; ftype resXY resXY_offXY bitSize class fsize usize timet := file_identify p_res } img_resize_same IS image_source_resize_same dir_base '150630 Spiral galaxy.png' dir_base '150630 Spiral galaxy4.png' '150630 Spiral galaxy4.png' crop_test IS { fpath_in := '/home/bill/Projects/Stalin supported Hitler/animations - Howell/Opening_Context/02.1 Battle of Britain/1 Battle of Britain/1-MilAtlas- EuropeNW Battle of Britain Jul-Oct1940.jpg' ; Host link 'convert "' fpath_in '" -gravity center -crop ' (char 39) '720x570+0+0' (char 39) ' "' fpath_crop '.jpg"' ; } # see for development : /home/bill/Projects/Dark matter, spiral galaxies, and galactic current sheets/z _imagemagic howell-image-translate-rotate - tests of combined.txt combine_images IS OP image1 image2 image_dest { cmd := link 'composite "' image1 '" "' image2 '" -blend ' (string 40) ' "' image_dest '"' ; %write cmd ; host cmd ; } #************************** # Main operators for image processing tasks image_scale_translation_rotation_sequence IS OP dir_source dir_destin fname_source fname_destin lenX_strt lenX_end lenY_strt lenY_end offX_strt offX_end offY_strt offY_end rotn_strt rotn_end timeLapse_sec fil_numStart { IF flag_test THEN dir_ot := dir_Tests ; ELSE dir_ot := dir_destin ; ENDIF ; fpath_in := link dir_source fname_source ; fpath_ot := link dir_ot fname_destin ; % ; sizeOutRatio := lenY_end / lenX_end ; t_steps := ceiling (timeLapse_sec * frames_per_sec) ; IF flag_test THEN t_steps := 6 ; ENDIF ; lenX_inc := (lenX_end - lenX_strt) / t_steps ; lenY_inc := (lenY_end - lenY_strt) / t_steps ; offX_inc := (offX_end - offX_strt) / t_steps ; offY_inc := (offY_end - offY_strt) / t_steps ; rotn_inc := (rotn_end - rotn_strt) / t_steps ; % ; FOR i WITH tell (t_steps + 1) DO lenX := lenX_strt + (lenX_inc * i) ; lenY := lenY_strt + (lenY_inc * i) ; lenXS := string floor lenX ; lenYS := string floor (lenX * sizeOutRatio) ; offX := string_off (offX_inc * i + offX_strt) ; offY := string_off (offY_inc * i + offY_strt) ; rotn := string_off (rotn_inc * i + rotn_strt) ; % ; %image_crop ; cvrt_exprn := link ' -gravity center -crop ' (char 39) lenXS 'x' lenYS offX offY (char 39) ' +repage ' ; cmd := link 'convert "' fpath_in '"' cvrt_exprn ' "' fpath_crop '"' ; %write cmd ; host cmd ; % ; mogrify fpath_crop ; %image_scale ; cmd := link 'convert "' fpath_crop '" -resize ' lenXS 'x' lenYS '! "' fpath_tran '" ' ; %write cmd ; host cmd ; % ; mogrify fpath_tran ; %image_rotate ; filNumStr := numStr_pad ((i + fil_numStart) fNameLen '0') ; fpath_rot := link fpath_ot '-' filNumStr '.jpg' ; % example (see above) convert image.jpg -distort SRT -45 rotate_cropped_image.png ; cmd := link 'convert "' fpath_tran '" -distort SRT ' rotn ' "' fpath_rot '"' ; %write cmd ; host cmd ; % ; mogrify fpath_rot ; write link 'Done file ' (string (i + 1)) ' of ' (string (t_steps + 1)) ', file: ' fname_source ; ENDFOR ; } #IF flag_break = l THEN Break ; ENDIF ; # 01Jul2015 Recent changes to image_scale_translation_rotation_sequence # cmd := link 'convert "' fpath_crop '" -resize 770!x570! "' fpath_tran '" ' ; # Image geometry http://www.imagemagick.org/script/command-line-processing.php#geometry # The "!" is only required at the end of the size spec : eg 770x570! '" -resize ' lenXS '!x' lenYS '! "' # Rotations bsed on x&y_image, rather than x&y_screen : %image_rotate ; IF lenX_strt >= lenY_strt THEN rot_direction := '>' ; ELSE rot_direction := '<' ; ENDIF ; filNumStr := numStr_pad ((i + fil_numStart) fNameLen '0') ; fpath_rot := fpath_ot '-' filNumStr '.jpg"' ; cmd := link 'convert "' fpath_tran '" -rotate "' rotn rot_direction '" "' fpath_rot ; # 01Jul2015 12:56 - still the original 336*336 image is cropped to 333*248 - maybe by [crop, scale, translate] - check later, for now do combine_image_sequences # combine_image_sequences - Assumes that the image sequences ALL have exactly the same [number of images, type of numbering]!!! combine_image_sequences IS OP dir_1 dir_2 fname_base_1 fname_base_2 timeLapse_sec fil_numStart { t_steps := ceiling (timeLapse_sec * frames_per_sec) ; IF flag_test THEN t_steps := 6 ; dir_1 := dir_Tests ; dir_2 := dir_Tests ; dir_ot := dir_Tests ; ELSE dir_ot := dir_combined ; ENDIF ; % ; fil_num := -1 ; FOR i WITH tell (t_steps + 1) DO fil_num := fil_num + 1 ; filNumStr := numStr_pad ((i + fil_numStart) fNameLen '0') ; fpath_1 := link dir_1 fname_base_1 '-' filNumStr '.jpg' ; fpath_2 := link dir_2 fname_base_2 '-' filNumStr '.jpg' ; fpath_combined := link dir_ot 'stars & Birkeland-' filNumStr '.jpg' ; combine_images fpath_1 fpath_2 fpath_combined ; write link 'Done file ' (string (i + 1)) ' of ' (string (t_steps + 1)) ', sources: ' fname_base_1 ' and ' fname_base_2 ; ENDFOR ; } # wrong - I rotated stars and Birkeland, only want Birkeland to rotate FOR i WITH tell (t_steps + 1) DO fil_num := fil_num + 1 ; filNumStr := numStr_pad ((i + fil_numStart) fNameLen '0') ; fpath_1 := link dir_1 fname_base_1 '-' filNumStr '.jpg' ; fpath_2 := link dir_2 fname_base_2 '-' filNumStr '.jpg' ; fpath_combined := link dir_ot 'stars & Birkeland-' filNumStr '.jpg' ; combine_images fpath_1 fpath_2 fpath_combined ; write link 'Done file ' (string (i + 1)) ' of ' (string (t_steps + 1)) ', sources: ' fname_base_1 ' and ' fname_base_2 ; ENDFOR ; #************************** # Galactic Birkeland currents - [birth, life, death] # # Spiral image is modified for each time step # # Easiest approach is to modify the last image" every time step, # rolling-over each incident list depending on the periodicity, and # re-calculating the current [action, scale] for every action-list. # # % initial Birkelands list is empty Birkelands := null ; # for now, assume only max of one [start, stop] per time step, with Poisson (flat ) distributions. Picked randomly out of list of active ejaculations. ; Should give a broad-time-scale distribution of starts & stops, with perhaps a bias to natural spectral periodicities and distributions. #rate_calc IS OP var_name { distribution rate_birth rate_death := t_start t_legth_prob p_distribution := } #Birkeland_strt { %Need some kind of "statistic" on [energy, timing, direction, etc] ; } #Birkeland_life { %Need some kind of "statistic" on [energy, timing, direction, etc] ; } #Birkeland_endd { %Need some kind of "statistic" on [energy, timing, direction, etc] ; } #Birkeland_stepp IS { death birth := TWICE yes_calc tstep ; %ALL THIS - at statistically guessed times. ; %For now, allow only one [birth, death] per time step ; IF birth > 0.5 THEN Birkeland_strt ; ENDIF ; IF death > 0.5 THEN Birkeland_endd ; %picks one at random, but partially based on [energy, age] of each ; ENDIF ; } #**************** # Data # image_scale_translation_rotation_sequence IS OP dir_source dir_destin fname_source fname_destin lenX_strt lenX_end lenY_strt lenY_end offX_strt offX_end offY_strt offY_end rotn_strt rotn_end timeLapse_sec fil_numStart seqSeq IS OP imgSeqSpec { dat_count := floor (gage shape imgSeqSpec / 2) ; dat_table := dat_count 2 reshape imgSeqSpec ; dat := second cols dat_table } # simple, initial model loaddefs link dir_base '1 - initial, simple/dataSpecs.ndf' ; # 2 - intermittent ejaculations loaddefs link dir_base '2 - intermittant galactic holes-Birkelands/dataSpecs.ndf' ; #**************** # Actions to test image file or generate animation # Don't know how to generate video files with imagemagic # - use OpenShot! flag_test := o ; tit IS combine_images (link dir_DarkMatter '150630 Spiral galaxy.png') (link dir_DarkMatter '150630 Spiral galaxy4.png') (link dir_DarkMatter 'combine_test.png') # sparkIt IS { %image_scale_translation_rotation_sequence rotate_stars_specs ; image_scale_translation_rotation_sequence rotate_Birkeland_specs ; combine_image_sequences combine_image_sequences_specs ; } # enddoc