Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START googlegenaisdk_imggen_canny_ctrl_type_with_txt_img]
const {GoogleGenAI, ControlReferenceImage} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION =
process.env.GOOGLE_CLOUD_LOCATION || 'us-central1';

async function generateImage(
outputGcsUri,
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const controlReferenceImage = new ControlReferenceImage();
controlReferenceImage.referenceId = 1;
controlReferenceImage.referenceImage = {
gcsUri: 'gs://cloud-samples-data/generative-ai/image/car_canny.png',
};
controlReferenceImage.config = {
controlType: 'CONTROL_TYPE_CANNY',
};

// TODO(developer): Update and un-comment below line
// outputGcsUri = "gs://your-bucket/your-prefix"

const response = await client.models.editImage({
model: 'imagen-3.0-capability-001',
// The '[1]' in the prompt corresponds to the controlReferenceImage.referenceId above.
prompt: 'a watercolor painting of a red car[1] driving on a road',
referenceImages: [controlReferenceImage],
config: {
editMode: 'EDIT_MODE_CONTROLLED_EDITING',
numberOfImages: 1,
safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE',
personGeneration: 'ALLOW_ADULT',
outputGcsUri: outputGcsUri,
},
});

console.log(response.generatedImages[0].image.gcsUri);
// Example response:
// gs://your-bucket/your-prefix
return response.generatedImages[0].image.gcsUri;
}
// [END googlegenaisdk_imggen_canny_ctrl_type_with_txt_img]

module.exports = {
generateImage,
};
70 changes: 70 additions & 0 deletions genai/image-generation/imggen-raw-reference-with-txt-img.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// [START googlegenaisdk_imggen_raw_reference_with_txt_img]

'use strict';

const {GoogleGenAI, RawReferenceImage} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION =
process.env.GOOGLE_CLOUD_LOCATION || 'us-central1';

async function generateImage(
outputGcsUri,
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const referenceImages = new RawReferenceImage();
referenceImages.referenceId = 1;
referenceImages.referenceImage = {
gcsUri: 'gs://cloud-samples-data/generative-ai/image/teacup-1.png',
};

// TODO(developer): Update and un-comment below line
// outputGcsUri = "gs://your-bucket/your-prefix"

const response = await client.models.editImage({
model: 'imagen-3.0-capability-001',
prompt:
'transform the subject in the image so that the teacup[1] is made entirely out of chocolate',
referenceImages: [referenceImages],
config: {
editMode: 'EDIT_MODE_DEFAULT',
numberOfImages: 1,
safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE',
personGeneration: 'ALLOW_ADULT',
outputGcsUri: outputGcsUri,
},
});

console.log(response);

// Example response:
// gs://your-bucket/your-prefix

return response.generatedImages[0].image.gcsUri;
}
// [END googlegenaisdk_imggen_raw_reference_with_txt_img]

module.exports = {
generateImage,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START googlegenaisdk_imggen_scribble_ctrl_type_with_txt_img]
const {GoogleGenAI, ControlReferenceImage} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION =
process.env.GOOGLE_CLOUD_LOCATION || 'us-central1';

async function generateImage(
outputGcsUri,
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const controlReferenceImage = new ControlReferenceImage();
controlReferenceImage.referenceId = 1;
controlReferenceImage.referenceImage = {
gcsUri: 'gs://cloud-samples-data/generative-ai/image/car_scribble.png',
};
controlReferenceImage.config = {
controlType: 'CONTROL_TYPE_SCRIBBLE',
};

// TODO(developer): Update and un-comment below line
// outputGcsUri = "gs://your-bucket/your-prefix"

const response = await client.models.editImage({
model: 'imagen-3.0-capability-001',
prompt: 'an oil painting showing the side of a red car[1]',
referenceImages: [controlReferenceImage],
config: {
editMode: 'EDIT_MODE_CONTROLLED_EDITING',
numberOfImages: 1,
safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE',
personGeneration: 'ALLOW_ADULT',
outputGcsUri: outputGcsUri,
},
});
console.log(response.generatedImages);

// Example response:
// gs://your-bucket/your-prefix
return response.generatedImages;
}
// [END googlegenaisdk_imggen_scribble_ctrl_type_with_txt_img]

