@@ -901,6 +901,38 @@ public function newFromImage($value): Image
901901 ]);
902902 }
903903
904+ /**
905+ * Find the name of the load operation vips will use to load a VipsSource, for
906+ * example 'VipsForeignLoadJpegSource'. You can use this to work out what
907+ * options to pass to newFromSource().
908+ *
909+ * @param VipsSource $source The source to test
910+ * @return string|null The name of the load operation, or null.
911+ */
912+ public static function findLoadSource (VipsSource $ source ): ?string
913+ {
914+ return FFI ::vips ()->vips_foreign_find_load_source (\FFI ::cast (FFI ::ctypes ('VipsSource ' ), $ source ->pointer ));
915+ }
916+
917+ /**
918+ * @throws Exception
919+ */
920+ public static function newFromSource (VipsSource $ source , string $ string_options = '' , array $ options = []): self
921+ {
922+ $ loader = self ::findLoadSource ($ source );
923+ if ($ loader === null ) {
924+ throw new Exception ('unable to load from source ' );
925+ }
926+
927+ if ($ string_options !== '' ) {
928+ $ options = array_merge ([
929+ "string_options " => $ string_options ,
930+ ], $ options );
931+ }
932+
933+ return VipsOperation::call ($ loader , null , [$ source ], $ options );
934+ }
935+
904936 /**
905937 * Write an image to a file.
906938 *
@@ -1040,6 +1072,28 @@ public function writeToArray(): array
10401072 return $ result ;
10411073 }
10421074
1075+ /**
1076+ * @throws Exception
1077+ */
1078+ public function writeToTarget (VipsTarget $ target , string $ suffix , array $ options = []): void
1079+ {
1080+ $ filename = Utils::filenameGetFilename ($ suffix );
1081+ $ string_options = Utils::filenameGetOptions ($ suffix );
1082+ $ saver = FFI ::vips ()->vips_foreign_find_save_target ($ filename );
1083+
1084+ if ($ saver === '' ) {
1085+ throw new Exception ("can't save to target with filename $ filename " );
1086+ }
1087+
1088+ if ($ string_options !== '' ) {
1089+ $ options = array_merge ([
1090+ "string_options " => $ string_options ,
1091+ ], $ options );
1092+ }
1093+
1094+ VipsOperation::call ($ saver , $ this , [$ target ], $ options );
1095+ }
1096+
10431097 /**
10441098 * Copy to memory.
10451099 *
0 commit comments