I'm not sure why the check is necessary in your particular example. If the destination image doesn't use the alpha channel (it's all opaque), you can simply overwrite the data using the source image's alpha channel.
If you're using pixels[] by the way, a single loop should do:
PImage withAlpha;
PImage noAlpha;
void setup(){
size(120, 130);
background(0);
withAlpha = loadImage("8fXFk.png");
noAlpha = loadImage("AOsi0.png");
copyAlphaChannel(withAlpha, noAlpha);
}
void draw(){
background(map(sin(frameCount * 0.1), -1.0, 1.0, 0, 192), 0, 0);
image(withAlpha, 0, 0);
image(noAlpha, 60, 0);
}
void copyAlphaChannel(PImage src, PImage dst){
// quick error check
if(src.width != dst.width || src.height != dst.height){
println(String.format("error, mismatching dimensions src(%d,%d) != dst(%d,%d)",
src.width, src.height, dst.width, dst.height));
return;
}
// load pixel data
src.loadPixels();
dst.loadPixels();
int numPixels = src.pixels.length;
// for each pixel
for(int i = 0 ; i < numPixels; i++){
// extract source alpha
int srcAlpha = (src.pixels[i] >> 24) & 0xFF;
// apply it to the destination image
// src alpha | dst RGB
dst.pixels[i] = srcAlpha << 24 | (dst.pixels[i] & 0xFFFFFF);
}
dst.updatePixels();
}

Update Thank you for pointing that out: I've missed this detail.
PImage can have three formats:
RGB (=1)
ARGB (=2)
ALPHA(=4)
One workaround to convert an RGB format PImage into ARGB format is to apply an opaque mask():
PImage withAlpha;
PImage noAlpha;
void setup(){
size(120, 130);
background(0);
withAlpha = loadImage("8fXFk.png");
noAlpha = loadImage("AOsi0.png");
println("before",withAlpha.format, noAlpha.format, ARGB, RGB); // notice noAlpha's format is RGB
forceAlphaChannel(noAlpha);
println("after",withAlpha.format, noAlpha.format, ARGB, RGB); // notice noAlpha's format is ARGB
copyAlphaChannel(withAlpha, noAlpha);
noAlpha.save("test.png");
}
void draw(){
background(map(sin(frameCount * 0.1), -1.0, 1.0, 0, 192), 0, 0);
image(withAlpha, 0, 0);
image(noAlpha, 60, 0);
}
void forceAlphaChannel(PImage src){
// make an opaque mask
PImage mask = createImage(src.width, src.height, ALPHA);
java.util.Arrays.fill(mask.pixels, color(255));
mask.updatePixels();
// apply the mask force the RGB image into ARGB format
src.mask(mask);
}
void copyAlphaChannel(PImage src, PImage dst){
// quick error check
if(src.width != dst.width || src.height != dst.height){
println(String.format("error, mismatching dimensions src(%d,%d) != dst(%d,%d)",
src.width, src.height, dst.width, dst.height));
return;
}
// load pixel data
src.loadPixels();
dst.loadPixels();
int numPixels = src.pixels.length;
// for each pixel
for(int i = 0 ; i < numPixels; i++){
// extract source alpha
int srcAlpha = (src.pixels[i] >> 24) & 0xFF;
// apply it to the destination image
// src alpha | dst RGB
dst.pixels[i] = srcAlpha << 24 | (dst.pixels[i] & 0xFFFFFF);
}
dst.updatePixels();
}
Since the above loops through pixels a bunch of times (once to create the mask and again to apply it) it may be more efficient to create an ARGB PImage in the first place, then copy RGB data from one PImage and ALPHA from another:
PImage withAlpha;
PImage noAlpha;
void setup(){
size(120, 130);
background(0);
withAlpha = loadImage("8fXFk.png");
noAlpha = loadImage("AOsi0.png");
println("before",withAlpha.format, noAlpha.format, ARGB, RGB); // notice noAlpha's format is RGB
noAlpha = getAlphaChannelCopy(withAlpha, noAlpha);
println("after",withAlpha.format, noAlpha.format, ARGB, RGB); // notice noAlpha's format is ARGB
noAlpha.save("test.png");
}
void draw(){
background(map(sin(frameCount * 0.1), -1.0, 1.0, 0, 192), 0, 0);
image(withAlpha, 0, 0);
image(noAlpha, 60, 0);
}
// copy src alpha and dst rgb into new ARGB PImage
PImage getAlphaChannelCopy(PImage src, PImage dst){
// quick error check
if(src.width != dst.width || src.height != dst.height){
println(String.format("error, mismatching dimensions src(%d,%d) != dst(%d,%d)",
src.width, src.height, dst.width, dst.height));
return null;
}
PImage out = createImage(src.width, src.height, ARGB);
// load pixel data
src.loadPixels();
dst.loadPixels();
out.loadPixels();
int numPixels = src.pixels.length;
// for each pixel
for(int i = 0 ; i < numPixels; i++){
// extract source alpha
int srcAlpha = (src.pixels[i] >> 24) & 0xFF;
// apply it to the destination image
// src alpha | dst RGB
out.pixels[i] = srcAlpha << 24 | (dst.pixels[i] & 0xFFFFFF);
}
out.updatePixels();
return out;
}
(The only minor downside here is you'd loadPixels() thrice: once per image.)