module.exports = {
generateImage,
};
73 changes: 73 additions & 0 deletions genai/image-generation/imggen-style-reference-with-txt-img.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START googlegenaisdk_imggen_style_reference_with_txt_img]
const {GoogleGenAI, StyleReferenceImage} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION =
process.env.GOOGLE_CLOUD_LOCATION || 'us-central1';

async function generateImage(
outputGcsUri,
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

// Create a style reference image of a neon sign stored in Google Cloud Storage
// using https://storage.googleapis.com/cloud-samples-data/generative-ai/image/neon.png

// TODO(developer): Update and un-comment below line
// outputGcsUri = "gs://your-bucket/your-prefix"

const styleReferenceImage = new StyleReferenceImage();
styleReferenceImage.referenceId = 1;
styleReferenceImage.referenceImage = {
gcsUri: 'gs://cloud-samples-data/generative-ai/image/neon.png',
};
styleReferenceImage.config = {
styleDescription: 'neon sign',
};

const response = await client.models.editImage({
model: 'imagen-3.0-capability-001',
prompt:
'generate an image of a neon sign [1] with the words: have a great day',
referenceImages: [styleReferenceImage],
config: {
editMode: 'EDIT_MODE_CONTROLLED_EDITING',
numberOfImages: 1,
safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE',
personGeneration: 'ALLOW_ADULT',
outputGcsUri: outputGcsUri,
},
});
console.log(response.generatedImages);

// Example response:
// gs://your-bucket/your-prefix
return response.generatedImages;
}
// [END googlegenaisdk_imggen_style_reference_with_txt_img]

module.exports = {
generateImage,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START googlegenaisdk_imggen_subj_refer_ctrl_refer_with_txt_imgs]
const {
GoogleGenAI,
ControlReferenceImage,
SubjectReferenceImage,
} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION =
process.env.GOOGLE_CLOUD_LOCATION || 'us-central1';

async function generateImage(
outputGcsUri,
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const subjectReferenceImage = new SubjectReferenceImage();
subjectReferenceImage.referenceId = 1;
subjectReferenceImage.referenceImage = {
gcsUri: 'gs://cloud-samples-data/generative-ai/image/person.png',
};
subjectReferenceImage.config = {
subjectDescription: 'a headshot of a woman',
subjectType: 'SUBJECT_TYPE_PERSON',
};

const controlReferenceImage = new ControlReferenceImage();
controlReferenceImage.referenceId = 2;
controlReferenceImage.referenceImage = {
gcsUri: 'gs://cloud-samples-data/generative-ai/image/person.png',
};
controlReferenceImage.config = {
controlType: 'CONTROL_TYPE_FACE_MESH',
};

// TODO(developer): Update and un-comment below line
// outputGcsUri = "gs://your-bucket/your-prefix"

const response = await client.models.editImage({
model: 'imagen-3.0-capability-001',
prompt: `a portrait of a woman[1] in the pose of the control image[2]in a watercolor style by a professional artist,
light and low-contrast stokes, bright pastel colors, a warm atmosphere, clean background, grainy paper,
bold visible brushstrokes, patchy details`,
referenceImages: [subjectReferenceImage, controlReferenceImage],
config: {
editMode: 'EDIT_MODE_CONTROLLED_EDITING',
numberOfImages: 1,
safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE',
personGeneration: 'ALLOW_ADULT',
outputGcsUri: outputGcsUri,
},
});
console.log(response.generatedImages);

// Example response:
// gs://your-bucket/your-prefix
return response.generatedImages;
}
// [END googlegenaisdk_imggen_subj_refer_ctrl_refer_with_txt_imgs]

module.exports = {
generateImage,
};
Loading
Loading