Copy link to clipboard
Copied
Hello,
I face a tricky problem with indesign Server.
My .js code import a .jpg files on the document like the common way :
var maske=pSheet.rectangles.add({geometricBounds:[y1_maske,x1_maske,y2_maske,x2_maske]});
var picture=maske.place('myFile.jpg',{geometricBounds:[y1_picture, x1_picture,y2_picture,x2_picture]});This code works fine, this is not the problem...
The problem is that for certain .jpg files the placemet of picture fails and it's due to the .jpg file wich seems to be not well "generated".
In Indesign desktop, I have the same problem with this picture, the message in French is : "Une erreur s'est produite lors de la lecture d'une image. L'image est endomagée ou incompatible. Réenregistrez la avec d'autres paramètres et recommencez". The message in english would be "An error occurred while reading an image. The image is damaged or incompatible. Save it again with other settings and start over".
To correct the problem "manualy" I just open the picture in Paint (on Windows), save the picture et then I can import it in indesign Desktop.
My question is :
Is there a way, to "repair" the wrong picture with .js before placing it on my sheet ? The aim is to run the script on Indesign Server.
Thanks a lot.
Vins.
See bellow the message when import this wrong picture in Indesign Desktop :
The problem is that InDesign (Server) can't call other programs. Better to fix faulty images before you upload the to the server. In a desktop instance you can go through all images: try to place them (in a try/catch statement) and if there's an error, log the image name. Then you know which images should be fixed.
Alternatively, just assume that all images are faulty and use a server version of an image processor to open and re-save all images. I thought that ImageMagick has a server version.
...Copy link to clipboard
Copied
The problem is that InDesign (Server) can't call other programs. Better to fix faulty images before you upload the to the server. In a desktop instance you can go through all images: try to place them (in a try/catch statement) and if there's an error, log the image name. Then you know which images should be fixed.
Alternatively, just assume that all images are faulty and use a server version of an image processor to open and re-save all images. I thought that ImageMagick has a server version. Then run your InDesign job.
P.
Copy link to clipboard
Copied
Hello Peter !
Thanks for you answer, I just made like you explain, PHP script to treat the pictures. The trick in PHP is just to open the Picture ans rewrite it :
I apply a filter to test if I have to rewrite the file or not. I remarked that all pictures causing trouble had no 'SectionsFound' in the array you get when you make an @exif_read_data on the file. Here is my PHP code :
$fileInfo = new SplFileInfo($parDatasPath . '/' . $file1 . '/' . $file2);
if ($fileInfo->getExtension() == 'jpg' ||
$fileInfo->getExtension() == 'JPG' ||
$fileInfo->getExtension() == 'jpeg' ||
$fileInfo->getExtension() == 'JPEG')
{
$tabExifReadData = @exif_read_data($parDatasPath . '/' . $file1 . '/' . $file2);
if (isset ($tabExifReadData) && $tabExifReadData['SectionsFound'] == '')
{
$JPGResource = imagecreatefromjpeg($parDatasPath . '/' . $file1 . '/' . $file2);
imagejpeg($JPGResource, $parDatasPath . '/' . $file1 . '/' . $file2, 100);
imagedestroy($JPGResource);
writeJPGSAndPNGSFixedFile($parDatasPath,$file1,$file2);
}
}
if ($fileInfo->getExtension() == 'png' ||
$fileInfo->getExtension() == 'PNG')
{
$PNGResource = imagecreatefrompng($parDatasPath . '/' . $file1 . '/' . $file2);
imageAlphaBlending($PNGResource, true);
imageSaveAlpha($PNGResource, true);
imagepng($PNGResource, $parDatasPath . '/' . $file1 . '/' . $file2);
imagedestroy($PNGResource);
writeJPGSAndPNGSFixedFile($parDatasPath,$file1,$file2);
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more